Difference between revisions of "Module:HonorChallPart"
From Pathfinder Wiki
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil ) | local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil ) | ||
local landingPage = frame:expandTemplate{ title='GetHonorLandingPage' } | local landingPage = frame:expandTemplate{ title='GetHonorLandingPage' } | ||
+ | landingPage = string.gsub(landingPage, "[\n\r]", '') | ||
+ | mw.log('HonorChallPart.getChallengingPart (landingPage): "'..landingPage..'"') | ||
local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' ) | local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' ) | ||
local retString = nil | local retString = nil | ||
Line 12: | Line 14: | ||
if ( #reqVariants['requirements'] > 1 ) then | if ( #reqVariants['requirements'] > 1 ) then | ||
-- create tab's | -- create tab's | ||
+ | local tabString = '' | ||
+ | local tabContentString = '' | ||
for key, variant in pairs(reqVariants['requirements']) do | for key, variant in pairs(reqVariants['requirements']) do | ||
tabText = '' | tabText = '' | ||
Line 26: | Line 30: | ||
end | end | ||
authAbbrev = variant['authorities'][1]['orig'] | authAbbrev = variant['authorities'][1]['orig'] | ||
− | + | tabString = tabString..createNavTab( authAbbrev, tabText, isActive ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local reqPageLink = landingPage..'/Requirements' | local reqPageLink = landingPage..'/Requirements' | ||
Line 39: | Line 37: | ||
end | end | ||
reqPageLink = reqPageLink..'/'..langSuffix | reqPageLink = reqPageLink..'/'..langSuffix | ||
+ | mw.log('HonorChallPart.getChallengingPart (reqPageLink): '..reqPageLink) | ||
+ | local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' ) | ||
+ | tabContentString = tabContentString..createContentTab( authAbbrev, content, isActive ) | ||
+ | end | ||
− | + | local HTMLTabContainer = mw.html.create( 'ul' ) | |
− | + | HTMLTabContainer | |
− | + | :addClass( 'nav nav-tabs' ) | |
− | + | :attr( 'id', 'challengeTab' ) | |
− | + | :attr( 'role', 'tablist' ) | |
− | + | :wikitext( tabString ) | |
− | retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent ) | + | local HTMLTabsContent = mw.html.create( 'div' ) |
− | + | HTMLTabsContent | |
+ | :addClass( 'tab-content' ) | ||
+ | :attr( 'challengeTabContent' ) | ||
+ | :wikitext( tabContentString ) | ||
+ | |||
+ | retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent ) | ||
else | else | ||
-- no or only 1 reqVariant's just use the default | -- no or only 1 reqVariant's just use the default | ||
Line 55: | Line 62: | ||
end | end | ||
end | end | ||
− | return retString | + | return frame:preprocess(retString) |
end | end | ||
function createNavTab( authAbbrev, tabText, isActive) | function createNavTab( authAbbrev, tabText, isActive) | ||
-- create a single tab | -- create a single tab | ||
− | local HTMLLink = mw.html.create( ' | + | local HTMLLink = mw.html.create( 'htmltag' ) |
− | + | ||
+ | local isActiveCSSClass = '' | ||
+ | if ( isActive == true ) then | ||
+ | mw.log('HonorChallPart.createNavTab: Tab is active') | ||
+ | isActiveCSSClass = ' active' | ||
+ | end | ||
+ | |||
HTMLLink | HTMLLink | ||
− | :addClass( 'nav-link' ) | + | :attr( 'tagname', 'a') |
+ | :addClass( 'nav-link'..isActiveCSSClass ) | ||
:attr( 'id', authAbbrev..'-tab' ) | :attr( 'id', authAbbrev..'-tab' ) | ||
:attr( 'data-toggle', 'tab' ) | :attr( 'data-toggle', 'tab' ) | ||
Line 82: | Line 96: | ||
function createContentTab( authAbbrev, content, isActive ) | function createContentTab( authAbbrev, content, isActive ) | ||
+ | mw.log('HonorChallPart.createContentTab (authAbbrev, content, isActive): '..authAbbrev..', '..content..', '..tostring(isActive)) | ||
--create a content tab | --create a content tab | ||
local HTMLContentTab = mw.html.create( 'div' ) | local HTMLContentTab = mw.html.create( 'div' ) | ||
− | + | ||
local isActiveCSSClass = '' | local isActiveCSSClass = '' | ||
if ( isActive == true ) then | if ( isActive == true ) then | ||
+ | mw.log('HonorChallPart.createContentTab: Tab is active') | ||
isActiveCSSClass = ' active show' | isActiveCSSClass = ' active show' | ||
end | end |
Latest revision as of 21:28, 31 July 2021
Documentation for this module may be created at Module:HonorChallPart/doc
local p = {}
local honorUtils = require ( "Module:HonorUtils" )
local utilities = require ( "Module:Utilities" )
function p.getChallengingPart( frame )
local reqVariants = honorUtils.getVariantsData( frame, nil, 'requirements', nil )
local landingPage = frame:expandTemplate{ title='GetHonorLandingPage' }
landingPage = string.gsub(landingPage, "[\n\r]", '')
mw.log('HonorChallPart.getChallengingPart (landingPage): "'..landingPage..'"')
local langSuffix = frame:preprocess( '{{PAGELANGUAGE}}' )
local retString = nil
if ( reqVariants ~= nil and reqVariants['requirements'] ~= nil ) then
if ( #reqVariants['requirements'] > 1 ) then
-- create tab's
local tabString = ''
local tabContentString = ''
for key, variant in pairs(reqVariants['requirements']) do
tabText = ''
for authorityKey, authority in pairs(variant['authorities']) do
if ( #tabText > 0 ) then
tabText = tabText..' & '..authority['translated']
else
tabText = authority['translated']
end
end
local isActive = false
if ( key == 1 ) then
isActive = true
end
authAbbrev = variant['authorities'][1]['orig']
tabString = tabString..createNavTab( authAbbrev, tabText, isActive )
local reqPageLink = landingPage..'/Requirements'
if ( key > 1 ) then
reqPageLink = reqPageLink..' '..key
end
reqPageLink = reqPageLink..'/'..langSuffix
mw.log('HonorChallPart.getChallengingPart (reqPageLink): '..reqPageLink)
local content = frame:callParserFunction( '#lst', reqPageLink, 'challenge' )
tabContentString = tabContentString..createContentTab( authAbbrev, content, isActive )
end
local HTMLTabContainer = mw.html.create( 'ul' )
HTMLTabContainer
:addClass( 'nav nav-tabs' )
:attr( 'id', 'challengeTab' )
:attr( 'role', 'tablist' )
:wikitext( tabString )
local HTMLTabsContent = mw.html.create( 'div' )
HTMLTabsContent
:addClass( 'tab-content' )
:attr( 'challengeTabContent' )
:wikitext( tabContentString )
retString = tostring( HTMLTabContainer )..tostring( HTMLTabsContent )
else
-- no or only 1 reqVariant's just use the default
local reqPageLink = landingPage..'/Requirements/'..langSuffix
retString = frame:callParserFunction( '#lst', reqPageLink, 'challenge' )
end
end
return frame:preprocess(retString)
end
function createNavTab( authAbbrev, tabText, isActive)
-- create a single tab
local HTMLLink = mw.html.create( 'htmltag' )
local isActiveCSSClass = ''
if ( isActive == true ) then
mw.log('HonorChallPart.createNavTab: Tab is active')
isActiveCSSClass = ' active'
end
HTMLLink
:attr( 'tagname', 'a')
:addClass( 'nav-link'..isActiveCSSClass )
:attr( 'id', authAbbrev..'-tab' )
:attr( 'data-toggle', 'tab' )
:attr( 'href', '#'..authAbbrev )
:attr( 'role', 'tab' )
:attr( 'aria-controls', authAbbrev )
:attr( 'aria-selected', tostring(isActive) )
:wikitext( tabText )
local HTMLLi = mw.html.create( 'li' )
HTMLLi
:addClass( 'nav-item' )
:attr( 'role', 'presentation' )
:wikitext( tostring( HTMLLink ) )
return tostring( HTMLLi )
end
function createContentTab( authAbbrev, content, isActive )
mw.log('HonorChallPart.createContentTab (authAbbrev, content, isActive): '..authAbbrev..', '..content..', '..tostring(isActive))
--create a content tab
local HTMLContentTab = mw.html.create( 'div' )
local isActiveCSSClass = ''
if ( isActive == true ) then
mw.log('HonorChallPart.createContentTab: Tab is active')
isActiveCSSClass = ' active show'
end
HTMLContentTab
:addClass( 'tab-pane fade'..isActiveCSSClass )
:attr( 'id', authAbbrev )
:attr( 'role', 'tabpanel' )
:attr( 'aria-labelledby', authAbbrev..'-tab' )
:wikitext( content )
return tostring( HTMLContentTab )
end
return p