Anonymous user
Module:Documentation: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
finish splitting the _startBox function into smaller functions
(add functions for rendering start box links and for making the start box link data) |
(finish splitting the _startBox function into smaller functions) |
||
Line 302:
function p._startBox(args, env)
-- Generate [view][edit][history][purge] or [create] links.
local links
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
-- Generate the start box html.
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
-- User specified no heading.
return nil
end
end
Line 448 ⟶ 372:
ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink)
else
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
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
Line 465 ⟶ 433:
.css('font-size', data.headingFontSize)
.wikitext(data.heading)
if links then
sbox.tag('span')
.addClass(data.linksClass)
.attr('id', data.linksId)
.wikitext(
end
return tostring(sbox)
|