Module:Folger Shakespeare

-- Modules we need
local getArgs = require('Module:Arguments').getArgs
local warn = require('Module:Warning')

-- Configuration
local cfg = mw.loadData('Module:Folger Shakespeare/config');
local _plays = mw.loadData('Module:Folger Shakespeare/plays');

-- Turn plays table inside out so we can look up by alias too
local plays = {}
for _, play in pairs(_plays) do
	for _, key in pairs(play.keys) do
		plays[key] = {
			["title"] = play.title,
			["folgerid"] = play.folgerid,
			["wikilink"] = play.wikilink
		}
	end
end


-- This module's function lookup table, used by the calling context
local p = {}

function p.sfd(args)
	local play  = plays[args[1]]
	local act   = tonumber(args[2])
	local scene = tonumber(args[3])
	local line  = args[4]

	-- Check the play argument
	if play == nil or play == "" then
		warn("No play argument provided, or the play provided was not recognised.")
		return
	end

	-- Check the act argument
	if act == nil or act == "" then
		warn("No act argument provided, or the act given was not numerical.")
		return
	end

	-- Check the scene argument
	if scene == nil or scene == "" then
		warn("No scene argument provided, or the scene given was not numerical.")
		return
	end

	-- Check the line argument
	if line == nil or line == "" then
		warn("No line argument provided.")
		return
	end

	local display_line = line
	if mw.ustring.match(line, '^%s*%d+[-–]%d+%s*$') then
		line = mw.ustring.match(line, '^%s*(%d+)[-–]%d+%s*$')
	elseif mw.ustring.match(line, '^%s*%d+%s*$') then
		line = mw.ustring.match(line, '^%s*(%d+)%s*$')
	else
		warn(("Could not coerce %s into a valid line specification."):format(line))
		return
	end

	local location = mw.ustring.format('line-%d.%d.%d', act, scene, line)
	local url = mw.ustring.format(cfg.url_pattern, play.folgerid, act, scene, location)

	local   id = play.title .. act .. '_' .. scene .. '_' .. display_line
	local name = 'FOOTNOTE' .. id

	local location_link = mw.ustring.format(cfg.location_format, url, act, scene, display_line)
	local cite = mw.ustring.format("''%s'', %s", play.title, location_link)

	local result = mw.getCurrentFrame():extensionTag{
		name = 'ref',
		args = {name = name},
		content = cite,
	}
	return result
end

function p.supported_plays(frame)
	local t = mw.html.create('table')
		:addClass('wikitable')
		:addClass('sortable')
	t:tag('tr')
		:tag('th'):wikitext('Play')
		:tag('th'):wikitext('Aliases')
	for _, play in ipairs(_plays) do
		local playlink = mw.ustring.format("[[%s|%s]]", play.wikilink, play.title)
		local row = t:tag('tr')
		row:tag('td'):wikitext(playlink)
		local aliasList = frame:expandTemplate{
			title = 'hlist',
			args = play.keys
		}
		row:tag('td'):wikitext(aliasList)
	end
	return t
end

function p.main(frame)
	local args = getArgs(frame)
	return p.sfd(args)
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.