This module was made as a sandbox for the user DarthKitty. This documentation is kept to prevent redlinks.
-- <nowiki>
--------------------------------------------------------------------------------
-- A tool for organizing [[Global Lua Modules]], which lets you put each
-- module's information on a "card". Makes it easier to find useful code and
-- relevant links.
--
-- @example
-- <div style="{{#invoke:Module cards|wrapper_css}}">
-- {{#invoke:Module cards|main
-- | name =
-- | desc =
-- | ext-source =
-- | ext-docs =
-- | no-tests =
-- }}
-- </div>
--------------------------------------------------------------------------------
local p = {}
-- Load dependencies
local checkType = require('libraryUtil').checkType
local getArgs = require('Dev:Arguments').getArgs
local userError = require('Dev:User error')
local yesno = require('Dev:Yesno')
-- Reduce table lookups
local createHtml = mw.html.create
--------------------------------------------------------------------------------
-- Returns an external link, or the name of a parameter if no url is provided.
--
-- @example
-- externalLink('//wikia.com', 'Wikia', 'wikia-link') => '[//wikia.com Wikia]'
--
-- @example
-- externalLink(nil, 'Wikia', 'wikia-link') => '{{{wikia-link}}}'
--------------------------------------------------------------------------------
local function externalLink(url, label, paramName)
if not url then
return '{{{' .. paramName .. '}}}'
end
return '[' .. url .. ' ' .. label .. ']'
end
--------------------------------------------------------------------------------
-- Returns an internal link, wrapped in a `<li>` and styled to match a card's
-- navigation.
--------------------------------------------------------------------------------
local function navigationLink(target, label)
return createHtml('li')
:css('border-left', '1px solid #aaa')
:css('-webkit-box-flex', '1')
:css('-webkit-flex', '1 1 0')
:css('-ms-flex', '1 1 0')
:css('flex', '1 1 0')
:css('margin', '0')
:css('padding', '0.5em')
-- :wikitext('[[Module:' .. target .. '|' .. label .. ']]')
:wikitext(externalLink(tostring(mw.uri.fullUrl('Module:' .. target)), label))
end
--------------------------------------------------------------------------------
-- Returns a string of CSS, used to style the cards' wrapper.
--------------------------------------------------------------------------------
function p.wrapper_css()
return table.concat{
'display: -webkit-box;',
'display: -webkit-flex;',
'display: -ms-flexbox;',
'display: flex;',
'-webkit-flex-wrap: wrap;',
'-ms-flex-wrap: wrap;',
'flex-wrap: wrap;',
'-webkit-box-pack: justify;',
'-webkit-justify-content: space-between;',
'-ms-flex-pack: justify;',
'justify-content: space-between;',
'line-height: 1.5;'
}
end
--------------------------------------------------------------------------------
-- Returns a "card" containing useful information about a module.
--
-- @param name
-- @param desc
-- @param ext-source
-- @param ext-docs
-- @param no-tests
--------------------------------------------------------------------------------
function p.main(frame)
local args = getArgs(frame)
local name = args.name
if not name then
return userError('the <code>name</code> parameter is required')
end
local extSource = args['ext-source']
local extDocs = args['ext-docs']
local extLinks
if extSource or extDocs then
local source = externalLink(extSource, 'Source', 'ext-source')
local docs = externalLink(extDocs, 'Full docs', 'ext-docs')
extLinks = createHtml('small')
:addClass('hidden')
:css('display', 'block')
:wikitext(source .. ' · ' .. docs)
end
local code = navigationLink(name, 'Code')
local sandbox = navigationLink(name .. '/sandbox', 'Sandbox')
local tests
if not yesno(args['no-tests']) then
tests = navigationLink(name .. '/testcases', 'Tests')
end
return createHtml('div')
:css('background-color', '#f9f9f9')
:css('border', '1px solid #aaa')
:css('display', '-webkit-box')
:css('display', '-webkit-flex')
:css('display', '-ms-flexbox')
:css('display', 'flex')
:css('-webkit-box-orient', 'vertical')
:css('-webkit-box-direction', 'normal')
:css('-webkit-flex-direction', 'column')
:css('-ms-flex-direction', 'column')
:css('flex-direction', 'column')
:css('margin-bottom', '1em')
:css('padding', '1em')
:css('width', 'calc(50% - 2.5em - 2px)')
:tag('h3')
:css('font-size', '1.2em')
:css('font-weight', 'bold')
:css('line-height', '1.5')
:css('margin', '0')
-- :wikitext('[[Global Lua Modules/' .. name .. '|' .. name .. ']]')
:wikitext(externalLink(tostring(mw.uri.fullUrl('Global Lua Modules/' .. name)), name))
:done()
:node(extLinks)
:tag('p')
:css('-webkit-box-flex', '1')
:css('-webkit-flex-grow', '1')
:css('-ms-flex-positive', '1')
:css('flex-grow', '1')
:css('margin', '0')
:css('margin-top', '0.5em')
:wikitext(args.desc or '{{{desc}}}')
:done()
:tag('ul')
:css('background-color', '#fbeecb')
:css('border-top', '1px solid #aaa')
:css('display', '-webkit-box')
:css('display', '-webkit-flex')
:css('display', '-ms-flexbox')
:css('display', 'flex')
:css('list-style-type', 'none')
:css('margin', '1em -1em -1em calc(-1em - 1px)')
:css('text-align', 'center')
:node(code)
:node(sandbox)
:node(tests)
:done()
end
return p
-- </nowiki>
-- (Add categories here.)