Module:Military navigation: Difference between revisions
Appearance
imported>Plastikspork m Protected "Module:Military navigation": High-risk Lua module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)) |
imported>Frietjes don't auto wrap lines with br tags |
||
| Line 56: | Line 56: | ||
if args['title'] and (pargs['style'] or '') ~= 'wide' then | if args['title'] and (pargs['style'] or '') ~= 'wide' then | ||
if not mw.ustring.match(args['title'], '<span class="wrap">') then | if not mw.ustring.match(args['title'], '<span class="wrap">') then | ||
local p = '[^%[%]|][^%[%]|][^%[%]|][^%[%]|][^%[%]|]' | local p = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]' | ||
local p = p .. p .. p | local p = p .. p .. p | ||
args['title'] = mw.ustring.gsub(args['title'], | args['title'] = mw.ustring.gsub(args['title'], | ||
'%[%[(' .. p .. '[^%[%]|]*)%]%]', | '%[%[(' .. p .. '[^%[%]<>|]*)%]%]', | ||
'[[%1|<span class="wrap">%1</span>]]') | '[[%1|<span class="wrap">%1</span>]]') | ||
args['title'] = mw.ustring.gsub(args['title'], | args['title'] = mw.ustring.gsub(args['title'], | ||
'%[%[([^%[%]|]*)|(' .. p .. '[^%[%]|]*)%]%]', | '%[%[([^%[%]<>|]*)|(' .. p .. '[^%[%]<>|]*)%]%]', | ||
'[[%1|<span class="wrap">%2</span>]]') | '[[%1|<span class="wrap">%2</span>]]') | ||
end | end | ||
Revision as of 13:55, 5 May 2017
Documentation for this module may be created at Module:Military navigation/doc
local p = { }
local Navbox = require('Module:Navbox')
local Styles = require('Module:WPMILHIST Infobox style')
local function isblank(s)
return (not s) or s == ''
end
local function isnotblank(s)
return s and s ~= ''
end
function p.main(frame)
local args = { }
local pargs = frame:getParent().args
-- process bodystyle and titlestyle
if (pargs['style'] or '') == 'wide' then
args['titlestyle'] = Styles['nav_box_wide_header']
args['bodystyle'] = Styles['nav_box_wide']
else
args['titlestyle'] = Styles['nav_box_header']
if (pargs['border'] or '') == 'child' then
args['bodystyle'] = Styles['nav_box_child']
else
args['bodystyle'] = Styles['nav_box']
end
end
pargs['titlestyle'] = ''
pargs['bodystyle'] = ''
-- process groupstyle, abovestyle, belowstyle
args['groupstyle'] = Styles['nav_box_label'] .. (pargs['groupstyle'] or '')
args['abovestyle'] = Styles['nav_box_label'] .. (pargs['abovestyle'] or '')
args['belowstyle'] = Styles['nav_box_label'] .. (pargs['belowstyle'] or '')
-- process oddstyle, evenstyle
args['oddstyle'] = isnotblank(pargs['odd_color'])
and ('background:' .. pargs['odd_color']) or nil
args['evenstyle'] = isnotblank(pargs['even_color'])
and ('background:' .. pargs['even_color']) or nil
pargs['oddstyle'] = ''
pargs['evenstyle'] = ''
-- process name and rawname
args['name'] = (isnotblank(pargs['name']) and pargs['name']) or pargs['rawname']
if isblank(args['name']) then args['navbar'] = 'plain' end
pargs['name'] = ''
pargs['rawname'] = ''
-- copy the remaining args
for k, v in pairs(pargs) do
if v and v ~= '' then
args[k] = v
end
end
-- add allow wrap
if args['title'] and (pargs['style'] or '') ~= 'wide' then
if not mw.ustring.match(args['title'], '<span class="wrap">') then
local p = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]'
local p = p .. p .. p
args['title'] = mw.ustring.gsub(args['title'],
'%[%[(' .. p .. '[^%[%]<>|]*)%]%]',
'[[%1|<span class="wrap">%1</span>]]')
args['title'] = mw.ustring.gsub(args['title'],
'%[%[([^%[%]<>|]*)|(' .. p .. '[^%[%]<>|]*)%]%]',
'[[%1|<span class="wrap">%2</span>]]')
end
end
return Navbox._navbox(args)
end
return p