Editing Module:Navbar

From MINR.ORG WIKI

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
local getArgs
+
local HtmlBuilder = require('Module:HtmlBuilder')
  
function p._navbar(args)
+
function trim(s)
local titleArg = 1
+
    return (mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1"))
 
+
end
if args.collapsible then
 
titleArg = 2
 
if not args.plain then
 
args.mini = 1
 
end
 
if args.fontcolor then
 
args.fontstyle = 'color:' .. args.fontcolor .. ';'
 
end
 
args.style = 'float:left; text-align:left'
 
end
 
 
 
local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
 
local title = mw.title.new(mw.text.trim(titleText), 'Template');
 
 
 
if not title then
 
error('Invalid title ' .. titleText)
 
end
 
 
 
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
 
 
 
local div = mw.html.create():tag('div')
 
div
 
:addClass('plainlinks')
 
:addClass('hlist')
 
:addClass('navbar')
 
:cssText(args.style)
 
 
 
if args.mini then div:addClass('mini') end
 
  
if not (args.mini or args.plain) then
+
function _navbar( args )
div
+
    if not args[1] then
:tag('span')
+
        local span = HtmlBuilder.create('span')
:css('word-spacing', 0)
+
:cssText(args.fontstyle)
+
        span
:wikitext(args.text or 'This box:')
+
            .addClass('error')
:wikitext(' ')
+
            .css('float', 'left')
end
+
            .css('white-space', 'nowrap')
 
+
            .wikitext('Error: No name provided')
if args.brackets then
+
div
+
        return span
:tag('span')
+
    end
:css('margin-right', '-0.125em')
+
:cssText(args.fontstyle)
+
    local title;
:wikitext('[ ')
+
    local pageName = trim(args[1])
end
+
    if mw.ustring.sub(pageName, 1, 1) == ':' then
 
+
        title = mw.title.new( mw.ustring.sub(pageName, 2) );
local ul = div:tag('ul');
+
    else
 
+
        title = mw.title.new( pageName, 'Template' );
ul
+
    end     
:tag('li')
+
:addClass('nv-view')
+
    local mainpage = title.fullText;
:wikitext('[[' .. title.fullText .. '|')
+
    local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''
:tag(args.mini and 'abbr' or 'span')
+
    local editurl = title:fullUrl( 'action=edit' );
:attr('title', 'View this template')
+
:cssText(args.fontstyle)
+
    local viewLink, talkLink, editLink = 'view', 'talk', 'edit'
:wikitext(args.mini and 'v' or 'view')
+
    if args.mini then
:done()
+
        viewLink, talkLink, editLink = 'v', 't', 'e'
:wikitext(']]')
+
    end
:done()
+
:tag('li')
+
    local div = HtmlBuilder.create( 'div' )
:addClass('nv-talk')
+
    div
:wikitext('[[' .. talkpage .. '|')
+
        .addClass( 'noprint' )
:tag(args.mini and 'abbr' or 'span')
+
        .addClass( 'plainlinks' )
:attr('title', 'Discuss this template')
+
        .addClass( 'hlist' )
:cssText(args.fontstyle)
+
        .addClass( 'navbar')
:wikitext(args.mini and 't' or 'talk')
+
        .cssText( args.style )
:done()
+
:wikitext(']]');
+
    if args.mini then div.addClass('mini') end
 
+
if not args.noedit then
+
    if not (args.mini or args.plain) then
ul
+
        div
:tag('li')
+
            .tag( 'span' )
:addClass('nv-edit')
+
                .css( 'word-spacing', 0 )
:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
+
                .cssText( args.fontstyle )
:tag(args.mini and 'abbr' or 'span')
+
                .wikitext( args.text or 'This box:' )
:attr('title', 'Edit this template')
+
                .wikitext( ' ' )
:cssText(args.fontstyle)
+
    end
:wikitext(args.mini and 'e' or 'edit')
+
:done()
+
    if args.brackets then
:wikitext(']');
+
        div
end
+
            .tag('span')
 
+
                .css('margin-right', '-0.125em')
if args.brackets then
+
                .cssText( args.fontstyle )
div
+
                .wikitext( '[' )
:tag('span')
+
                .newline();
:css('margin-left', '-0.125em')
+
    end
:cssText(args.fontstyle)
+
:wikitext(' ]')
+
    local ul = div.tag('ul');
end
+
 
+
    ul
if args.collapsible then
+
        .tag( 'li' )
div
+
            .addClass( 'nv-view' )
:done()
+
            .wikitext( '[[' .. mainpage .. '|' )
:tag('div')
+
            .tag( 'span ' )
:css('font-size', '114%')
+
                .attr( 'title', 'View this template' )
:css('margin', args.mini and '0 4em' or '0 7em')
+
                .cssText( args.fontstyle or '' )
:cssText(args.fontstyle)
+
                .wikitext( viewLink )
:wikitext(args[1])
+
                .done()
end
+
            .wikitext( ']]' )
 
+
            .done()
return tostring(div:done())
+
        .tag( 'li' )
 +
            .addClass( 'nv-talk' )
 +
            .wikitext( '[[' .. talkpage .. '|' )
 +
            .tag( 'span ' )
 +
                .attr( 'title', 'Discuss this template' )
 +
                .cssText( args.fontstyle or '' )
 +
                .wikitext( talkLink )
 +
                .done()
 +
            .wikitext( ']]' );
 +
 +
    if not args.noedit then  
 +
        ul
 +
            .tag( 'li' )
 +
                .addClass( 'nv-edit' )
 +
                .wikitext( '[' .. editurl .. ' ' )
 +
                .tag( 'span ' )
 +
                    .attr( 'title', 'Edit this template' )
 +
                    .cssText( args.fontstyle or '' )
 +
                    .wikitext( editLink )
 +
                    .done()
 +
                .wikitext( ']' );
 +
    end
 +
 +
    if args.brackets then
 +
        div
 +
            .tag('span')
 +
                .css('margin-left', '-0.125em')
 +
                .cssText( args.fontstyle or '' )
 +
                .wikitext( ']' )
 +
                .newline();
 +
    end
 +
 +
    return tostring(div)
 
end
 
end
  
 
function p.navbar(frame)
 
function p.navbar(frame)
if not getArgs then
+
    local origArgs
getArgs = require('Module:Arguments').getArgs
+
    -- If called via #invoke, use the args passed into the invoking template.
end
+
    -- Otherwise, for testing purposes, assume args are being passed directly in.
return p._navbar(getArgs(frame))
+
    if frame == mw.getCurrentFrame() then
 +
        origArgs = frame:getParent().args
 +
    else
 +
        origArgs = frame
 +
    end
 +
 +
    -- ParserFunctions considers the empty string to be false, so to preserve the previous
 +
    -- behavior of {{navbar}}, change any empty arguments to nil, so Lua will consider
 +
    -- them false too.
 +
    args = {}
 +
    for k, v in pairs(origArgs) do
 +
        if v ~= '' then
 +
            args[k] = v
 +
        end
 +
    end
 +
 +
    return _navbar(args)
 
end
 
end
 
+
 
return p
 
return p

Please note that all contributions to MINR.ORG WIKI may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see MINR.ORG WIKI:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)