Module:Navbar
Appearance
Documentation for this module may be created atModule:Navbar/doc
localp={}
localHtmlBuilder=require('Module:HtmlBuilder')
functiontrim(s)
returnmw.ustring.match(s,"^%s*(.-)%s*$")
end
functionerror(s)
localspan=HtmlBuilder.create('span')
span
.addClass('error')
.css('float','left')
.css('white-space','nowrap')
.wikitext('Error: '..s)
returntostring(span)
end
functiongetTitle(pageName)
pageName=trim(pageName);
localpage_title,talk_page_title;
ifmw.ustring.sub(pageName,1,1)==':'then
page_title=mw.title.new(mw.ustring.sub(pageName,2));
else
page_title=mw.title.new(pageName,'Template');
end
ifpage_titlethen
talk_page_title=page_title.talkPageTitle;
else
talk_page_title=nil;
end
returnpage_title,talk_page_title;
end
function_navbar(args)
ifnotargs[1]then
returnerror('No name provided')
end
localgood,title,talk_title;
good,title,talk_title=pcall(getTitle,args[1]);
ifnotgoodthen
returnerror(title);
end
ifnottitlethen
returnerror('Page does not exist')
end
localmainpage=title.fullText;
localtalkpage=talk_titleandtalk_title.fullTextor''
localediturl=title:fullUrl('action=edit');
localviewLink,talkLink,editLink='view','talk','edit'
ifargs.minithen
viewLink,talkLink,editLink='v','t','e'
end
localdiv=HtmlBuilder.create('div')
div
.addClass('plainlinks')
.addClass('hlist')
.addClass('navbar')
.cssText(args.style)
ifargs.minithendiv.addClass('mini')end
ifnot(args.miniorargs.plain)then
div
.tag('span')
.css('word-spacing',0)
.cssText(args.fontstyle)
.wikitext(args.textor'This box:')
.wikitext(' ')
end
ifargs.bracketsthen
div
.tag('span')
.css('margin-right','-0.125em')
.cssText(args.fontstyle)
.wikitext('[')
.newline();
end
localul=div.tag('ul');
ul
.tag('li')
.addClass('nv-view')
.wikitext('[['..mainpage..'|')
.tag('span ')
.attr('title','View this template')
.cssText(args.fontstyleor'')
.wikitext(viewLink)
.done()
.wikitext(']]')
.done()
.tag('li')
.addClass('nv-talk')
.wikitext('[['..talkpage..'|')
.tag('span ')
.attr('title','Discuss this template')
.cssText(args.fontstyleor'')
.wikitext(talkLink)
.done()
.wikitext(']]');
ifnotargs.noeditthen
ul
.tag('li')
.addClass('nv-edit')
.wikitext('['..editurl..' ')
.tag('span ')
.attr('title','Edit this template')
.cssText(args.fontstyleor'')
.wikitext(editLink)
.done()
.wikitext(']');
end
ifargs.bracketsthen
div
.tag('span')
.css('margin-left','-0.125em')
.cssText(args.fontstyleor'')
.wikitext(']')
.newline();
end
returntostring(div)
end
functionp.navbar(frame)
localorigArgs
-- If called via #invoke, use the args passed into the invoking template.
-- Otherwise, for testing purposes, assume args are being passed directly in.
ifframe==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={}
fork,vinpairs(origArgs)do
ifv~=''then
args[k]=v
end
end
return_navbar(args)
end
returnp