Module:Sandbox/BrandonXLF/4: Difference between revisions

Content deleted Content added
Add spaces
Fix errors
 
(15 intermediate revisions by the same user not shown)
Line 2:
local p = {}
 
local roadDataModule = require('Module:Road data/sandbox') -- REMOVE SANDBOX
function p.main(frame)
 
local wikitext = frame:preprocess(frame.args[1])
function p._shieldmain(args)
local itemsshields = {}
local toCloserouteCount = {}1
while args[routeCount * 2 - 1] do
-- Parse each row
local outroute = ''{
for indent, item in wikitext:gmatch("(**) *([^\n]+)") do
country = args['country' .. routeCount] or args.country,
items[#items + 1] = {'*' .. indent, item}
state = args['state' .. routeCount] or args['province' .. routeCount] or args.state or args.province,
end
type = args[routeCount * 2 - 1],
route = args[routeCount * 2]
local toClose = {}
}
local out = ''
 
-- Bold sublist titles and add a blank list item before them
-- The blank item is used by CSS to make the list item block leel
for i, item in pairs(items) do
-- Close <li> and <ul> enclosing deeper items
while #toClose > 0 and #toClose[#toClose][1] >= #item[1] do
out = out .. toClose[#toClose][2]
table.remove(toClose, #toClose)
end
if not route.country then
-- Create new lists
local countryModule = mw.loadData('Module:Road data/countrymask')
while #toClose > 0 and (#toClose[#toClose][1] + 1 < #item[1] or toClose[#toClose][2] ~= '</ul>') do
route.country = countryModule[route.state] or 'UNK'
out = out .. '<ul>'
toClose[#toClose + 1] = { item[1]:sub(1, -2), '</ul>' }
end
 
local shield = roadDataModule.shield(route, 'main', 'infobox', true)
-- Added by {{Keep inline}}
table.insert(shields, shield)
local keepInline = item[2]:match('KEEP%-INLINE$') ~= nil
 
routeCount = routeCount + 1
if keepInline then
out = out .. '<li>'
out = out .. item[2]:gsub(' *KEEP%-INLINE$', '') .. '<span class="content-list-inline"></span>'
elseif i < #items and #items[i + 1][1] > #item[1] then
out = out .. '<li class="content-sublist">'
out = out .. "'''''" .. item[2] .. "&#58; '''''"
else
out = out .. '<li>'
out = out .. item[2]
end
toClose[#toClose + 1] = { item[1], '</li>' }
end
 
return '<pre>' table.. mw.text.encodeconcat(out) ..shields, '</pre>&thinsp;' ..)
end
 
'<div class="content-list"><ul>\n' .. out .. '</ul></div>' .. frame:extensionTag{
function p.mainshieldmain(frame)
name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
local args = require('Module:Arguments').getArgs(frame)
}
return p._shieldmain(args)
end