ФЭНДОМ


-- <nowiki>
local p = {}
 
function p.main(frame)
    frame = frame:getParent()
 
    local stage = frame.args["состояние"] or ''
    local title = frame.args["название"] or ''
    local url = frame.args["url"] or ''
    local description = frame.args["описание"] or ''
    local workers = frame.args["работали"] or ''
 
    if #(stage..title..url..description..workers) == 0 then
        return ''
    end
 
    local result = mw.html.create('div')
        :addClass('wiki-card')
        :addClass(stage)
 
    if #(title..url) ~= 0 then
        local header = result
            :tag('div')
            :addClass('wc-header')
 
        if #url ~= 0 then
            header
                :tag('span')
                :wikitext('[http://'..url..'.wikia.com '..url..'.wikia.com]')
                :done()
        end
 
        if #title ~= 0 then
            header
                :tag('div')
                :addClass('wc-title')
                :wikitext(title)
                :done()
        end
 
        header:done()
    end
 
    if #(description..workers) ~= 0 then
        local details = result
            :tag('div')
            :addClass('wc-details')
 
        if #description ~= 0 then
            details
                :tag('div')
                :addClass('wc-description')
                :wikitext(description)
                :done()
        end
 
        if #workers ~= 0 then
            local work = {
                ["articles"] = "pencil",
                ["code"] = "code",
                ["design"] = "paint-brush"
            }
 
            local aliases = {
                ["articles"] = "articles",
                ["a"] = "articles",
                ["статьи"] = "articles",
                ["крейсер"] = "articles",
                ["code"] = "code",
                ["c"] = "code",
                ["код"] = "code",
                ["корвет"] = "code",
                ["design"] = "design",
                ["d"] = "design",
                ["дизайн"] = "design",
                ["истребитель"] = "design"
            }
 
            local tags = details
                :tag('div')
                :addClass('wc-tags')
 
            for raw_data in mw.text.gsplit(workers, "%s*%]%s*") do
                local data = mw.text.split(raw_data, "%s*%[%s*")
                local username = data[1]
                local classname = data[2] and aliases[mw.ustring.lower(data[2])] or nil
 
                if #username ~= 0 then
                    local tag = tags
                        :tag('div')
                        :addClass('wc-tag')
                        :addClass(classname)
                    local icon = ''
 
                    if classname then
                        icon = icon..tostring(
                            mw.html.create('span')
                            :addClass('fa')
                            :addClass('fa-'..work[classname])
                            :done()
                        )
                    end
 
                    tag
                        :wikitext('[[User:'..username..'|'..icon..username..']]')
                        :done()
                end
            end
 
            tags:done()
        end
 
        details:done()
    end
 
    return tostring(result:allDone())
end
 
return p