Module:Sandbox

From Path of Exile 2 Wiki
Revision as of 14:00, 2 July 2015 by >OmegaK2
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]


This page is not an actual Scribunto module. It exists to provide editors a place to create experimental modules.

Naming your modules

To keep things tidy, please use the following format to name your experimental modules:

Module:Sandbox/Your username/Module name

Cleaning up unused modules

Experimental modules may be deleted by admins upon request or after a long period of inactivity.

List of modules in this area

For a list of the experimental modules under Module:Sandbox, see Special:PrefixIndex/Module:Sandbox/.

local p = {}
local getArgs

-- for testing
local quest_data = {
    {
        reward="Ground Slam",
        reward_type="skill",
        class="Marauder",
        difficulty="Normal",
        quest="Enemy at the Gate",
    },
    {
        reward="Molten Strike",
        reward_type="skill",
        class="Marauder",
        difficulty="Normal",
        quest="Enemy at the Gate",
    },
}

function p.table(frame)
    if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
    local args = getArgs(frame, {
		parentFirst = true
	})
    
    args.reward = args.reward or args.Reward
    args.reward_type = args.reward_type or args.rewardType or args.RewardType
    args.class = args.class or args.Class
    args.difficulty = args.difficulty or args.Difficulty
    args.quest = args.quest or args.Quest
    args.display_style = args.display_style or args.displayStyle or args.DisplayStyle
    
    -- parser
    
    local return_data = {}
    
    
    for key, row in ipairs(quest_data) do
        (function()
            for k, v in ipairs({"reward", "reward_type", "class", "quest", "difficulty"}) do
                if args[v] ~= nil and row[v] ~= args[v] then return end
            end
            
            return_data.insert(row)
        end)()
    end
    
    local tbl = mw.html.create('table')
    
    tbl
        :tag('tr')
            :tag('th')
                :wikitext('test')
    
    
    for key, row in ipairs(return_data) do
        local output
        if row['reward_type'] == 'skill' then
            output = '{{sl|' .. row['reward'] .. '}}'
        elseif row['reward_type'] == 'item' then
            output = '{{il|' .. row['reward'] .. '}}'
        else
            output = row['reward']
        end
         
        if row['display'] ~= nil then
            output = replace_vars{row[display], reward=output}
        end
        
        tbl
            :tag('tr')
                :tag('td')
                    :wikitext(output)
        
    end
    
    return 
end

function replace_vars(str, vars)
  -- Allow replace_vars{str, vars} syntax as well as replace_vars(str, {vars})
  if not vars then
    vars = str
    str = vars[1]
  end
  return (string_gsub(str, "({([^}]+)})",
    function(whole,i)
      return vars[i] or whole
    end))
end

return p