Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Book appearances: Difference between revisions

From Wings of Fire Wiki
No edit summary
Darkstalker refers to the character page, so use Darkstalker (book) instead
 
(16 intermediate revisions by one other user not shown)
Line 4: Line 4:


local abbrs = {
local abbrs = {
["TDP"] = "The Dragonet Prophecy",
["TDP"] = "[[The Dragonet Prophecy]]",
["TLH"] = "The Lost Heir",
["TLH"] = "[[The Lost Heir]]",
["THK"] = "The Hidden Kingdom",
["THK"] = "[[The Hidden Kingdom]]",
["TDS"] = "The Dark Secret",
["TDS"] = "[[The Dark Secret]]",
["TBN"] = "The Brightest Night",
["TBN"] = "[[The Brightest Night]]",
["MR"] = "[[Moon Rising]]",
["WT"] = "[[Winter Turning]]",
["EP"] = "[[Escaping Peril]]",
["TOP"] = "[[Talons of Power]]",
["DOD"] = "[[Darkness of Dragons]]",
["TLC"] = "[[The Lost Continent]]",
["THQ"] = "[[The Hive Queen]]",
["TPJ"] = "[[The Poison Jungle]]",
["TDG"] = "[[The Dangerous Gift]]",
["TFOH"] = "[[The Flames of Hope]]",
["L1"] = "[[Darkstalker (book)|Darkstalker]]",
["L2"] = "[[Dragonslayer]]",
["DS"] = "DS is ambiguous and could refer to Darkstalker (use L1) or Dragonslayer (use L2).",
["W:P"] = "[[Prisoners]]",
["W:A"] = "[[Assassin]]",
["W:D"] = "[[Deserter]]",
["W:R"] = "[[Runaway]]",
["AGTTDW"] = "[[A Guide to the Dragon World]]",
["TOCB"] = "The Official Coloring Book",
["FYDW"] = "[[Forge Your Dragon World]]",
["HTD"] = "How to Draw",
["SGAB"] = "Stained Glass Art Book"
}
}


-- str: String to parse
-- str: String to parse
-- delim: String to use to join the book names (default '\n')
-- delim: String to use to join the book names (default '\n')
function p._appearancesList(str, delim)
function p._appearancesList(str, fmt, delim)
if not str then  
if not str or str == "" then  
return '{{error|Please specify the <code>str</code> or first unnamed param.}}'
return ""
end
end
fmt = fmt or '%s'
delim = delim or '\n'
delim = delim or '\n'
local res = '';
local names = mw.text.split(str, ' ', true)
-- iterate over substrings
-- iterate over substrings
for abbr in mw.text.gsplit(str, ' ', true) do
for i, v in ipairs(names) do
local full = abbrs[abbr]
if str == "" then
if full then
-- do notning
res = res .. full .. delim -- concat to result string
else
else
return '{{error|Unrecognized abbreviation <code>' .. abbr .. '</code>}}'
local full = abbrs[v]
if full then
names[i] = string.format(fmt, full)
else
return '{{error|Unrecognized abbreviation <code>' .. v .. '</code>}}'
end
end
end
end
end
return res
return table.concat(names, delim)
end
end
-- for debugging -- https://stackoverflow.com/a/27028488
function p._dump(o)
  if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
        if type(k) ~= 'number' then k = '"'..k..'"' end
        s = s .. '['..k..'] = ' .. p._dump(v) .. ','
      end
      return s .. '} '
  else
      return tostring(o)
  end
end


-- wrapper for _appearancesList, untested
-- wrapper for _appearancesList, untested
function p.appearancesList(frame)
function p.appearancesList(frame)
local args
local args = frame.args
-- if parent frame's args are not empty
if frame:getParent() ~= nil and next(frame:getParent().args) ~= nil then
args = frame:getParent().args
else
args = frame.args
end
local str = args.str or args[1]
local str = args.str or args[1]
local delim = args.delim or args[2]
local fmt = args.fmt or args[2] or "''%s''"
return p._dump(frame) .. '<br>\n' .. p._dump(frame:getParent()) .. '<br>\n' .. frame:preprocess(p._appearancesList(str, delim))
local delim = args.delim or args[3] or '<br>'
return frame:preprocess(p._appearancesList(str, fmt, delim))
end
end


return p
return p

Latest revision as of 09:15, 9 July 2025

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

-- local string = require("Module:String")

local p = {}

local abbrs = {
	["TDP"] = "[[The Dragonet Prophecy]]",
	["TLH"] = "[[The Lost Heir]]",
	["THK"] = "[[The Hidden Kingdom]]",
	["TDS"] = "[[The Dark Secret]]",
	["TBN"] = "[[The Brightest Night]]",
	["MR"] = "[[Moon Rising]]",
	["WT"] = "[[Winter Turning]]",
	["EP"] = "[[Escaping Peril]]",
	["TOP"] = "[[Talons of Power]]",
	["DOD"] = "[[Darkness of Dragons]]",
	["TLC"] = "[[The Lost Continent]]",
	["THQ"] = "[[The Hive Queen]]",
	["TPJ"] = "[[The Poison Jungle]]",
	["TDG"] = "[[The Dangerous Gift]]",
	["TFOH"] = "[[The Flames of Hope]]",
	["L1"] = "[[Darkstalker (book)|Darkstalker]]",
	["L2"] = "[[Dragonslayer]]",
	["DS"] = "DS is ambiguous and could refer to Darkstalker (use L1) or Dragonslayer (use L2).",
	["W:P"] = "[[Prisoners]]",
	["W:A"] = "[[Assassin]]",
	["W:D"] = "[[Deserter]]",
	["W:R"] = "[[Runaway]]",
	["AGTTDW"] = "[[A Guide to the Dragon World]]",
	["TOCB"] = "The Official Coloring Book",
	["FYDW"] = "[[Forge Your Dragon World]]",
	["HTD"] = "How to Draw",
	["SGAB"] = "Stained Glass Art Book"
}

-- str: String to parse
-- delim: String to use to join the book names (default '\n')
function p._appearancesList(str, fmt, delim)
	if not str or str == "" then 
		return ""
	end
	fmt = fmt or '%s'
	delim = delim or '\n'
	local names = mw.text.split(str, ' ', true)
	-- iterate over substrings
	for i, v in ipairs(names) do
		if str == "" then
			-- do notning
		else
			local full = abbrs[v]
			if full then
				names[i] = string.format(fmt, full)
			else
				return '{{error|Unrecognized abbreviation <code>' .. v .. '</code>}}'
			end
		end
	end
	return table.concat(names, delim)
end

-- wrapper for _appearancesList, untested
function p.appearancesList(frame)
	local args = frame.args
	local str = args.str or args[1]
	local fmt = args.fmt or args[2] or "''%s''"
	local delim = args.delim or args[3] or '<br>'
	return frame:preprocess(p._appearancesList(str, fmt, delim))
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.