Module:Sandbox/N8wilson/FAQ item
Appearance
require('strict')
local getArgs = require('Module:Arguments').getArgs
local mHatnote = require('Module:Hatnote')
local templatestyles = 'TemplateStyles sandbox/N8wilson/SeeFAQstyles.css'
local p = {}
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
function p.ternary(cond, ctrue, cfalse)
if cond then return ctrue end
return cfalse
end
p.pinned = makeInvokeFunc('_pinned')
function p._pinned(args)
-- Generate FAQ for inclusion as the first discussion at the top of the page.
local builder = mw.html.create()
builder:tag('div')
:addClass('faq-item')
:tag('div')
:addClass('faq-link-key')
:wikitext(p.ternary(args['link-key'], '🔗' .. args['link-key'], ''))
:done()
:tag('span')
:addClass('faq-question')
:wikitext('Q' .. (args.index or '') .. '. ' .. (args.q or ''))
:done()
:tag('span')
:addClass('faq-answer')
:wikitext(args.a or '')
return builder
-- Do not include <h2> tag. The L2 header needs to be interpreted as wikitext
-- (i.e. "== header ==") in order to be properly processed by minerva,
-- the mobile skin. If the h2 is included directly, minerva shows it but makes
-- the content underneath it inaccessible on mobile interfaces.
end
p.faqpage = makeInvokeFunc('_faqpage')
function p._faqpage(args)
-- Generate FAQ as it should render on the FAQ content page with anchors to questions
local builder = mw.html.create()
builder:tag('div')
:addClass('faq-item faq-page')
:tag('h3')
:addClass('faq-question')
:addClass('anchor')
:attr('id', ('kFAQ-' .. (args['link-key'] or '')))
:wikitext(args.q or nil)
:done()
:wikitext(mHatnote._hatnote(tostring(args['link-key'] or ''), {extraclasses='link-key'}))
:tag('div')
:addClass('faq-short-answer')
:wikitext(args['short-a'] or '')
:done()
:tag('div')
:addClass('faq-answer')
:wikitext(args.a or '')
:done()
return builder
end
p.default = makeInvokeFunc('_default')
function p._default(args)
-- Generate item as it should render outside of the FAQ page
-- (assume ref to single question in discussion)
local builder = mw.html.create()
builder:tag('span')
:addClass('faq-question')
:wikitext(args.q or '')
builder:tag('span')
:addClass('faq-answer')
:wikitext(args.a or '')
return builder
end
p.beginsection = makeInvokeFunc('_beginsection')
function p._beginsection(args)
return mw.html.create('section', {selfClosing = true})
:attr('begin', (args.key or ''))
end
p.endsection = makeInvokeFunc('_endsection')
function p._endsection(args)
return mw.html.create('section', {selfClosing = true})
:attr('end', (args.key or ''))
end
p.main = makeInvokeFunc('_main')
function p._main(args)
-- make a decision about which format to use based on params
if 'FAQ' == mw.title.getCurrentTitle().subpageText then
return p._faqpage(args)
end
if args.format == 'pinned' then
return p._pinned(args)
end
return p._default(args)
end
return p