Module:Listbox: Difference between revisions

Want an adless experience? Log in or Create an account.
m
change label class to zdw-label to distinguish from bootstrap
(match expanded {{Main}} in the case that it's in a transcluded page)
m (change label class to zdw-label to distinguish from bootstrap)
 
(14 intermediate revisions by the same user not shown)
Line 6: Line 6:
     :tag( 'ul' )
     :tag( 'ul' )
   for _, section in ipairs( sections ) do
   for _, section in ipairs( sections ) do
    local mainTemplate = section.summary:match( '%{%{Main|(.-)}}' )
     -- !!!! This may break if Template:Main is modified !!!!
     -- !!!! This may break if Template:Main is modified !!!!
     local expandedMainTemplate = section.summary:match( 'Main article: %[%[(.-)]]' )
     local expandedMainTemplate = section.summary:match( 'Main article: %[%[(.-)]]' )
     local link = mainTemplate and mw.text.split( mainTemplate, '|' )[1] or expandedMainTemplate and mw.text.split( expandedMainTemplate, '|' )[1]
     local link = expandedMainTemplate and mw.text.split( expandedMainTemplate, '|' )[1]
     list:tag( 'li' )
     list:tag( 'li' )
       :wikitext( '[[' .. (link or section.name) .. '|' .. section.name .. ']]' )
       :wikitext( '[[' .. (link or section.name) .. '|' .. section.name .. ']]' )
Line 27: Line 26:
-- override
-- override
function Listbox:renderContent()
function Listbox:renderContent()
   local listing = Listing._parseListing( self.categories[1] == 'The Legend of Zelda' and self.subject .. '/Staging' or self.subject )
   local listing = Listing._parseListing( self.subject )
 
  -- If categories weren't set already (because caller used single arg), then use the ones parsed from the page.
  -- CODE SMELL: setting unrelated state. this only works because renderFooter is called after renderContent.
  if #self.categories == 0 then self.categories = listing.categories end


   local content = mw.html.create( 'table' )
   local content = mw.html.create( 'table' )
Line 42: Line 45:
       local row = content:tag( 'tr' )
       local row = content:tag( 'tr' )
       row:tag( 'th' )
       row:tag( 'th' )
         :addClass( 'label' )
         :addClass( 'zdw-label' )
         :wikitext( group.name )
         :wikitext( group.name )
       local cell = row:tag( 'td' )
       local cell = row:tag( 'td' )
Line 66: Line 69:
   getParent = function() return {
   getParent = function() return {
     args = {
     args = {
       [1] = "The Legend of Zelda",
       [1] = "The Legend of Zelda Locations"
      [2] = "Locations"
     }
     }
   } end
   } end