Module:Sandbox/KurwaAntics/Module cards

--

-- Modified from DarthKitty's module cards -- Under testing

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') => ''

local function externalLink(url, label, paramName) if not url then return '' end return '[' .. url .. ' ' .. label .. ']' end

-- Returns an internal link, wrapped in a `` 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( .. 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  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 .. ' &middot; ' .. 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(33.3% - 2.5em - 2px)') :tag('h3') :css('font-size', '1.2em') :css('font-weight', 'bold') :css('line-height', '1.5') :css('margin', '0') :wikitext( .. 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 '') :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 -- -- (Add categories here.)