Module:Sandbox/Md gilbert/ListItem

.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/ListItem
require('strict')

local p = {}

--[[
This module is intended to be invoked by the ListMaster module. Depending on the style
passed to the parent, will parse and display the list item as a table row, subsection, etc.

Possible values that could be used for a members table:
  name, role, member_since, role, status, etc
Possible values that could be used for a tasks table:
  title, notes, page, owner, created, due, completed, priority, remaining, etc
  
Values can be passed in that aren't displayed, allowing for more robust storage
of metadata for each item (ie, any arbitrary value can be passed in that aren't
intended to be displayed, but instead facilitate machine-trackable data).
--]]
function p.printItem(frame)
	local parent_frame = frame:getParent()
	local style = parent_frame.args.style
	local display = parent_frame.args.display

	local res = ""
	if style == "table" then
		res = "|- \n"
		for col in string.gmatch(display, "[^,]+") do
			-- Validate the current field, make sure we have the desired value,
			-- setting to an empty string if the arg doesn't exist.
			if frame.args[col] == nil then
				frame.args[col] = ""
			end
			-- Then display, passing to our local functions if the argument
			-- is one for which we have a specialized display function
			if p["display_" .. col] ~= nil then
				res = res .. "| " .. p["display_" .. col]( frame.args[col] ) .. "\n"
			else
				res = res .. "| " .. frame.args[col] .. "\n"
			end
		end
	elseif style == "section" then
		local title = "ListItem"
		if frame.args.name ~= nil then
			title = frame.args.name
		elseif frame.args.title ~= nil then
			title = frame.args.title
		end
		res = "==" .. title .. "==\n"
		-- Then go through each of the display sections and add to res
		for col in string.gmatch(display, "[^,]+") do
			-- Validate the current field, make sure we have the desired value,
			-- setting to an empty string if the arg doesn't exist.
			if frame.args[col] == nil then
				frame.args[col] = ""
			end
			-- Then display each value, passing to our local functions if they exist.
			if p["display_" .. col] ~= nil then
				res = res .. "'''" .. p.firstToUpper(col) .. "''': " .. p["display_" .. col]( frame.args[col] )
			else
				res = res .. "'''" .. p.firstToUpper(col) .. "''': " .. frame.args[col]
			end
		end
	end

	return res
end

function p.display_name(name)
	return "[[User:" .. name .. "|" .. name .. "]] • [[User_talk:" .. name .. "|Talk]] • [[Special:Contributions/" .. name .. "|Contribs]]"
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.