Module:Sandbox/BrandonXLF/3: Difference between revisions

Content deleted Content added
Automatically get flag
Theme navbox-image
 
(22 intermediate revisions by the same user not shown)
Line 1:
-- Sandbox, do not delete
 
return {
local getArgs = require('Module:Arguments').getArgs
aria_label = 'Navbox',
local yesno = require('Module:Yesno')
nowrap_item = '%s<span class="nowrap">%s</span>',
local p = {}
templatestyles = mw.getCurrentFrame():extensionTag{
 
name = 'templatestyles', args = { src = 'User:BrandonXLF/styles2.css' }
local function getCountry(country)
},
local title = mw.title.new(country)
hlist_templatestyles = 'Hlist/styles.css',
plainlist_templatestyles = 'Plainlist/styles.css',
if not title or not title.exists then
-- do not localize marker table
return country
marker = {
end
oddeven = '\127_ODDEVEN_\127',
restart = '\127_ODDEVEN0_\127',
return '[[' .. country .. ']]'
regex = '\127_ODDEVEN(%d?)_\127'
end
},
 
category = {
local function getTimespan(timespan)
orphan = '[[Category:Navbox orphans]]',
return ' (' .. timespan .. ')'
horizontal_lists = 'Navigational boxes without horizontal lists',
end
background_colors = 'Navboxes using background colours',
 
illegible = 'Potentially illegible navboxes',
local function getImage(image)
borders = 'Navboxes using borders',
local file = null
},
 
keyword = {
if string.match(image, '.-%.') then
border_subgroup = 'subgroup',
file = mw.getCurrentFrame():expandTemplate{title = 'flagicon image', args = {image}}
border_child = 'child',
elseif string.match(image, '.- %(.-%)') then
border_none = 'none',
local country, var = string.match(image,'(.-) %((.-)%)')
evenodd_swap = 'swap',
file = mw.getCurrentFrame():expandTemplate{title = 'flagdeco', args = {country, var, noredlink = 'y'}}
navbar_off = 'off',
else
navbar_plain = 'plain',
file = mw.getCurrentFrame():expandTemplate{title = 'flagdeco', args = {image, noredlink = 'y'}}
nocat_false = 'false',
end
nowrapitems_yes = 'yes',
orphan_yes = 'yes',
return file
state_collapsed = 'collapsed',
end
state_off = 'off',
 
state_plain = 'plain',
function p.main(frame)
subgroups = {'subgroup', 'child', ''},
local args = getArgs(frame)
subpage_doc = 'doc',
local hasFlags = false
subpage_sandbox = 'sandbox',
local entries = {}
subpage_testcases = 'testcases',
local i = 1
tracking_no = 'no'
local knownKeys = {
},
[''] = true,
class = {
['date'] = true,
autocollapse = 'autocollapse',
flag = true
collapsible = 'mw-collapsible',
collapsed = 'mw-collapsed',
-- Warning
navbox = 'navbox', -- WMF currently hides 'navbox' from mobile,
-- so you probably shouldn't change the navbox class.
navbox_abovebelow = 'navbox-abovebelow notheme',
navbox_group = 'navbox-group notheme',
navbox_image = 'navbox-image',
navbox_inner = 'navbox-inner notheme',
navbox_list = 'navbox-list notheme',
navbox_list_with_group = 'navbox-list-with-group',
navbox_part = 'navbox-', -- do not l10n
navbox_styles = 'navbox-styles',
navbox_subgroup = 'navbox-subgroup',
navbox_title = 'navbox-title notheme', -- l10n only if you change pattern.navbox_title below
navbox_odd_part = 'odd', -- do not l10n
navbox_even_part = 'even', -- do not l10n
nomobile = 'nomobile',
nowraplinks = 'nowraplinks',
noviewer = 'noviewer' -- used to remove images from MediaViewer
},
pattern = {
listnum = '^list(%d+)$',
class = 'class',
sandbox = '/sandbox$',
navbox = 'Template:Navbox',
nowrap = '^<span class="nowrap">',
style = 'style$',
navbox_title = '<th[^>]*"navbox%-title"',
hlist = 'hlist',
plainlist = 'plainlist',
},
arg = {
above = 'above',
aboveclass = 'aboveclass',
abovestyle = 'abovestyle',
basestyle = 'basestyle',
bodyclass = 'bodyclass',
bodystyle = 'bodystyle',
border = 'border',
below = 'below',
belowclass = 'belowclass',
belowstyle = 'belowstyle',
evenodd = 'evenodd',
evenstyle = 'evenstyle',
group1 = 'group1',
group2 = 'group2',
group_and_num = 'group%d',
groupstyle_and_num = 'group%dstyle',
groupclass = 'groupclass',
groupstyle = 'groupstyle',
groupwidth = 'groupwidth',
innerstyle = 'innerstyle',
image = 'image',
imageclass = 'imageclass',
imageleft = 'imageleft',
imageleftstyle = 'imageleftstyle',
imagesetyle = 'imagestyle',
list_and_num = 'list%d',
listclass_and_num = 'list%dclass',
liststyle_and_num = 'list%dstyle',
list1padding = 'list1padding',
listclass = 'listclass',
listpadding = 'listpadding',
liststyle = 'liststyle',
name = 'name',
navbar = 'navbar',
navboxclass = 'navboxclass',
nocat = 'nocat',
nowrapitems = 'nowrapitems',
oddstyle = 'oddstyle',
orphan = 'orphan',
state = 'state',
style = 'style',
templatestyles = 'templatestyles',
child_templatestyles = 'child templatestyles',
title = 'title',
titleclass = 'titleclass',
titlestyle = 'titlestyle',
tracking = 'tracking'
},
-- names of navbar arguments
navbar = {
name = 1,
fontstyle = 'fontstyle',
mini = 'mini'
}
}
 
for i, entry in ipairs(args) do
local country
local timespan
local flag
local data = {}
for line in entry:gmatch('[^\n]+') do
line = mw.text.trim(line)
local key, val = line:match('^([a-z]*):? *(.*)$')
if knownKeys[key] then
data[key] = val
else
return require('Module:Error').error{'Invalid key ' .. key .. ' in argument ' .. i}
end
end
if data[''] then
data[''] = getCountry(data[''])
else
return require('Module:Error').error{'A country is required in argument ' .. i}
end
if data['date'] then
data['date'] = getTimespan(data['date'])
else
return require('Module:Error').error{'A date is required in argument ' .. i}
end
if data.flag then
hasFlags = true
end
data['flag'] = getImage((yesno(data['flag']) == false and '') or data['flag'] or data[''] or '')
table.insert(entries, data)
end
local container = mw.html.create('div')
:addClass('historical-affiliation')
:css('float', args.float or 'left')
local titleId = math.random()
 
container:tag('div')
:attr('id', titleId)
:addClass('historical-affiliation-title')
:wikitext(args.title and args.title or 'Historical affiliations')
local list = container:tag('ul')
:attr('aria-labelledby', titleId)
:addClass('historical-affiliation-list')
 
for i, entry in ipairs(entries) do
local item = list:tag('li');
item:tag('span')
:wikitext(entry.flag)
item:tag('span')
:wikitext(entry[''] .. entry['date'])
end
 
return tostring(container) .. frame:extensionTag{
name = 'templatestyles',
args = { src = 'User:BrandonXLF/J/styles.css' }
}
end
 
return p