Difference between revisions of "Module:Asbox stubtree"

From blackwiki
Jump to navigation Jump to search
blackwiki>WOSlinker
(Created page with 'local i = {} function i._subtree(pagename) local out = {"",pagename} local temp1; local t = {} -- split items on dash into table for token ...')
 
blackwiki>WOSlinker
Line 5: Line 5:
 
     local temp1;
 
     local temp1;
 
     local t = {}
 
     local t = {}
 +
   
 
     -- split items on dash into table
 
     -- split items on dash into table
 
     for token in mw.ustring.gmatch(pagename, "[^-]+") do
 
     for token in mw.ustring.gmatch(pagename, "[^-]+") do
Line 13: Line 14:
 
     end
 
     end
 
     table.remove(t, #t)
 
     table.remove(t, #t)
    table.remove(t, 1)
 
  
     while (#t > 0) do
+
     while (#t > 1) do
 +
        table.remove(t, 1)
 
         temp1 = table.concat(t, "-") .. "-stub"
 
         temp1 = table.concat(t, "-") .. "-stub"
 
         table.insert(out,temp1)
 
         table.insert(out,temp1)
        table.remove(t, 1)
 
 
     end
 
     end
  

Revision as of 20:54, 24 February 2013

This module is used by Module:Asbox to create stub hierarchy boxes for stub template documentations. It also implements {{asbox/stubtree}} and served the same function via {{Asbox/templatepage}} prior to being converted to Lua.

Acknowledgements

In addition to the contributors listed in the contribution histories of Template:Asbox stubtree and Module:Asbox stubtree, this module also implements ideas from the (soon to be) deleted Template:Asbox/templatepage, which primary authors are User:MSGJ and User:WOSlinker.



local i = {}
 
function i._subtree(pagename)
    local out = {"",pagename}
    local temp1;
    local t = {}
    
    -- split items on dash into table
    for token in mw.ustring.gmatch(pagename, "[^-]+") do
        -- don't add numbered items to list
        if tonumber(mw.ustring.sub(token,1,1)) == nil then
            table.insert(t,token)
        end
    end
    table.remove(t, #t)

    while (#t > 1) do
        table.remove(t, 1)
        temp1 = table.concat(t, "-") .. "-stub"
        table.insert(out,temp1)
    end

    return table.concat(out, "\n* ")
end

function i.subtree(frame)
    return i._subtree(frame.args["PAGENAME"])
end

return i