Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Md gilbert/ListMaster
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
require('strict') local p = {} --[[ Will first validate, normalize, and then print tabular data according to the style named in the arguments list. Validation will remove any malformed submodule transclusions to ensure one bad entry doesn't break the entire display. Normalization ensures that the desired key-value pairs exist (still working through the details on how this should be implemented. Display is self-explanatory. The goal of this module is to provide a more resilient means of supporting both human- and machine-readable and writable data. Usage to print a members' table, for instance: {{#invoke:Sandbox/Md gilbert/ListMaster|printTable|style=[table|section]|display=[...]| {{#name=name1|role=role1|member_since=date1}} {{#name=name2|role=role2|member_since=date2}} {{#name=name3|role=role3|member_since=date3}} {{#name=name4|role=role4|member_since=date4}} }} --]] function p.printTable(frame) -- Ensure the style is supported, defaults to table if frame.args.style ~= "table" and frame.args.style ~= "section" then frame.args.style = "table" end -- Ensure the display argument exists, return error otherwise if frame.args.display == nil then return "'display' argument is required in ListMaster invocation" end -- Display either table or section, other styles can be added in the future local res = "" if frame.args.style == "table" then -- Print the table header res = res .. "{| class='wikitable' style='border-spacing: 10px; border-collapse: collapse;' \n" res = res .. "|- \n" for col in string.gmatch(frame.args.display, "[^,]+") do res = res .. "! " .. p.firstToUpper(col) .. "\n" end elseif frame.args.style == "section" then end -- Then iterate over all the submodule items for k,v in ipairs(frame.args) do for mod in string.gmatch(v, "{{[^}}]+}}") do -- Add in the invocation text mod = "{{#invoke:Sandbox/Md gilbert/ListItem|printItem|" .. string.sub(mod, 4) -- And process the module res = res .. frame:preprocess( mod ) .. "\n" end end if frame.args.style == "table" then res = res .. "|}\n" elseif frame.args.style == "section" then end --return "<nowiki>" .. res .. "</nowiki>" return res end function p.firstToUpper(str) return (str:gsub("^%l", string.upper)) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Md gilbert/ListMaster/doc
(
edit
)