RuneScape Wiki
Register
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 store = args['store'..i] or ''
+
local locationwithlink = args['location'] or edit
  +
local location = string.gsub(string.gsub(locationwithlink, '%[%[', ''), '%]%]', '')
-- stop if nothing
 
if not store:find('%S') then
 
break
 
end
 
   
-- item cost
+
-- item cost
local cost = string.lower(args['price'..i] or '')
+
local cost = string.lower(args['price'] or '')
if cost == 'free' or cost == '0' or cost == 'sample' then
+
if cost == 'free' or cost == '0' or cost == 'sample' then
cost = 0
+
cost = free_sample
else
+
else
if cost:find('%S') then
+
if cost:find('%S') then
cost = string.gsub(cost,',','')
+
cost = string.gsub(cost,',','')
cost = tonumber(cost)
+
cost = tonumber(cost)
if not cost then
+
if cost then
cost = edit
+
cost = commas(cost)
end
 
 
else
 
else
 
cost = edit
 
cost = edit
 
end
 
end
 
else
 
cost = edit
 
end
 
end
 
end
   
-- currency
+
-- currency
local currency = args['currency'..i] or ''
+
local currency = args['currency'] or ''
if currency:find('%S') and not (string.match(currency:lower(),'^coin')) and cost ~= 0 then
+
if currency:find('%S') and not (string.match(currency:lower(),'^coin')) and cost ~= free_sample then
local currencyimg = args['currencyimg'..i]
+
local currencyimg = args['currencyimg']
if currencyimg then
+
if currencyimg then
currency = string.format('[[File:%s|link=]]%s ',currencyimg,currency)
+
currency = string.format('[[File:%s|link=]]%s ',currencyimg,currency)
end
 
elseif cost == 0 then
 
currency = '-'
 
else
 
currency = string.format('[[File:%s|link=]]%s ',coins_image(tonumber(cost) or 100),'Coins')
 
 
end
 
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
+
-- base amount in stock
local stock = args['stock'..i] or ''
+
local stock = args['stock'] or ''
if stock:find('%S') then
+
if stock:find('%S') then
stock = string.gsub(stock,',','')
+
stock = string.lower(string.gsub(stock,',',''))
  +
if stock == '∞' or stock == 'inf' or stock == 'infinite' then
  +
stock = '∞'
  +
else
 
stock = tonumber(stock)
 
stock = tonumber(stock)
 
end
if not stock then
 
 
if not stock then
stock = edit
 
end
 
else
 
 
stock = edit
 
stock = edit
 
end
 
end
  +
else
  +
stock = edit
 
end
   
-- members only?
+
-- members only?
local mems = string.lower(args['members'..i] or '')
+
local mems = string.lower(args['members'] or '')
if mems == 'yes' then
+
if mems == 'yes' then
mems = true
+
mems = true
elseif mems == 'no' then
+
elseif mems == 'no' then
mems = false
+
mems = false
else
+
else
mems = 0
+
mems = 0
end
 
 
table.insert(_args, { store = store, cost = cost, currency = currency, stock = stock, mems = mems} )
 
 
end
 
end
  +
 
_args = { store = store, location = location, cost = cost, currency = currency, stock = stock, mems = mems}
   
 
return p._main(_args)
 
return p._main(_args)
Line 82: Line 87:
 
}
 
}
   
local ret = mw.html.create('table')
+
local ret = mw.html.create('tr')
 
if args.mems == true then
:addClass('wikitable')
 
:tag('tr')
+
ret:addClass('members-line')
 
end
:tag('th')
 
:wikitext('Seller')
 
:done()
 
:tag('th')
 
:wikitext('Cost')
 
:done()
 
:tag('th')
 
:wikitext('Currency')
 
:done()
 
:tag('th')
 
:wikitext('Base stock')
 
:done()
 
:tag('th')
 
:wikitext('Members?')
 
:done()
 
:done()
 
for _, v in ipairs(args) do
 
local row = ret:tag('tr')
 
if v.mems == true then
 
row:css('background','#CCC')
 
end
 
   
row :tag('td')
+
ret :tag('td')
:wikitext(v.store)
+
:wikitext(args.store)
:done()
+
:done()
:tag('td')
+
:tag('td')
 
:wikitext(args.location)
:css('text-align','right')
 
:wikitext(v.cost)
+
:done()
:done()
+
:tag('td')
:tag('td')
+
:css('text-align','right')
 
:wikitext(args.cost)
:css('text-align','right')
 
 
:done()
:wikitext(v.currency)
 
:done()
+
:tag('td')
:tag('td')
+
:css('text-align','right')
 
:wikitext(args.currency)
:css('text-align','right')
 
:wikitext(v.stock)
+
:done()
:done()
+
:tag('td')
:tag('td')
+
:css('text-align','right')
 
:wikitext(args.stock)
:css('text-align','center')
 
 
:done()
:wikitext(memsmap[v.mems])
 
:done()
+
:tag('td')
 
:css('text-align','center')
row:done()
 
 
:wikitext(memsmap[args.mems])
end
 
 
:done()
   
 
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