mNo edit summary Tag: sourceedit |
m (test) |
||
(17 intermediate revisions by 4 users not shown) | |||
Line 6: | Line 6: | ||
local editbutton = require('Module:Edit button') |
local editbutton = require('Module:Edit button') |
||
local edit = editbutton("'''?''' (edit)") |
local edit = editbutton("'''?''' (edit)") |
||
+ | local commas = require('Module:Addcommas')._add |
||
+ | |||
+ | local free_sample = 'Free sample' |
||
function p.main(frame) |
function p.main(frame) |
||
Line 11: | Line 14: | ||
local _args = {} |
local _args = {} |
||
+ | local store = args['store'] or edit |
||
− | for i=1,20 do |
||
− | + | local locationwithlink = args['location'] or edit |
|
+ | local location = string.gsub(string.gsub(locationwithlink, '%[%[', ''), '%]%]', '') |
||
− | -- stop if nothing |
||
⚫ | |||
− | break |
||
⚫ | |||
− | + | -- item cost |
|
− | + | local cost = string.lower(args['price'] or '') |
|
− | + | if cost == 'free' or cost == '0' or cost == 'sample' then |
|
− | + | cost = free_sample |
|
− | + | else |
|
− | + | if cost:find('%S') then |
|
− | + | cost = string.gsub(cost,',','') |
|
− | + | cost = tonumber(cost) |
|
− | + | if cost then |
|
− | + | cost = commas(cost) |
|
⚫ | |||
else |
else |
||
cost = edit |
cost = edit |
||
end |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
− | + | -- currency |
|
− | + | local currency = args['currency'] or '' |
|
− | + | if currency:find('%S') and not (string.match(currency:lower(),'^coin')) and cost ~= free_sample then |
|
− | + | local currencyimg = args['currencyimg'] |
|
− | + | if currencyimg then |
|
− | + | currency = string.format('[[File:%s|link=]]%s ',currencyimg,currency) |
|
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | -- base amount in stock |
|
− | + | local stock = args['stock'] or '' |
|
− | + | if stock:find('%S') then |
|
− | + | stock = string.lower(string.gsub(stock,',','')) |
|
+ | if stock == '∞' or stock == 'inf' or stock == 'infinite' then |
||
+ | stock = '∞' |
||
+ | else |
||
stock = tonumber(stock) |
stock = tonumber(stock) |
||
⚫ | |||
− | if not stock then |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
stock = edit |
stock = edit |
||
end |
end |
||
+ | else |
||
+ | stock = edit |
||
⚫ | |||
− | + | -- members only? |
|
− | + | local mems = string.lower(args['members'] or '') |
|
− | + | if mems == 'yes' then |
|
− | + | mems = true |
|
− | + | elseif mems == 'no' then |
|
− | + | mems = false |
|
− | + | else |
|
− | + | mems = 0 |
|
⚫ | |||
− | |||
⚫ | |||
end |
end |
||
+ | |||
⚫ | |||
return p._main(_args) |
return p._main(_args) |
||
Line 82: | Line 87: | ||
} |
} |
||
− | local ret = mw.html.create(' |
+ | local ret = mw.html.create('tr') |
⚫ | |||
− | :addClass('wikitable') |
||
− | + | ret:addClass('members-line') |
|
⚫ | |||
− | :tag('th') |
||
⚫ | |||
⚫ | |||
− | :tag('th') |
||
⚫ | |||
⚫ | |||
− | :tag('th') |
||
⚫ | |||
⚫ | |||
− | :tag('th') |
||
⚫ | |||
− | :done() |
||
− | :tag('th') |
||
⚫ | |||
− | :done() |
||
− | :done() |
||
− | for _, v in ipairs(args) do |
||
− | local row = ret:tag('tr') |
||
⚫ | |||
⚫ | |||
− | end |
||
− | + | ret :tag('td') |
|
− | + | :wikitext(args.store) |
|
− | + | :done() |
|
− | + | :tag('td') |
|
⚫ | |||
− | :css('text-align','right') |
||
− | + | :done() |
|
− | + | :tag('td') |
|
− | : |
+ | :css('text-align','right') |
⚫ | |||
− | :css('text-align','right') |
||
⚫ | |||
− | :wikitext(v.currency) |
||
− | + | :tag('td') |
|
− | : |
+ | :css('text-align','right') |
⚫ | |||
− | :css('text-align','right') |
||
− | + | :done() |
|
− | + | :tag('td') |
|
− | : |
+ | :css('text-align','right') |
⚫ | |||
− | :css('text-align','center') |
||
⚫ | |||
− | :wikitext(memsmap[v.mems]) |
||
− | + | :tag('td') |
|
⚫ | |||
− | row:done() |
||
⚫ | |||
− | end |
||
⚫ | |||
return ret |
return ret |
Latest revision as of 20:42, 2 May 2018
Documentation for this module may be created at Module:SellersLine/doc
-- <pre>
local p = {}
local coins_image = require('Module:Coins image')
local editbutton = require('Module:Edit button')
local edit = editbutton("'''?''' (edit)")
local commas = require('Module:Addcommas')._add
local free_sample = 'Free sample'
function p.main(frame)
local args = frame:getParent().args
local _args = {}
local store = args['store'] or edit
local locationwithlink = args['location'] or edit
local location = string.gsub(string.gsub(locationwithlink, '%[%[', ''), '%]%]', '')
-- item cost
local cost = string.lower(args['price'] or '')
if cost == 'free' or cost == '0' or cost == 'sample' then
cost = free_sample
else
if cost:find('%S') then
cost = string.gsub(cost,',','')
cost = tonumber(cost)
if cost then
cost = commas(cost)
else
cost = edit
end
else
cost = edit
end
end
-- currency
local currency = args['currency'] or ''
if currency:find('%S') and not (string.match(currency:lower(),'^coin')) and cost ~= free_sample then
local currencyimg = args['currencyimg']
if currencyimg then
currency = string.format('[[File:%s|link=]]%s ',currencyimg,currency)
end
elseif cost == free_sample then
currency = '-'
else
currency = string.format('[[File:%s|link=]]%s ',coins_image(tonumber(cost) or 100),'Coins')
end
-- base amount in stock
local stock = args['stock'] or ''
if stock:find('%S') then
stock = string.lower(string.gsub(stock,',',''))
if stock == '∞' or stock == 'inf' or stock == 'infinite' then
stock = '∞'
else
stock = tonumber(stock)
end
if not stock then
stock = edit
end
else
stock = edit
end
-- members only?
local mems = string.lower(args['members'] or '')
if mems == 'yes' then
mems = true
elseif mems == 'no' then
mems = false
else
mems = 0
end
_args = { store = store, location = location, cost = cost, currency = currency, stock = stock, mems = mems}
return p._main(_args)
end
function p._main(args)
local memsmap = {
[true] = 'Yes',
[false] = 'No',
[0] = edit
}
local ret = mw.html.create('tr')
if args.mems == true then
ret:addClass('members-line')
end
ret :tag('td')
:wikitext(args.store)
:done()
:tag('td')
:wikitext(args.location)
:done()
:tag('td')
:css('text-align','right')
:wikitext(args.cost)
:done()
:tag('td')
:css('text-align','right')
:wikitext(args.currency)
:done()
:tag('td')
:css('text-align','right')
:wikitext(args.stock)
:done()
:tag('td')
:css('text-align','center')
:wikitext(memsmap[args.mems])
:done()
return ret
end
return p