Module:Ref: Difference between revisions

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Jump to navigation Jump to search
Content deleted Content added
Created page with "local p = {} function p.main(frame) local parent_args = frame:getParent().args local final_content = "" -- Variables from parent template. -- Ref tag parameters. local name = parent_args["name"] local group = parent_args["group"] -- "lower-alpha" or nil mostly -- MLA citation parameters. local title = parent_args["title"] local url = parent_args["url"] local author = parent_args["author"] local publisher = parent_args["publisher"] local platform =..."
 
mNo edit summary
Line 1: Line 1:
local p = {}
local p = {}

function StringAdd(base, content)
base = base .. content
end

function ContainsOr(base, options)
local found = false
for _, option in ipairs(options) do
if base == option then
found = true
break
end
end
return found
end


function p.main(frame)
function p.main(frame)
Line 19: Line 35:
local archived = parent_args["archived"]
local archived = parent_args["archived"]
local isbn = parent_args["isbn"]
local isbn = parent_args["isbn"]
-- Link platform-specific handles.
local handle_link = ""
if ContainsOr(platform, {"Twitter", "X", "twitter", "x"}) then
handle_link = "[https://twitter.com/@" .. handle .. " @" .. handle .. "]"
elseif ContainsOr(platform, {"YouTube", "youtube", "YT", "yt"}) then
handle_link = "[https://www.youtube.com/@" .. handle .. " @" .. handle .. "]"
end
if parent_args[1] == nil then
if parent_args[1] then
final_content = parent_args[1]

else
else
if author then
final_content = parent_args[1]
StringAdd(final_content, author)
if handle then
StringAdd(final_content, " <nowiki>[</nowiki>" .. handle .. "]")
end
end
end
end
return frame:extensionTag{ name = "ref", content = final_content, args = { name = name, group = group }}
return frame:extensionTag{ name = "ref", content = final_content, args = { name = name, group = group }}
end
end



Revision as of 06:10, 11 March 2024

Documentation for this module may be created at Module:Ref/doc

local p = {}

function StringAdd(base, content)
	base = base .. content
end

function ContainsOr(base, options)
	local found = false
	for _, option in ipairs(options) do
	    if base == option then
	        found = true
	        break
	    end
	end
	return found
end
	

function p.main(frame)
	local parent_args = frame:getParent().args
	local final_content = ""
	
	-- Variables from parent template.
		-- Ref tag parameters.
		local name = parent_args["name"]
		local group = parent_args["group"] -- "lower-alpha" or nil mostly
		-- MLA citation parameters.
		local title = parent_args["title"]
		local url = parent_args["url"]
		local author = parent_args["author"]
		local publisher = parent_args["publisher"]
		local platform = parent_args["platform"]
		local handle = parent_args["handle"]
		local date = parent_args["date"]
		local archived = parent_args["archived"]
		local isbn = parent_args["isbn"]
	
	-- Link platform-specific handles.
	local handle_link = ""
	if ContainsOr(platform, {"Twitter", "X", "twitter", "x"}) then
		handle_link = "[https://twitter.com/@" .. handle .. " @" .. handle .. "]"
	elseif ContainsOr(platform, {"YouTube", "youtube", "YT", "yt"}) then
		handle_link = "[https://www.youtube.com/@" .. handle .. " @" .. handle .. "]"
	end
		
	if parent_args[1] then
		final_content = parent_args[1]
	else
		if author then
			StringAdd(final_content, author)
			if handle then
				StringAdd(final_content, " <nowiki>[</nowiki>" .. handle .. "]")
			end
		end
	end
	
	return frame:extensionTag{ name = "ref", content = final_content, args = { name = name, group = group }}
end

return p