Module:Sandbox/Md gilbert/ListMaster

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Sandbox/Md gilbert/ListMaster
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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.