Modul:Vorlage:Auflistung: Unterschied zwischen den Versionen

2020-10-22
(2020-10-02)
 
(2020-10-22)
Zeile 1: Zeile 1:
local HorizontalList = { suite  = "HorizontalList",
local HorizontalList = { suite  = "HorizontalList",
                         serial = "2020-10-02",
                         serial = "2020-10-22",
                         item  = 0 }
                         item  = 0 }
-- Horizontal list of items by HTML/CSS list
-- Horizontal list of items by HTML/CSS list
Zeile 6: Zeile 6:




HorizontalList.classes = { }
local CSS = { classesBlock = { },
HorizontalList.styles  = "Template:Subpage/styles.css"
              classesSep  = { } }
table.insert( HorizontalList.classes, "breadcrumb-nav-container" )
table.insert( HorizontalList.classes, "breadcrumb-nav-middot" )






HorizontalList.f = function ( all, altogether, frame )
HorizontalList.f = function ( all, altogether, apart, frame )
     -- Generate horizontal list from wikitext
     -- Generate horizontal list from wikitext
     -- Parameter:
     -- Parameter:
Zeile 19: Zeile 17:
     --                    each line starting with one of * or #
     --                    each line starting with one of * or #
     --    altogether  -- true, if nowrap around each regular item
     --    altogether  -- true, if nowrap around each regular item
    --    apart        -- string, with separator, if desired
     --    frame        -- object, if available
     --    frame        -- object, if available
     -- Returns string
     -- Returns string
Zeile 42: Zeile 41:
             end -- for i
             end -- for i
             if got then
             if got then
                 r = HorizontalList.fiat( got, list, altogether, frame )
                 r = HorizontalList.fiat( got,
                                        list,
                                        altogether,
                                        apart,
                                        frame )
             else
             else
                 r = ""
                 r = ""
Zeile 59: Zeile 62:




HorizontalList.fiat = function ( all, advance, altogether, frame )
HorizontalList.fiat = function ( all, advance, altogether, apart, frame )
     -- Generate horizontal list from wikitext
     -- Generate horizontal list from item sequence
     -- Parameter:
     -- Parameter:
     --    all          -- table, with sequence of items
     --    all          -- table, with sequence of items
Zeile 66: Zeile 69:
     --    advance      -- true, if ordered list requested
     --    advance      -- true, if ordered list requested
     --    altogether  -- true, if nowrap around each item
     --    altogether  -- true, if nowrap around each item
    --    apart        -- string, with separator, if desired
     --    frame        -- object, if available
     --    frame        -- object, if available
     -- Returns string
     -- Returns string
Zeile 72: Zeile 76:
         local e
         local e
         if #all > 1 then
         if #all > 1 then
             local ou, s
             local es, ou, s
             if advance then
             if advance then
                 s = "ol"
                 s = "ol"
Zeile 79: Zeile 83:
             end
             end
             ou = mw.html.create( s )
             ou = mw.html.create( s )
             if type( HorizontalList.classes ) == "table" then
            for k, v in pairs( CSS.classesBlock ) do
                 for i = 1, #HorizontalList.classes do
                ou:addClass( v )
                     ou:addClass( HorizontalList.classes[ i ] )
            end -- for k, v
                 end -- for i
             if type( apart ) == "string" then
                es = mw.html.create( "span" )
                            :wikitext( apart )
                 for k, v in pairs( CSS.classesSep ) do
                     es:addClass( v )
                 end -- for k, v
             end
             end
             for i = 1, #all do
             for i = 1, #all do
Zeile 91: Zeile 100:
                 else
                 else
                     e:wikitext( tostring( s ) )
                     e:wikitext( tostring( s ) )
                end
                if es  and  i < #all then
                    e:node( es )
                 end
                 end
                 if altogether then
                 if altogether then
Zeile 101: Zeile 113:
                 frame = mw.getCurrentFrame()
                 frame = mw.getCurrentFrame()
             end
             end
             r = frame:extensionTag( "templatestyles",
             if CSS.styles then
                                    nil,
                r = frame:extensionTag( "templatestyles",
                                    { src = HorizontalList.styles } )
                                        nil,
                                        { src = CSS.styles } )
            else
                r = ""
            end
             r = r .. tostring( ou )
             r = r .. tostring( ou )
         else
         else
Zeile 121: Zeile 137:
     return r or ""
     return r or ""
end -- HorizontalList.fiat()
end -- HorizontalList.fiat()
HorizontalList.first = function ( arglist )
    -- Configure CSS environment
    -- Parameter:
    --    arglist  -- table, with optional components
    --                styles        -- templatestyles page
    --                                  -- string, with name
    --                                  -- table, with title object
    --                classesBlock  -- class(es) for block element
    --                                  -- string, with class(es)
    --                                  -- table, with particular mapping
    --                classesSep    -- class(es) for separator element
    --                                  -- string, with class(es)
    --                                  -- table, with particular mapping
    if type( arglist ) == "table" then
        local s, val
        for k, v in pairs( CSS ) do
            if type( v ) == "table" then
                val = arglist[ k ]
                s  = type( val )
                if s == "string" then
                    s = mw.text.trim( val )
                    if s ~= "" then
                        table.insert( v, s )
                    end
                elseif s == "table" then
                    for kk, vv in pairs( val ) do
                        if type( vv ) == "string" then
                            s = mw.text.trim( vv )
                            if s == "" then
                                s = nil
                            end
                        else
                            s = nil
                        end
                        v[ kk ] = s
                    end -- for kk, vvv
                end
            end
        end -- for k, v
        val = arglist.styles
        s  = type( val )
        if s == "string" then
            s = mw.text.trim( val )
        elseif s == "table"  and
              type( val.prefixedText ) == "string"  and
              type( val.exists ) == "boolean"  and
              val.exists then
            s = val.prefixedText
        else
            s = false
        end
        if s  and  s:match( ".+:.+%.css$") then
            CSS.styles = s
        end
    end
end -- HorizontalList.first()




Zeile 129: Zeile 204:
p.f = function ( frame )
p.f = function ( frame )
     -- Template call
     -- Template call
    HorizontalList.first( { styles      = frame.args.styles,
                            classesBlock = frame.args.classesBlock,
                            classesSep  = frame.args.classesSep } )
     return HorizontalList.f( frame.args[ 1 ],
     return HorizontalList.f( frame.args[ 1 ],
                             frame.args.nowrap == "1",
                             frame.args.nowrap == "1",
                            frame.args.sep,
                             frame )
                             frame )
end -- p.f
end -- p.f
Zeile 140: Zeile 219:


p.Auflistung = function ()
p.Auflistung = function ()
     -- Module interface
     -- Module interface @dewiki
     return HorizontalList
     return HorizontalList
end
end


return p
return p
Anonymer Benutzer