Module:Skill link and Module:Skill link/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
(No globals. Use invoker factory from Module:Util.)
 
No edit summary
 
Line 3: Line 3:
--                              Module:Skill link
--                              Module:Skill link
--  
--  
-- This module implements [[Template:Skill link]] and
-- This module implements Template:Skill link
-- [[Template:Query skill infobox]]
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------


require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')


-- Should we use the sandbox version of our submodules?
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Skill link')
local use_sandbox = m_util.misc.maybe_sandbox('Skill link')
local m_cargo = use_sandbox and require('Module:Cargo/sandbox') or require('Module:Cargo')


-- The cfg table contains all localisable strings and configuration, to make it
-- The cfg table contains all localisable strings and configuration, to make it
Line 49: Line 47:
function h.format_skill_icon(skill, tpl_args)
function h.format_skill_icon(skill, tpl_args)
     --[[
     --[[
        Add a skill image.
    Add a skill image.
     ]]
     ]]
     if tpl_args.icon ~= nil then
     if tpl_args.icon ~= nil then
         skill['skill.skill_icon'] = tpl_args.icon
         skill['skill.skill_icon'] = tpl_args.icon
Line 78: Line 78:


-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Main functions
-- Exported functions
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------


local function _query_skill_infobox(tpl_args)
local p = {}
 
function p.skill_infobox_link(frame)
     --[[
     --[[
     Finds and shows the infobox of a skill.
     Finds and shows the infobox of a skill.
Line 89: Line 91:
     = p.skill_infobox_link{"Icestorm"}
     = p.skill_infobox_link{"Icestorm"}
     = p.skill_infobox_link{q_where = 'skill.active_skill_name="Icestorm"'}
     = p.skill_infobox_link{q_where = 'skill.active_skill_name="Icestorm"'}
     ]]
     ]]
    -- Get args
    tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)


     if tpl_args.id and (tpl_args.q_where == nil) then
     if tpl_args.id and (tpl_args.q_where == nil) then
Line 160: Line 169:
         },
         },
     }
     }
     local out = {}
     out = {}
     local cats = {}
     local cats = {}
     for _,v in ipairs(err_tbl) do
     for _,v in ipairs(err_tbl) do
Line 184: Line 193:
         end
         end


         -- Store as main page
         -- Store as main page:
        tpl_args.main = tpl_args.main and m_util.cast.boolean(tpl_args.main) or mw.title.getCurrentTitle():inNamespace(0)
         m_cargo.store(
         if tpl_args.main then
            {
            m_cargo.store(
                _table='main_pages',
                {
                id=v['skill.skill_id'],
                    _table='main_pages',
             }
                    data_page = v['skill._pageName'],
         )
                    id = v['skill.skill_id'],
                    name = v['skill.active_skill_name'],
                }
             )
            mw.getCurrentFrame():expandTemplate{title = cfg.attach_template}
         end
     end
     end


Line 202: Line 205:
end
end


local function _skill_link(tpl_args)
--
-- Template:Skill link
--
function p.skill_link(frame)
     --[[
     --[[
     Links a skill
     Links a skill
Line 217: Line 223:
     }
     }
     ]]
     ]]
    -- Get args
    local tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)


     tpl_args.skill_name = tpl_args.skill_name or tpl_args[1]
     tpl_args.skill_name = tpl_args.skill_name or tpl_args[1]
Line 372: Line 384:
             :node(activator)
             :node(activator)
             :node(display)
             :node(display)
            :done()


         return tostring(container)
         return tostring(container)
Line 383: Line 396:
     end
     end
end
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
--
-- [[Template:Skill link]]
--
p.skill_link = m_util.misc.invoker_factory(_skill_link, {
    wrappers = cfg.wrappers.skill_link,
})
--
-- [[Template:Query skill infobox]]
--
p.query_skill_infobox = m_util.misc.invoker_factory(_query_skill_infobox, {
    wrappers = cfg.wrappers.query_skill_infobox,
})


return p
return p