Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Flexbox: Difference between revisions

From Credoth
mNo edit summary
Tag: Reverted
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 17: Line 17:
     local columns = tonumber(args['columns']) or 3  -- Default to 3 columns if not passed
     local columns = tonumber(args['columns']) or 3  -- Default to 3 columns if not passed
     local gap = args['gap'] or '0.5rem'
     local gap = args['gap'] or '0.5rem'
    local justify = args['justify'] or 'flex-start'
     local direction
     local direction


Line 25: Line 26:
     html:css('--template-flexbox-columns', columns)
     html:css('--template-flexbox-columns', columns)
     html:css('--template-flexbox-gap', gap)
     html:css('--template-flexbox-gap', gap)
    html:css('--template-flexbox-justify', justify)


     -- Loop over content arguments
     -- Loop over content arguments
Line 33: Line 35:


         local item = mw.html.create('div'):addClass('template-flexbox-item')
         local item = mw.html.create('div'):addClass('template-flexbox-item')
       
        -- Get span for the current item, default to 1 if not set
        local span = tonumber(args['span' .. num]) or 1
        item:css('--template-flexbox-item-span', span)
        -- If the span equals the number of columns, apply full width
        if span == columns then
            item:css('flex-basis', '100%')
        end
         item:wikitext(content)
         item:wikitext(content)
         html:node(item)
         html:node(item)
Line 51: Line 43:
     } .. tostring(html)
     } .. tostring(html)
end
end




-- Ensure the module returns the table 'p'
-- Ensure the module returns the table 'p'
return p
return p

Latest revision as of 01:16, 29 December 2024

Documentation for this module may be created at Module:Flexbox/doc

local mArguments -- initialize lazily
local getArgNums = require('Module:Common').getArgNums
local p = {}  -- Initialize the p table to hold functions

-- Implements {{flexbox}} from the frame
function p.flexbox(frame)
    mArguments = require('Module:Arguments')
    return p._flexbox(mArguments.getArgs(frame), frame)
end

function p._flexbox(args, frame)
    if not args then
        return 'Missing arguments'
    end

    local html = mw.html.create('div'):addClass('template-flexbox')
    local columns = tonumber(args['columns']) or 3  -- Default to 3 columns if not passed
    local gap = args['gap'] or '0.5rem'
    local justify = args['justify'] or 'flex-start'
    local direction

    if columns then
        direction = 'row'
    end

    html:css('--template-flexbox-columns', columns)
    html:css('--template-flexbox-gap', gap)
    html:css('--template-flexbox-justify', justify)

    -- Loop over content arguments
    for i, _ in ipairs(getArgNums('content', args)) do
        local num = tostring(i)
        local content = args['content' .. num]
        if not content then return end

        local item = mw.html.create('div'):addClass('template-flexbox-item')
        item:wikitext(content)
        html:node(item)
    end

    return frame:extensionTag {
        name = 'templatestyles', args = { src = 'Module:Flexbox/styles.css' }
    } .. tostring(html)
end


-- Ensure the module returns the table 'p'
return p