Module:Harvest/sandbox: Difference between revisions
Jump to navigation
Jump to search
(Create sandbox version of Module:Harvest) |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
-- | ------------------------------------------------------------------------------- | ||
-- Module | -- | ||
-- | -- Module:Harvest | ||
-- | |||
-- This module implements Template:Harvest crafting options | |||
------------------------------------------------------------------------------- | |||
require('Module:No globals') | |||
local m_util = require('Module:Util') | |||
local m_cargo = require('Module:Cargo') | local m_cargo = require('Module:Cargo') | ||
-- Should we use the sandbox version of our submodules? | |||
local use_sandbox = m_util.misc.maybe_sandbox('Harvest') | |||
-- The cfg table contains all localisable strings and configuration, to make it | |||
-- easier to port this module to another wiki. | |||
local cfg = use_sandbox and mw.loadData('Module:Harvest/config/sandbox') or mw.loadData('Module:Harvest/config') | |||
local i18n = cfg.i18n | |||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- Cargo tables | -- Cargo tables | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
local tables = {} | local tables = {} | ||
tables.harvest_crafting_options = { | tables.harvest_crafting_options = { | ||
table = 'harvest_crafting_options', | table = 'harvest_crafting_options', | ||
fields = { | fields = { | ||
ordinal = { | ordinal = { | ||
Line 48: | Line 62: | ||
}, | }, | ||
} | } | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- | -- Data | ||
-- ---------------------------------------------------------------------------- | |||
local data = {} | |||
data.crafting_options_table = { | |||
{ | |||
field = 'effect_html', | |||
header = i18n.crafting_options.effect, | |||
}, | |||
{ | |||
field = 'cost_wild', | |||
header = i18n.crafting_options.wild, | |||
}, | |||
{ | |||
field = 'cost_vivid', | |||
header = i18n.crafting_options.vivid, | |||
}, | |||
{ | |||
field = 'cost_primal', | |||
header = i18n.crafting_options.primal, | |||
}, | |||
{ | |||
field = 'cost_sacred', | |||
header = i18n.crafting_options.sacred, | |||
}, | |||
} | |||
-- ---------------------------------------------------------------------------- | |||
-- Main functions | |||
-- ---------------------------------------------------------------------------- | |||
local function _crafting_options(tpl_args) | |||
local tbl = mw.html.create('table') | |||
tbl | |||
:addClass('wikitable sortable harvest-crafting-options-table') | |||
local tblhead = tbl:tag('tr') | |||
for _, tmap in ipairs(data.crafting_options_table) do | |||
tblhead | |||
:tag('th') | |||
:wikitext(tmap.header) | |||
:done() | |||
end | |||
local results = m_cargo.query( | |||
{tables.harvest_crafting_options.table}, | |||
m_util.table.column(data.crafting_options_table, 'field'), | |||
{ | |||
orderBy = 'ordinal ASC', | |||
} | |||
) | |||
local tblrow | |||
for _, row in ipairs(results) do | |||
tblrow = tbl:tag('tr') | |||
for _, tmap in ipairs(data.crafting_options_table) do | |||
tblrow | |||
:tag('td') | |||
:wikitext(row[tmap.field]) | |||
:done() | |||
end | |||
end | |||
return tostring(tbl) | |||
end | |||
-- ---------------------------------------------------------------------------- | |||
-- Exported functions | |||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
Line 55: | Line 134: | ||
p.table_harvest_crafting_options = m_cargo.declare_factory{data=tables.harvest_crafting_options} | p.table_harvest_crafting_options = m_cargo.declare_factory{data=tables.harvest_crafting_options} | ||
p.store_data = m_cargo.store_from_lua{tables=tables, module='Harvest'} | p.store_data = m_cargo.store_from_lua{tables=tables, module='Harvest'} | ||
-- ---- | -- | ||
-- Template:Harvest crafting options | |||
-- | |||
p.crafting_options = m_util.misc.invoker_factory(_crafting_options, { | |||
wrappers = cfg.wrappers.crafting_options, | |||
}) | |||
return p | return p |
Latest revision as of 22:25, 29 August 2022
This is the module sandbox page for Module:Harvest (diff).
The above documentation is transcluded from Module:Harvest/doc.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
-------------------------------------------------------------------------------
--
-- Module:Harvest
--
-- This module implements Template:Harvest crafting options
-------------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Harvest')
-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Harvest/config/sandbox') or mw.loadData('Module:Harvest/config')
local i18n = cfg.i18n
-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------
local tables = {}
tables.harvest_crafting_options = {
table = 'harvest_crafting_options',
fields = {
ordinal = {
field = 'ordinal',
type = 'Integer',
},
id = {
field = 'id',
type = 'String',
},
effect = {
field = 'effect',
type = 'Text',
},
effect_html = {
field = 'effect_html',
type = 'Text',
},
cost_wild = {
field = 'cost_wild',
type = 'Integer',
},
cost_vivid = {
field = 'cost_vivid',
type = 'Integer',
},
cost_primal = {
field = 'cost_primal',
type = 'Integer',
},
cost_sacred = {
field = 'cost_sacred',
type = 'Integer',
},
},
}
-- ----------------------------------------------------------------------------
-- Data
-- ----------------------------------------------------------------------------
local data = {}
data.crafting_options_table = {
{
field = 'effect_html',
header = i18n.crafting_options.effect,
},
{
field = 'cost_wild',
header = i18n.crafting_options.wild,
},
{
field = 'cost_vivid',
header = i18n.crafting_options.vivid,
},
{
field = 'cost_primal',
header = i18n.crafting_options.primal,
},
{
field = 'cost_sacred',
header = i18n.crafting_options.sacred,
},
}
-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------
local function _crafting_options(tpl_args)
local tbl = mw.html.create('table')
tbl
:addClass('wikitable sortable harvest-crafting-options-table')
local tblhead = tbl:tag('tr')
for _, tmap in ipairs(data.crafting_options_table) do
tblhead
:tag('th')
:wikitext(tmap.header)
:done()
end
local results = m_cargo.query(
{tables.harvest_crafting_options.table},
m_util.table.column(data.crafting_options_table, 'field'),
{
orderBy = 'ordinal ASC',
}
)
local tblrow
for _, row in ipairs(results) do
tblrow = tbl:tag('tr')
for _, tmap in ipairs(data.crafting_options_table) do
tblrow
:tag('td')
:wikitext(row[tmap.field])
:done()
end
end
return tostring(tbl)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
p.table_harvest_crafting_options = m_cargo.declare_factory{data=tables.harvest_crafting_options}
p.store_data = m_cargo.store_from_lua{tables=tables, module='Harvest'}
--
-- Template:Harvest crafting options
--
p.crafting_options = m_util.misc.invoker_factory(_crafting_options, {
wrappers = cfg.wrappers.crafting_options,
})
return p