FANDOM


-- <nowiki>
--------------------------------------------------------------------------------
-- 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') => '{{{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 .. ']]')
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 .. ' &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
 
    local personal
 
    if yesno(args['personal']) then
        personal = createHtml('span')
            :css('background', '#F44336')
            :css('border-radius', '2px')
            :css('color', '#fff')
            :css('display', 'inline-block')
            :css('font-size', '12px')
            :css('height', '19px')
            :css('line-height', '20px')
            :css('margin', '0')
            :css('padding', '0 5px')
            :css('text-decoration', 'none')
            :css('white-space', 'nowrap')
            :css('float', 'right')
            :wikitext('Personal only')
            :done()
    end
 
    local sitewide
 
    if yesno(args['sitewide']) then
        sitewide = createHtml('span')
            :css('background', '#1E88E5')
            :css('border-radius', '2px')
            :css('color', '#fff')
            :css('display', 'inline-block')
            :css('font-size', '12px')
            :css('height', '19px')
            :css('line-height', '20px')
            :css('margin', '0')
            :css('padding', '0 5px')
            :css('text-decoration', 'none')
            :css('white-space', 'nowrap')
            :css('float', 'right')
            :wikitext('Site-wide only')
            :done()
    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.6em - 2px)')
        :node(personal)
        :node(sitewide)
        :tag('h3')
            :css('font-size', '1.2em')
            :css('font-weight', 'bold')
            :css('line-height', '1.5')
            :css('margin', '0')
            :wikitext('[[' .. name .. ']]')
            :done()
        :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.)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.