Modul: ChapterTabs: Unterschied zwischen den Versionen

Aus Zweidat
Wechseln zu: Navigation, Suche
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 4: Zeile 4:
-- Main function to generate tabs
-- Main function to generate tabs
function p.generateTabs(frame)
function p.generateTabs(frame)
    -- Get the mw.html builder
     local content = mw.html.create('div')
     local builder = mw.html.create()
        :addClass('tabber-module')
        :wikitext('<tabber>\n')
      
      
     -- Get the SMW query results for books
     -- Get the SMW query results for books
Zeile 13: Zeile 14:
         return "No results found"
         return "No results found"
     end
     end
   
    -- Create the content that needs to be parsed
    local content = '<div class="tabber-module">\n'
    content = content .. '{{TabberNeue\n'  -- Use TabberNeue template/parser function
      
      
     -- Generate tabs for each book
     -- Generate tabs for each book
Zeile 25: Zeile 22:
         local safePageName = string.gsub(pageName, "=", "&#61;")
         local safePageName = string.gsub(pageName, "=", "&#61;")
          
          
         -- Add tab using TabberNeue syntax
         -- Add tab content
         content = content .. '|' .. safePageName .. '=' .. pageName .. '\n'
         content:wikitext(safePageName .. '=' .. pageName .. '\n|-|\n')
     end
     end
      
      
     content = content .. '}}\n</div>'
    -- Add closing tag
     content:wikitext('</tabber>')
      
      
     -- Parse the content to properly render TabberNeue
     -- Return the complete HTML structure
     return frame:preprocess(content)
     return tostring(content)
end
end


return p
return p

Version vom 25. Oktober 2024, 12:56 Uhr

Die Dokumentation für dieses Modul kann unter Modul:ChapterTabs/Doku erstellt werden

-- Module for creating TabberNeue structure from SMW query
local p = {}

-- Main function to generate tabs
function p.generateTabs(frame)
    local content = mw.html.create('div')
        :addClass('tabber-module')
        :wikitext('<tabber>\n')
    
    -- Get the SMW query results for books
    local query = mw.smw.ask('[[Category:Buch]]|?BuchSortierung')
    
    if not query then
        return "No results found"
    end
    
    -- Generate tabs for each book
    for _, result in ipairs(query) do
        -- Get the page name from the first element
        local pageName = result[1]
        -- Escape any equal signs in the page name
        local safePageName = string.gsub(pageName, "=", "&#61;")
        
        -- Add tab content
        content:wikitext(safePageName .. '=' .. pageName .. '\n|-|\n')
    end
    
    -- Add closing tag
    content:wikitext('</tabber>')
    
    -- Return the complete HTML structure
    return tostring(content)
end

return p