A large portion of relevant modules/templates have now been switched to cargo. Various usages of SMW throughout the wiki need to be replaced by the new functions, in particular item tables. If some pages do not show up but contain no errors, please null-edit them. To see how you can help with the port check out Path_of_Exile_Wiki:To-do_list/SMW_migration (and leave a comment on the talk page if you have questions).

Module:SMW result formats

From Path of Exile Wiki
Jump to: navigation, search

Overview

Module for implementing templates for use in Semantic MediaWiki result formatting.

List of currently implemented templates

Tests

YesY All tests passed.

Name Expected Actual
YesY test_generic_list

local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local m_game = require('Module:Game')


local g_frame, g_args

-- ----------------------------------------------------------------------------
-- Page
-- ----------------------------------------------------------------------------

local p = {}
p.default_separator = ';'

-- ----------------------------------------------------------------------------
-- Section generic templates
-- ----------------------------------------------------------------------------

--
-- Template: SMW generic link
--

function p.generic_link(frame)
    -- Args
    g_args = getArgs(frame, {
        parentFirst = true
    })
    g_frame = util.misc.get_frame(frame)
    
    --
    local args = util.string.split_args(g_args.userparam, {sep=', '})
    g_args.userparam = args
    
    local extra = {}
    
    local i = 3
    local j
    local text = g_args[i]
    while text ~= nil do
        text = string.gsub(text, '<br>', '&nbsp;&nbsp;')
        j = i - 2 
        if args['color' .. j] then
            text = g_frame:expandTemplate{title='C', args={args['color' .. j], text}}
        end
        
        if args['template' .. j] then
            local tplargs
            if args['template' .. j .. '_args'] then
                tplargs = util.string.split_args(args['template' .. j .. '_args'], {sep='; '})
            else
                tplargs = {}
            end
            
            tplargs.text = text
            
            text = g_frame:expandTemplate{title=args['template' .. j], args=tplargs}
        end
        
        table.insert(extra, text)
        
        i = i + 1
        text = g_args[i]
    end
    
    local extra_text = ''
    if #extra > 0 then
        extra_text = string.format(' %s%s%s', args.intro or '(', table.concat(extra, args.sep or ', '), args.outro or ')')
    end
    
    if args['template'] then
        local tplargs
        if args['template_args'] then
            tplargs = util.string.split_args(args['template_args'], {sep='; '})
        else
            tplargs = {}
        end
        tplargs[1] = g_args[1]
        tplargs[2] = g_args[2]
        tplargs.page = g_args[1]
        tplargs.text = g_args[2]
        text = g_frame:expandTemplate{title=args['template'], args=tplargs}
    else
        text = string.format('[[%s|%s]]', g_args[1], g_args[2])
    end
    
    if args['color'] then
        text = g_frame:expandTemplate{title='C', args={args['color'], text}}
    end
    
    return text .. extra_text
end

--
-- Template: SMW generic list
--
function p.generic_list(frame)
    -- Args
    g_args = getArgs(frame, {
        parentFirst = true
    })
    g_frame = util.misc.get_frame(frame)
    
    --
    local args = util.string.split_args(g_args.userparam, {sep=', '})
    g_args.userparam = nil
    
    --
    out = {}
    
    for i, v in ipairs(g_args) do
        out[#out+1] = v 
    end
    
    for k, v in pairs(g_args) do
        if type(k) ~= 'number' then
            out[#out+1] = string.format('%s=%s', k, v or '')
        end
    end
    
    return table.concat(out, args.sep or p.default_separator) .. (args.rowsep or '\n')
end

--
--
--

return p