Module:Documentation: Difference between revisions
Jump to navigation
Jump to search
m>Mr. Stradivarius add functions for rendering start box links and for making the start box link data |
m>Mr. Stradivarius finish splitting the _startBox function into smaller functions |
||
Line 302: | Line 302: | ||
function p._startBox(args, env) | function p._startBox(args, env) | ||
-- Generate [view][edit][history][purge] or [create] links. | |||
local links | |||
-- | |||
local | |||
local content = args[message('contentArg', 'string')] | local content = args[message('contentArg', 'string')] | ||
if not content then | |||
-- No need to include the links if the documentation is on the template page itself. | |||
local linksData = p.makeStartBoxLinksData(args, env) | |||
links = p.renderStartBoxLinks(linksData) | |||
-- | end | ||
local | -- Generate the start box html. | ||
if | local data = p.makeStartBoxData(args, env, links) | ||
if type(data) == 'table' then | |||
return p.renderStartBox(data) | |||
elseif type(data) == 'string' then | |||
-- data is an error message. | |||
return data | |||
else | else | ||
-- User specified no heading. | |||
return nil | return nil | ||
end | end | ||
end | end | ||
Line 448: | Line 372: | ||
ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) | ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink) | ||
else | else | ||
ret = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) | |||
end | |||
end | |||
function p.makeStartBoxData(args, env, links) | |||
local subjectSpace = env.subjectSpace | |||
local data = {} | |||
-- Heading | |||
local heading = args[message('headingArg', 'string')] -- Blank values are not removed. | |||
if heading == '' then | |||
-- Don't display the start box if the heading arg is defined but blank. | |||
return nil | |||
end | end | ||
if heading then | |||
data.heading = heading | |||
elseif subjectSpace == 10 then -- Template namespace | |||
data.heading = message('documentationIconWikitext', 'string') .. ' ' .. message('templateNamespaceHeading', 'string') | |||
elseif subjectSpace == 828 then -- Module namespace | |||
data.heading = message('documentationIconWikitext', 'string') .. ' ' .. message('moduleNamespaceHeading', 'string') | |||
elseif subjectSpace == 6 then -- File namespace | |||
data.heading = message('fileNamespaceHeading', 'string') | |||
else | |||
data.heading = message('otherNamespacesHeading', 'string') | |||
end | |||
-- Heading CSS | |||
local headingStyle = args[message('headingStyleArg', 'string')] | |||
if headingStyle then | |||
data.headingStyleText = headingStyle | |||
elseif subjectSpace == 10 then | |||
-- We are in the template or template talk namespaces. | |||
data.headingFontWeight = 'bold' | |||
data.headingFontSize = '125%' | |||
else | |||
data.headingFontSize = '150%' | |||
end | |||
-- [view][edit][history][purge] or [create] links. | |||
if links then | |||
data.linksClass = message('startBoxLinkclasses', 'string') | |||
data.linksId = message('startBoxLinkId', 'string') | |||
data.links = links | |||
end | |||
return data | |||
end | end | ||
Line 465: | Line 433: | ||
.css('font-size', data.headingFontSize) | .css('font-size', data.headingFontSize) | ||
.wikitext(data.heading) | .wikitext(data.heading) | ||
local links = data.links | |||
if links then | |||
sbox.tag('span') | sbox.tag('span') | ||
.addClass(data.linksClass) | .addClass(data.linksClass) | ||
.attr('id', data.linksId) | .attr('id', data.linksId) | ||
.wikitext( | .wikitext(links) | ||
end | end | ||
return tostring(sbox) | return tostring(sbox) |