Module:Navbox: Difference between revisions

m
1 revision
m (1 revision)
 
m (1 revision)
 
(5 intermediate revisions by the same user not shown)
Line 6: Line 6:
   
   
local HtmlBuilder = require('Module:HtmlBuilder')
local HtmlBuilder = require('Module:HtmlBuilder')
local Navbar = require('Module:Navbar')
local navbar = require('Module:Navbar')._navbar
local getArgs -- lazily initialized


local args
local args
local frame
local tableRowAdded = false
local tableRowAdded = false
local border
local border
Line 50: Line 50:
         -- also no show/hide link, then we need a spacer on the right to achieve the left shift.
         -- also no show/hide link, then we need a spacer on the right to achieve the left shift.
         if args.state == 'plain' then spacerSide = 'right' end
         if args.state == 'plain' then spacerSide = 'right' end
     elseif args.navbar == 'plain' or args.navbar == 'off' or (not args.name and (border == 'subgroup' or border == 'child' or border == 'none')) then
     elseif args.navbar == 'plain' or (not args.name and mw.getCurrentFrame():getParent():getTitle() == 'Template:Navbox' and (border == 'subgroup' or border == 'child' or border == 'none')) then
         -- No navbar. Need a spacer on the left to balance out the width of the show/hide link.
         -- No navbar. Need a spacer on the left to balance out the width of the show/hide link.
         if args.state ~= 'plain' then spacerSide = 'left' end
         if args.state ~= 'plain' then spacerSide = 'left' end
Line 58: Line 58:
         if args.state == 'plain' then spacerSide = 'right' end
         if args.state == 'plain' then spacerSide = 'right' end


         titleCell.wikitext(Navbar.navbar({  
         titleCell.wikitext(navbar{  
             args.name,  
             args.name,  
             mini = 1,  
             mini = 1,  
             fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
             fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
         }))
         })
     end
     end
      
      
Line 271: Line 271:


local function hasBackgroundColors()
local function hasBackgroundColors()
     return args.titlestyle or args.groupstyle
     return mw.ustring.match(args.titlestyle or '','background') or mw.ustring.match(args.groupstyle or '','background') or mw.ustring.match(args.basestyle or '','background')
end
end


Line 282: Line 282:


local function renderTrackingCategories(builder)
local function renderTrackingCategories(builder)
     local frame = mw.getCurrentFrame()
     local title = mw.title.getCurrentTitle()
   
     if title.namespace ~= 10 then return end -- not in template space
     if not frame then return end
     local subpage = title.subpageText
   
    local s = frame:preprocess('{{#ifeq:{{NAMESPACE}}|{{ns:10}}|1|0}}{{SUBPAGENAME}}')
    if mw.ustring.sub(s, 1, 1) == '0' then return end -- not in template space
     local subpage = mw.ustring.lower(mw.ustring.sub(s, 2))
     if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
     if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
      
      
Line 382: Line 378:
   
   
function p.navbox(frame)
function p.navbox(frame)
     -- ParserFunctions considers the empty string to be false, so to preserve the previous
     if not getArgs then
    -- behavior of {{navbox}}, change any empty arguments to nil, so Lua will consider
    getArgs = require('Module:Arguments').getArgs
     -- them false too.
     end
     local args = {}
     args = getArgs(frame, {wrappers = 'Template:Navbox'})
    local parent_args = frame:getParent().args;


     -- Out of order parsing bug.
     -- Read the arguments in the order they'll be output in, to make references number in the right order.
     local temp;
     local _
     temp = parent_args.title;
     _ = args.title
     temp = parent_args.above;
     _ = args.above
     for i = 1, 20 do
     for i = 1, 20 do
         temp = parent_args["group" .. tostring(i)];
         _ = args["group" .. tostring(i)]
         temp = parent_args["list" .. tostring(i)];
         _ = args["list" .. tostring(i)]
     end     
     end     
     temp = parent_args.below;
     _ = args.below
   
 
    for k, v in pairs(parent_args) do
        if v ~= '' then
            args[k] = v
        end
    end
     return p._navbox(args)
     return p._navbox(args)
end
end
   
   
return p
return p
14,061

edits