Module:Timeline

From wikilawschool.org. Wiki Law School does not provide legal advice. For educational purposes only.
-- TimelineModule.lua

local p = {}

function p.createTimeline(...)
    local events = {...}
    local output = mw.html.create()

    output:tag('div')
        :addClass('container')
        :wikitext('\n')

    output:tag('div')
        :addClass('row')
        :wikitext('\n')

    output:tag('div')
        :addClass('col-md-12 col-sm-12 col-xs-12')
        :wikitext('\n')

    output:tag('section')
        :addClass('main-timeline-section')
        :wikitext('\n')

    for i = 1, #events, 2 do
        local text = events[i]
        local date = events[i + 1]

        if text and date then
            output:tag('div')
                :addClass('timeline-article timeline-article-top')
                :wikitext('\n')

            output:tag('div')
                :addClass('content-date')
                :wikitext('<span>' .. date .. '</span>')
                :wikitext('\n</div>')

            output:tag('div')
                :addClass('meta-date')
                :wikitext('\n</div>')

            output:tag('div')
                :addClass('content-box')
                :wikitext('\n<p>' .. text .. '</p>\n</div>')

            output:wikitext('\n</div>')
        end
    end

    for i = 2, #events, 2 do
        local text = events[i]
        local date = events[i + 1]

        if text and date then
            output:tag('div')
                :addClass('timeline-article timeline-article-bottom')
                :wikitext('\n')

            output:tag('div')
                :addClass('content-date')
                :wikitext('<span>' .. date .. '</span>')
                :wikitext('\n</div>')

            output:tag('div')
                :addClass('meta-date')
                :wikitext('\n</div>')

            output:tag('div')
                :addClass('content-box')
                :wikitext('\n<p>' .. text .. '</p>\n</div>')

            output:wikitext('\n</div>')
        end
    end

    output:wikitext('\n</section>\n</div>\n</div>\n</div>\n</div>')

    return tostring(output)
end

return p