Модуль:Сущность: различия между версиями

мНет описания правки
Нет описания правки
Строка 42: Строка 42:
end
end


local function renderTitleBlock(key, tplCalls, sources, includeHeader)
local function renderTitleBlock(key, tplCalls, sources, includeHeader, frame)
     local parts = {}
     local parts = {}
    if includeHeader then table.insert(parts, "<h2>" .. mw.text.encode(key) .. "</h2>") end
     if tplCalls and #tplCalls > 0 then
     if tplCalls and #tplCalls > 0 then
         for i, tpl in ipairs(tplCalls) do
         for i, tpl in ipairs(tplCalls) do
             local line = tpl
             local add = true
             local src = sources and sources[i]
            if frame then
            line = '<div>' .. line .. '</div><div class="ts-Сущность-field">' .. makeSourceLink(src) .. '</div>'
                local expanded = frame:preprocess(tpl)
            table.insert(parts, '<div class="ts-Сущность">' .. line .. '</div>')
                add = expanded and trim(expanded) ~= ""
            end
             if add then
                local src = sources and sources[i]
                local line = '<div>' .. tpl .. '</div><div class="ts-Сущность-field">' .. makeSourceLink(src) .. '</div>'
                table.insert(parts, '<div class="ts-Сущность">' .. line .. '</div>')
            end
        end
        if #parts == 0 then
            return ""
        end
        if includeHeader then
            table.insert(parts, 1, "<h2>" .. mw.text.encode(key) .. "</h2>")
         end
         end
     end
     end
Строка 72: Строка 83:
     },
     },
     title = {
     title = {
         wrapper = function(key, tplCalls, sources)
         wrapper = function(key, tplCalls, sources, frame)
             return renderTitleBlock(key, tplCalls, sources, true)
             return renderTitleBlock(key, tplCalls, sources, true, frame)
         end
         end
     }
     }
Строка 127: Строка 138:
             end
             end
             if noHeaders and sw == "title" then
             if noHeaders and sw == "title" then
                 local outStr = renderTitleBlock(key, tplCalls, sources, false)
                 local outStr = renderTitleBlock(key, tplCalls, sources, false, frame)
                 if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
                 if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
             else
             else
                 if cfg.wrapper then
                 if cfg.wrapper then
                     local outStr = cfg.wrapper(key, tplCalls, sources)
                     local outStr = cfg.wrapper(key, tplCalls, sources, frame)
                     if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
                     if outStr and outStr ~= "" then table.insert(outLocal, outStr) end
                 end
                 end
Строка 415: Строка 426:
     end
     end


     return frame:preprocess(table.concat(out, "\n"))
     return table.concat(out, "\n")
end
end


return p
return p