Module:Navbox: تفاوت بین نسخه‌ها

از دانشنامه‌ی اسلامی
پرش به ناوبری پرش به جستجو
(خنثی‌سازی ویرایش 51595 توسط Zamani (بحث))
 
سطر ۱: سطر ۱:
<includeonly><span dir="ltr">--
 
-- This module implements {{Navbox}}
 
 
--
 
--
 
+
  -- This module will implement {{Navbox}}
local p = {}
+
  --
 
+
local navbar = require('Module:Navbar')._navbar
+
local p = {}
local getArgs -- lazily initialized
+
 
+
local HtmlBuilder = require('Module:HtmlBuilder')
local args
+
local Navbar = require('Module:Navbar')
local tableRowAdded = false
+
local border
+
local args
local listnums = {}
+
local frame
 
+
local tableRowAdded = false
local function trim(s)
+
local border
return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
+
local listnums = {}
end
+
 
+
function trim(s)
local function addNewline(s)
+
    return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
if s:match('^[*:;#]') or s:match('^{|') then
+
  end
return '\n' .. s ..'\n'
+
else
+
function addTableRow(tbl)
return s
+
    -- If any other rows have already been added, then we add a 2px gutter row.
end
+
    if tableRowAdded then
end
+
        tbl
 
+
            .tag('tr')
local function addTableRow(tbl)
+
                .css('height', '2px')
-- If any other rows have already been added, then we add a 2px gutter row.
+
                .tag('td')
if tableRowAdded then
+
  end
tbl
+
:tag('tr')
+
    tableRowAdded = true
:css('height', '2px')
+
:tag('td')
+
    return tbl.tag('tr')
:attr('colspan',2)
+
end
end
+
 
+
tableRowAdded = true
+
--
 
+
--   Title row
return tbl:tag('tr')
+
--
end
+
function renderTitleRow(tbl)
 
+
    if not args.title then return end
local function renderNavBar(titleCell)
+
-- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
+
    local titleRow = addTableRow(tbl)
-- or right to keep the title centered.
+
local spacerSide = nil
+
    if args.titlegroup then
 
+
        titleRow
if args.navbar == 'off' then
+
            .tag('th')
-- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's
+
                .attr('scope', 'row')
-- also no show/hide link, then we need a spacer on the right to achieve the left shift.
+
                .addClass('navbox-group')
if args.state == 'plain' then spacerSide = 'left' end
+
                .addClass(args.titlegroupclass)
elseif args.navbar == 'plain' or (not args.name and mw.getCurrentFrame():getParent():getTitle() == 'الگو:Navbox' and (border == 'subgroup' or border == 'child' or border == 'none')) then
+
                .cssText(args.basestyle)
-- No navbar. Need a spacer on the left to balance out the width of the show/hide link.
+
                .cssText(args.groupstyle)
if args.state ~= 'plain' then spacerSide = 'right' end
+
                .cssText(args.titlegroupstyle)
else
+
                .wikitext(args.titlegroup)
-- Will render navbar (or error message). If there's no show/hide link, need a spacer on the right
+
    end
-- to balance out the width of the navbar.
+
if args.state == 'plain' then spacerSide = 'left' end
+
    local titleCell = titleRow.tag('th').attr('scope', 'col')
 
+
titleCell:wikitext(navbar{
+
    if args.titlegroup then
args.name,
+
        titleCell
mini = 1,
+
            .css('border-left', '2px solid #fdfdfd')
fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
+
            .css('width', '100%')
})
+
    end
end
+
 
+
    local titleColspan = 2
-- Render the spacer div.
+
    if args.imageleft then titleColspan = titleColspan + 1 end
if spacerSide then
+
    if args.image then titleColspan = titleColspan + 1 end
titleCell
+
    if args.titlegroup then titleColspan = titleColspan - 1 end
:tag('span')
+
:css('float', spacerSide)
+
    titleCell
:css('width', '6em')
+
        .cssText(args.basestyle)
:wikitext('&nbsp;')
+
        .cssText(args.titlestyle)
end
+
        .addClass('navbox-title')
end
+
        .attr('colspan', titleColspan)
--  Title row
+
--
+
      renderNavBar(titleCell)
local function renderTitleRow(tbl)
+
if not args.title then return end
+
      titleCell
 
+
          .tag('div')
local titleRow = addTableRow(tbl)
+
              .addClass(args.titleclass)
 
+
              .css('font-size', '110%')
if args.titlegroup then
+
              .newline()
titleRow
+
              .wikitext(args.title)
:tag('th')
+
end
:attr('scope', 'row')
+
:addClass('navbox-group')
+
function renderNavBar(titleCell)
:addClass(args.titlegroupclass)
+
    -- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
:cssText(args.basestyle)
+
    -- or right to keep the title centered.
:cssText(args.groupstyle)
+
    local spacerSide = nil
:cssText(args.titlegroupstyle)
+
:wikitext(args.titlegroup)
+
    if args.navbar == 'off' then
end
+
        -- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's
 
+
        -- also no show/hide link, then we need a spacer on the right to achieve the left shift.
local titleCell = titleRow:tag('th'):attr('scope', 'col')
+
        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
if args.titlegroup then
+
        -- No navbar. Need a spacer on the left to balance out the width of the show/hide link.
titleCell
+
        if args.state ~= 'plain' then spacerSide = 'left' end
:css('border-right', '2px solid #fdfdfd')
+
    else
:css('width', '100%')
+
        -- Will render navbar (or error message). If there's no show/hide link, need a spacer on the right
end
+
        -- to balance out the width of the navbar.
 
+
        if args.state == 'plain' then spacerSide = 'right' end
local titleColspan = 2
+
if args.imageright then titleColspan = titleColspan + 1 end
+
        titleCell.wikitext(Navbar.navbar({
if args.image then titleColspan = titleColspan + 1 end
+
            args.name,
if args.titlegroup then titleColspan = titleColspan - 1 end
+
            mini = 1,
 
+
            fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') ..  ';background:none transparent;border:none;'
titleCell
+
        }))
:cssText(args.basestyle)
+
    end
:cssText(args.titlestyle)
+
:addClass('navbox-title')
+
    -- Render the spacer div.
:attr('colspan', titleColspan)
+
    --            .css('float', spacerSide)
 
+
    if spacerSide then
renderNavBar(titleCell)
+
        titleCell
 
+
            .tag('span')
titleCell
+
   
:tag('div')
+
                .css('float', 'right')
:addClass(args.titleclass)
+
                .css('width', '6em')
:css('font-size', '110%')
+
                .wikitext('&nbsp;')
:wikitext(addNewline(args.title))
+
    end
end
+
end
--  Above/Below rows
+
--
+
 
+
--
local function getAboveBelowColspan()
+
--  Above/Below rows
local ret = 2
+
--
if args.imageright then ret = ret + 1 end
+
function renderAboveRow(tbl)
if args.image then ret = ret + 1 end
+
    if not args.above then return end
return ret
+
end
+
    addTableRow(tbl)
 
+
        .tag('td')
local function renderAboveRow(tbl)
+
            .addClass('navbox-abovebelow')
if not args.above then return end
+
            .addClass(args.aboveclass)
 
+
            .cssText(args.basestyle)
addTableRow(tbl)
+
            .cssText(args.abovestyle)
:tag('td')
+
            .attr('colspan', getAboveBelowColspan())
:addClass('navbox-abovebelow')
+
            .tag('div')
:addClass(args.aboveclass)
+
                .newline()
:cssText(args.basestyle)
+
                .wikitext(args.above)
:cssText(args.abovestyle)
+
end
:attr('colspan', getAboveBelowColspan())
+
:tag('div')
+
function renderBelowRow(tbl)
:wikitext(addNewline(args.above))
+
    if not args.below then return end
end
+
 
+
    addTableRow(tbl)
local function renderBelowRow(tbl)
+
        .tag('td')
if not args.below then return end
+
            .addClass('navbox-abovebelow')
 
+
            .addClass(args.belowclass)
addTableRow(tbl)
+
            .cssText(args.basestyle)
:tag('td')
+
            .cssText(args.belowstyle)
:addClass('navbox-abovebelow')
+
            .attr('colspan', getAboveBelowColspan())
:addClass(args.belowclass)
+
            .tag('div')
:cssText(args.basestyle)
+
                .newline()
:cssText(args.belowstyle)
+
                .wikitext(args.below)
:attr('colspan', getAboveBelowColspan())
+
end
:tag('div')
+
:wikitext(addNewline(args.below))
+
function getAboveBelowColspan()
end
+
    local ret = 2
--  List rows
+
    if args.imageleft then ret = ret + 1 end
--
+
    if args.image then ret = ret + 1 end
local function renderListRow(tbl, listnum)
+
    return ret
local row = addTableRow(tbl)
+
end
 
+
if listnum == 1 and args.imageright then
+
row
+
--
:tag('td')
+
--  List rows
:addClass('navbox-image')
+
--
:addClass(args.imageclass)
+
function renderListRow(tbl, listnum)
:css('width', '0%')
+
    local row = addTableRow(tbl)
:css('padding', '0px 2px 0px 0px')
+
:cssText(args.imagerightstyle)
+
    if listnum == 1 and args.imageleft then
:attr('rowspan', 2 * #listnums - 1)
+
        row
:tag('div')
+
            .tag('td')
:wikitext(addNewline(args.imageright))
+
                .addClass('navbox-image')
end
+
                .addClass(args.imageclass)
 
+
                .css('width', '0%')
if args['group' .. listnum] then
+
                .css('padding', '0px 2px 0px 0px')
local groupCell = row:tag('th')
+
                .cssText(args.imageleftstyle)
 
+
                .attr('rowspan', 2 * #listnums - 1)
groupCell
+
                .tag('div')
:attr('scope', 'row')
+
                    .newline()
:addClass('navbox-group')
+
                    .wikitext(args.imageleft)
:addClass(args.groupclass)
+
end
:cssText(args.basestyle)
+
 
+
    if args['group' .. listnum] then
if args.groupwidth then
+
        local groupCell = row.tag('th')
groupCell:css('width', args.groupwidth)
+
end
+
        groupCell
 
+
                .attr('scope', 'row')
groupCell
+
                .addClass('navbox-group')
:cssText(args.groupstyle)
+
                .addClass(args.groupclass)
:cssText(args['group' .. listnum .. 'style'])
+
                .cssText(args.basestyle)
:wikitext(args['group' .. listnum])
+
end
+
        if args.groupwidth then
 
+
            groupCell.css('width', args.groupwidth)
local listCell = row:tag('td')
+
        end
 
+
if args['group' .. listnum] then
+
        groupCell
listCell
+
            .cssText(args.groupstyle)
:css('text-align', 'right')
+
            .cssText(args['group' .. listnum .. 'style'])
:css('border-right-width', '2px')
+
            .wikitext(args['group' .. listnum])
:css('border-right-style', 'solid')
+
    end
else
+
listCell:attr('colspan', 2)
+
    local listCell = row.tag('td')
end
+
 
+
    if args['group' .. listnum] then
if not args.groupwidth then  
+
        listCell
listCell:css('width', '100%')
+
            .css('text-align', 'left')
end
+
            .css('border-left-width', '2px')
 
+
            .css('border-left-style', 'solid')
local isOdd = (listnum % 2) == 1
+
    else
local rowstyle = args.evenstyle
+
        listCell.attr('colspan', 2)
if isOdd then rowstyle = args.oddstyle end
+
    end
 
+
local evenOdd
+
    if not args.groupwidth then
if args.evenodd == 'swap' then
+
        listCell.css('width', '100%')
if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
+
    end
else
+
if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
+
    local isOdd = (listnum % 2) == 1
end
+
    local rowstyle = args.evenstyle
 
+
    if isOdd then rowstyle = args.oddstyle end
listCell
+
:css('padding', '0px')
+
    local evenOdd
:cssText(args.liststyle)
+
    if args.evenodd == 'swap' then
:cssText(rowstyle)
+
        if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
:cssText(args['list' .. listnum .. 'style'])
+
    else
:addClass('navbox-list')
+
        if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
:addClass('navbox-' .. evenOdd)
+
    end
:addClass(args.listclass)
+
:tag('div')
+
    listCell
:css('padding', (listnum == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
+
        .css('padding', '0px')
:wikitext(addNewline(args['list' .. listnum]))
+
        .cssText(args.liststyle)
 
+
        .cssText(rowstyle)
if listnum == 1 and args.image then
+
        .cssText(args['list' .. listnum .. 'style'])
row
+
        .addClass('navbox-list')
:tag('td')
+
        .addClass('navbox-' .. evenOdd)
:addClass('navbox-image')
+
        .addClass(args.listclass)
:addClass(args.imageclass)
+
        .tag('div')
:css('width', '0%')
+
            .css('padding', (listnum == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
:css('padding', '0px 0px 0px 2px')
+
            .newline()
:cssText(args.imagestyle)
+
            .wikitext(args['list' .. listnum])
:attr('rowspan', 2 * #listnums - 1)
+
:tag('div')
+
    if listnum == 1 and args.image then
:wikitext(addNewline(args.image))
+
        row
end
+
            .tag('td')
end
+
                .addClass('navbox-image')
--  Tracking categories
+
                .addClass(args.imageclass)
--
+
                .css('width', '0%')
 
+
                .css('padding', '0px 0px 0px 2px')
local function needsHorizontalLists()
+
                .cssText(args.imagestyle)
if border == 'child' or border == 'subgroup'  or args.tracking == 'no' then return false end
+
                .attr('rowspan', 2 * #listnums - 1)
 
+
                .tag('div')
local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist hwrap', 'hlist vcard', 'vcard hlist', 'hlist vevent'}
+
                    .newline()
for _, cls in ipairs(listClasses) do
+
                    .wikitext(args.image)
if args.listclass == cls or args.bodyclass == cls then
+
    end
return false
+
end
end
+
end
+
 
+
--
return true
+
--  Tracking categories
end
+
--
 
+
function renderTrackingCategories(builder)
local function hasBackgroundColors()
+
    local frame = mw.getCurrentFrame()
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
+
    if not frame then return end
 
+
local function getTrackingCategories()
+
    local s = frame:preprocess('{{#ifeq:{{NAMESPACE}}|{{ns:10}}|1|0}}{{SUBPAGENAME}}')
local cats = {}
+
    if mw.ustring.sub(s, 1, 1) == '0' then return end -- not in template space
if needsHorizontalLists() then table.insert(cats, 'ناوباکس‌های بدون فهرست افقی') end
+
    local subpage = mw.ustring.lower(mw.ustring.sub(s, 2))
if hasBackgroundColors() then table.insert(cats, 'جعبه‌های ناوبری با استفاده از رنگ‌های پس‌زمینه') end
+
    if subpage == 'doc' or subpage == 'sandbox' or subpage == 'testcases' then return end
return cats
+
end
+
    for i, cat in ipairs(getTrackingCategories()) do
 
+
        builder.wikitext('')
local function renderTrackingCategories(builder)
+
    end
local title = mw.title.getCurrentTitle()
+
end
if title.namespace ~= 10 then return end -- not in template space
+
local subpage = title.subpageText
+
function getTrackingCategories()
if subpage == 'توضیحات' or subpage == 'تمرین' or subpage == 'آزمایشی' then return end
+
    local cats = {}
 
+
    if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end
for _, cat in ipairs(getTrackingCategories()) do
+
    if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
builder:wikitext('[[رده:' .. cat .. ']]')
+
    return cats
end
+
end
end
+
--  Main navbox tables
+
function needsHorizontalLists()
--
+
    if border == 'child' or border == 'subgroup' or args.tracking == 'no' then return false end
local function renderMainTable()
+
local tbl = mw.html.create('table')
+
    local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist hwrap', 'hlist vcard', 'vcard hlist', 'hlist vevent'}
:addClass('nowraplinks')
+
    for i, cls in ipairs(listClasses) do
:addClass(args.bodyclass)
+
        if args.listclass == cls or args.bodyclass == cls then
 
+
            return false
if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
+
        end
tbl
+
    end
:addClass('collapsible')
+
:addClass(args.state or 'autocollapse')
+
    return true
end
+
end
 
+
tbl:css('border-spacing', 0)
+
function hasBackgroundColors()
if border == 'subgroup' or border == 'child' or border == 'none' then
+
    return args.titlestyle or args.groupstyle
tbl
+
end
:addClass('navbox-subgroup')
+
:cssText(args.bodystyle)
+
:cssText(args.style)
+
--
else -- regular navobx - bodystyle and style will be applied to the wrapper table
+
--  Main navbox tables
tbl
+
--
:addClass('navbox-inner')
+
function renderMainTable()
:css('background', 'transparent')
+
    local tbl = HtmlBuilder.create('table')
:css('color', 'inherit')
+
        .attr('cellspacing', 0)
end
+
        .addClass('nowraplinks')
tbl:cssText(args.innerstyle)
+
        .addClass(args.bodyclass)
 
+
renderTitleRow(tbl)
+
    if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
renderAboveRow(tbl)
+
        tbl
for _, listnum in ipairs(listnums) do
+
            .addClass('collapsible')
renderListRow(tbl, listnum)  
+
            .addClass(args.state or 'autocollapse')
end
+
    end
renderBelowRow(tbl)
+
 
+
    tbl.css('border-spacing', 0)
return tbl
+
    if border == 'subgroup' or border == 'child' or border == 'none' then
end
+
        tbl
 
+
            .addClass('navbox-subgroup')
function p._navbox(navboxArgs)
+
            .cssText(args.bodystyle)
args = navboxArgs
+
            .cssText(args.style)
 
+
    else -- regular navobx - bodystyle and style will be applied to the wrapper table
for k, _ in pairs(args) do
+
        tbl
local listnum = ('' .. k):match('^list(%d+)$')
+
            .addClass('navbox-inner')
if listnum then table.insert(listnums, tonumber(listnum)) end
+
            .css('background', 'transparent')
end
+
            .css('color', 'inherit')
table.sort(listnums)
+
    end
 
+
    tbl.cssText(args.innerstyle)
border = trim(args.border or args[1] or '')
+
 
+
    renderTitleRow(tbl)
-- render the main body of the navbox
+
    renderAboveRow(tbl)
local tbl = renderMainTable()
+
    for i, listnum in ipairs(listnums) do
 
+
        renderListRow(tbl, listnum)
-- render the appropriate wrapper around the navbox, depending on the border param
+
    end
local res = mw.html.create()
+
    renderBelowRow(tbl)
if border == 'none' then
+
res:node(tbl)
+
    return tbl
elseif border == 'subgroup' or border == 'child' then
+
end
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
+
-- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
+
function p._navbox(navboxArgs)
-- padding being applied, and at the end add a <div> to balance out the parent's </div>
+
    args = navboxArgs
res
+
:wikitext('</div>') -- XXX: hack due to lack of unclosed support in mw.html.
+
    for k, v in pairs(args) do
:node(tbl)
+
        local listnum = ('' .. k):match('^list(%d+)$')
:wikitext('<div>') -- XXX: hack due to lack of unclosed support in mw.html.
+
        if listnum then table.insert(listnums, tonumber(listnum)) end
else
+
    end
res
+
    table.sort(listnums)
:tag('table')
+
:addClass('navbox')
+
    border = trim(args.border or args[1] or '')
:css('border-spacing', 0)
+
:cssText(args.bodystyle)
+
    -- render the main body of the navbox
:cssText(args.style)
+
    local tbl = renderMainTable()
:tag('tr')
+
:tag('td')
+
    -- render the appropriate wrapper around the navbox, depending on the border param
:css('padding', '2px')
+
    local res = HtmlBuilder.create()
:node(tbl)
+
    if border == 'none' then
end
+
        res.node(tbl)
 
+
    elseif border == 'subgroup' or border == 'child' then
renderTrackingCategories(res)
+
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is
 
+
        -- therefore inside a div with padding:0em 0.25em. We start with a </div> to avoid the
return tostring(res)
+
      res            .tag('/div', {unclosed = true})
end
+
                .done()
 
+
            .node(tbl)
function p.navbox(frame)
+
            .tag('div', {unclosed = true})
if not getArgs then
+
    else
getArgs = require('Module:Arguments').getArgs
+
        res
end
+
            .tag('table')
args = getArgs(frame, {wrappers = 'الگو:Navbox'})
+
                .attr('cellspacing', 0)
 
+
                .addClass('navbox')
-- Read the arguments in the order they'll be output in, to make references number in the right order.
+
                .css('border-spacing', 0)
local _
+
                .cssText(args.bodystyle)
_ = args.title
+
                .cssText(args.style)
_ = args.above
+
                .tag('tr')
for i = 1, 20 do
+
                    .tag('td')
_ = args["group" .. tostring(i)]
+
                        .css('padding', '2px')
_ = args["list" .. tostring(i)]
+
                        .node(tbl)
end  
+
    end
_ = args.below
+
 
+
    renderTrackingCategories(res)
return p._navbox(args)
+
end
+
    return tostring(res)
 
+
end
return p
+
</span></includeonly>
+
function p.navbox(frame)
 +
    -- ParserFunctions considers the empty string to be false, so to preserve the previous
 +
    -- behavior of {{navbox}}, change any empty arguments to nil, so Lua will consider
 +
    -- them false too.
 +
    local args = {}
 +
    local parent_args = frame:getParent().args;
 +
 +
    -- Out of order parsing bug.
 +
    local temp;
 +
    temp = parent_args.title;
 +
    temp = parent_args.above;
 +
    for i = 1, 20 do
 +
        temp = parent_args["group" .. tostring(i)];
 +
        temp = parent_args["list" .. tostring(i)];
 +
    end
 +
    temp = parent_args.below;
 +
 +
    for k, v in pairs(parent_args) do
 +
        if v ~= '' then
 +
            args[k] = v
 +
        end
 +
    end
 +
    return p._navbox(args)
 +
end
 +
 +
return p

نسخهٔ کنونی تا ‏۱۲ سپتامبر ۲۰۱۵، ساعت ۱۴:۳۴

--

-- This module will implement

 --

local p = {}

local HtmlBuilder = require('Module:HtmlBuilder')
local Navbar = require('Module:Navbar')

local args
local frame
local tableRowAdded = false
local border
local listnums = {}

function trim(s)
    return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
 end

function addTableRow(tbl)
    -- If any other rows have already been added, then we add a 2px gutter row.
    if tableRowAdded then
        tbl
            .tag('tr')
                .css('height', '2px')
                .tag('td')
 end

    tableRowAdded = true

    return tbl.tag('tr')
end


--
--   Title row
--
function renderTitleRow(tbl)
    if not args.title then return end

    local titleRow = addTableRow(tbl)

    if args.titlegroup then
        titleRow
            .tag('th')
                .attr('scope', 'row')
                .addClass('navbox-group')
                .addClass(args.titlegroupclass)
                .cssText(args.basestyle)
                .cssText(args.groupstyle)
                .cssText(args.titlegroupstyle)
                .wikitext(args.titlegroup)
    end

    local titleCell = titleRow.tag('th').attr('scope', 'col')

    if args.titlegroup then
        titleCell
            .css('border-left', '2px solid #fdfdfd')
            .css('width', '100%')
    end

    local titleColspan = 2
    if args.imageleft then titleColspan = titleColspan + 1 end
    if args.image then titleColspan = titleColspan + 1 end
    if args.titlegroup then titleColspan = titleColspan - 1 end

    titleCell
        .cssText(args.basestyle)
        .cssText(args.titlestyle)
        .addClass('navbox-title')
        .attr('colspan', titleColspan)

     renderNavBar(titleCell)

     titleCell
         .tag('div')
             .addClass(args.titleclass)
             .css('font-size', '110%')
             .newline()
             .wikitext(args.title)
end

function renderNavBar(titleCell)
    -- Depending on the presence of the navbar and/or show/hide link, we may need to add a spacer div on the left
    -- or right to keep the title centered.
    local spacerSide = nil

    if args.navbar == 'off' then
        -- No navbar, and client wants no spacer, i.e. wants the title to be shifted to the left. If there's
        -- 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
    elseif args.navbar == 'plain' or args.navbar == 'off' or (not args.name 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.
        if args.state ~= 'plain' then spacerSide = 'left' end
    else
        -- Will render navbar (or error message). If there's no show/hide link, need a spacer on the right
        -- to balance out the width of the navbar.
        if args.state == 'plain' then spacerSide = 'right' end

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

    -- Render the spacer div.
    --            .css('float', spacerSide)
    if spacerSide then
        titleCell
            .tag('span')
    
                .css('float', 'right')
                .css('width', '6em')
                .wikitext(' ')
    end
end


--
--   Above/Below rows
--
function renderAboveRow(tbl)
    if not args.above then return end

    addTableRow(tbl)
        .tag('td')
            .addClass('navbox-abovebelow')
            .addClass(args.aboveclass)
            .cssText(args.basestyle)
            .cssText(args.abovestyle)
            .attr('colspan', getAboveBelowColspan())
            .tag('div')
                .newline()
                .wikitext(args.above)
end

function renderBelowRow(tbl)
    if not args.below then return end

    addTableRow(tbl)
        .tag('td')
            .addClass('navbox-abovebelow')
            .addClass(args.belowclass)
            .cssText(args.basestyle)
            .cssText(args.belowstyle)
            .attr('colspan', getAboveBelowColspan())
            .tag('div')
                .newline()
                .wikitext(args.below)
end

function getAboveBelowColspan()
    local ret = 2
    if args.imageleft then ret = ret + 1 end
    if args.image then ret = ret + 1 end
    return ret
end


--
--   List rows
--
function renderListRow(tbl, listnum)
    local row = addTableRow(tbl)

    if listnum == 1 and args.imageleft then
        row
            .tag('td')
                .addClass('navbox-image')
                .addClass(args.imageclass)
                .css('width', '0%')
                .css('padding', '0px 2px 0px 0px')
                .cssText(args.imageleftstyle)
                .attr('rowspan', 2 * #listnums - 1)
                .tag('div')
                    .newline()
                    .wikitext(args.imageleft)
end

    if args['group' .. listnum] then
        local groupCell = row.tag('th')

        groupCell
               .attr('scope', 'row')
               .addClass('navbox-group')
               .addClass(args.groupclass)
               .cssText(args.basestyle)

        if args.groupwidth then
            groupCell.css('width', args.groupwidth)
        end

        groupCell
            .cssText(args.groupstyle)
            .cssText(args['group' .. listnum .. 'style'])
            .wikitext(args['group' .. listnum])
    end

    local listCell = row.tag('td')

    if args['group' .. listnum] then
        listCell
            .css('text-align', 'left')
            .css('border-left-width', '2px')
            .css('border-left-style', 'solid')
    else
        listCell.attr('colspan', 2)
    end

    if not args.groupwidth then
        listCell.css('width', '100%')
    end

    local isOdd = (listnum % 2) == 1
    local rowstyle = args.evenstyle
    if isOdd then rowstyle = args.oddstyle end

    local evenOdd
    if args.evenodd == 'swap' then
        if isOdd then evenOdd = 'even' else evenOdd = 'odd' end
    else
        if isOdd then evenOdd = args.evenodd or 'odd' else evenOdd = args.evenodd or 'even' end
    end

    listCell
        .css('padding', '0px')
        .cssText(args.liststyle)
        .cssText(rowstyle)
        .cssText(args['list' .. listnum .. 'style'])
        .addClass('navbox-list')
        .addClass('navbox-' .. evenOdd)
        .addClass(args.listclass)
        .tag('div')
            .css('padding', (listnum == 1 and args.list1padding) or args.listpadding or '0em 0.25em')
            .newline()
            .wikitext(args['list' .. listnum])

    if listnum == 1 and args.image then
        row
            .tag('td')
                .addClass('navbox-image')
                .addClass(args.imageclass)
                .css('width', '0%')
                .css('padding', '0px 0px 0px 2px')
                .cssText(args.imagestyle)
                .attr('rowspan', 2 * #listnums - 1)
                .tag('div')
                    .newline()
                    .wikitext(args.image)
    end
end


--
--   Tracking categories
--
function renderTrackingCategories(builder)
    local frame = mw.getCurrentFrame()

    if not frame then return end

    local s = frame:preprocess('0Module:Navbox')
    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

    for i, cat in ipairs(getTrackingCategories()) do
        builder.wikitext()
    end
end

function getTrackingCategories()
    local cats = {}
    if needsHorizontalLists() then table.insert(cats, 'Navigational boxes without horizontal lists') end
    if hasBackgroundColors() then table.insert(cats, 'Navboxes using background colours') end
    return cats
end

function needsHorizontalLists()
    if border == 'child' or border == 'subgroup'  or args.tracking == 'no' then return false end

    local listClasses = {'plainlist', 'hlist', 'hlist hnum', 'hlist hwrap', 'hlist vcard', 'vcard hlist', 'hlist vevent'}
    for i, cls in ipairs(listClasses) do
        if args.listclass == cls or args.bodyclass == cls then
            return false
        end
    end

    return true
end

function hasBackgroundColors()
    return args.titlestyle or args.groupstyle
end


--
--   Main navbox tables
--
function renderMainTable()
    local tbl = HtmlBuilder.create('table')
        .attr('cellspacing', 0)
        .addClass('nowraplinks')
        .addClass(args.bodyclass)

    if args.title and (args.state ~= 'plain' and args.state ~= 'off') then
        tbl
            .addClass('collapsible')
            .addClass(args.state or 'autocollapse')
    end

    tbl.css('border-spacing', 0)
    if border == 'subgroup' or border == 'child' or border == 'none' then
        tbl
            .addClass('navbox-subgroup')
            .cssText(args.bodystyle)
            .cssText(args.style)
    else -- regular navobx - bodystyle and style will be applied to the wrapper table
        tbl
            .addClass('navbox-inner')
            .css('background', 'transparent')
            .css('color', 'inherit')
    end
    tbl.cssText(args.innerstyle)

    renderTitleRow(tbl)
    renderAboveRow(tbl)
    for i, listnum in ipairs(listnums) do
        renderListRow(tbl, listnum)
    end
    renderBelowRow(tbl)

    return tbl
end

function p._navbox(navboxArgs)
    args = navboxArgs

    for k, v in pairs(args) do
        local listnum = ( .. k):match('^list(%d+)$')
        if listnum then table.insert(listnums, tonumber(listnum)) end
    end
    table.sort(listnums)

    border = trim(args.border or args[1] or )

    -- render the main body of the navbox
    local tbl = renderMainTable()

    -- render the appropriate wrapper around the navbox, depending on the border param
    local res = HtmlBuilder.create()
    if border == 'none' then
        res.node(tbl)
    elseif border == 'subgroup' or border == 'child' then
-- We assume that this navbox is being rendered in a list cell of a parent navbox, and is

-- therefore inside a div with padding:0em 0.25em. We start with a to avoid the

     res             .tag('/div', {unclosed = true})
                .done()
            .node(tbl)
            .tag('div', {unclosed = true})
    else
        res
            .tag('table')
                .attr('cellspacing', 0)
                .addClass('navbox')
                .css('border-spacing', 0)
                .cssText(args.bodystyle)
                .cssText(args.style)
                .tag('tr')
                    .tag('td')
                        .css('padding', '2px')
                        .node(tbl)
    end

    renderTrackingCategories(res)

    return tostring(res)
end

function p.navbox(frame)
    -- ParserFunctions considers the empty string to be false, so to preserve the previous

-- behavior of

, change any empty arguments to nil, so Lua will consider

    -- them false too.
    local args = {}
    local parent_args = frame:getParent().args;

    -- Out of order parsing bug.
    local temp;
    temp = parent_args.title;
    temp = parent_args.above;
    for i = 1, 20 do
        temp = parent_args["group" .. tostring(i)];
        temp = parent_args["list" .. tostring(i)];
    end
    temp = parent_args.below;

    for k, v in pairs(parent_args) do
        if v ~=  then
            args[k] = v
        end
    end
    return p._navbox(args)
end

return p
مسابقه از خطبه ۱۱۴ نهج البلاغه