Module:Newarticletext

From Coral Island Wiki
Revision as of 10:39, 9 August 2023 by Admin coral island (talk | contribs) (Created page with "local p = {} function p.main(frame) local td_attr = { valign='top' } local td_css = { width='50%' } local title = frame:getParent():getTitle() local sections = mw.loadData('Module:Newarticletext/data') local output = {} -- For Each Section for i,section_data in ipairs(sections) do if section_data['header'] and section_data['sections'] then local evenTest local section = page_layout(...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}
function p.main(frame)
    local td_attr = {
        valign='top'
    }
    local td_css = {
        width='50%'
    }

    local title = frame:getParent():getTitle()
    local sections = mw.loadData('Module:Newarticletext/data')
    
    local output = {}
    -- For Each Section
    for i,section_data in ipairs(sections) do
        if section_data['header'] and section_data['sections'] then
            local evenTest
            local section = page_layout(section_data['header'])
            local row
            local column
            -- For Each Link Area
            for j,link_data in ipairs(section_data['sections']) do
                evenTest = j%2
                if evenTest==1 then
                    row = section:tag('tr')
                end
                column = row:tag('td')
                    :attr(td_attr):css(td_css)
                if (type(link_data['link']) == 'table') then
                    local ul = column:wikitext(link_data['text'] .. '<br/>'):tag('ul')
                        :addClass('pipe_delimit')
                        :css('font-size',link_data['link']['size'])
                    for k,sub_link in ipairs(link_data['link']) do
                        ul:tag('li')
                            :wikitext(preload_link(title,sub_link['link'],sub_link['text']))
                    end
                else
                    column:wikitext(preload_link(title,link_data['link'],tostring(link_data['text'])))
                end
            end
            if evenTest==1 then
                column:attr('colspan',2)
            end
            table.insert(output, tostring(section))
        end
    end

    return table.concat(output)
end
function preload_link(page,preload,display)
    return '[' .. tostring(
        mw.uri.fullUrl(page,{
            action='edit',
            preload=preload
        })
    ) .. ' ' .. display .. ']'
end
function page_layout(section_title)
    local table_attr = {
        class                 = 'wikitable mw-collapsible mw-collapsed plainlinks',
        ['data-expandtext']   = '+',
        ['data-collapsetext'] = '-'
    }
    local table_css = {
        width          = '100%',
        ['text-align'] = 'center'
    }

    return mw.html.create('table')
        :attr(table_attr)
        :css(table_css)
        :tag('tr'):tag('th')
            :attr('colspan',2)
            :wikitext(section_title)
            :allDone()
end
return p