Module:Folger Shakespeare: Difference between revisions
Appearance
Content deleted Content added
Cleanup |
update to support new Folger website (sync from sandbox) |
||
Line 1: | Line 1: | ||
-- 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 |
-- This module's function lookup table, used by the calling context |
||
local p = {} |
local p = {} |
||
function p. |
function p.sfd(args) |
||
local play = plays[args[1]] |
|||
local pframe = frame:getParent() |
|||
local act = tonumber(args[2]) |
|||
local scene = tonumber(args[3]) |
|||
local line = args[4] |
|||
-- Check the play argument |
|||
cfg = mw.loadData('Module:Folger Shakespeare/configuration'); |
|||
if play == nil or play == "" then |
|||
warn("No play argument provided, or the play provided was not recognised.") |
|||
return |
|||
end |
|||
-- Check the act argument |
|||
local play = cfg.aliases[pframe.args[1]] or '' |
|||
if act == nil or act == "" then |
|||
local act = pframe.args[2] or '' |
|||
warn("No act argument provided, or the act given was not numerical.") |
|||
local scene = pframe.args[3] or '' |
|||
return |
|||
end |
|||
-- Check the scene argument |
|||
local line = '' |
|||
if scene == nil or scene == "" then |
|||
local line_given = false |
|||
warn("No scene argument provided, or the scene given was not numerical.") |
|||
local ftln_given = false |
|||
return |
|||
if pframe.args['ftln'] then |
|||
end |
|||
line = pframe.args['ftln'] |
|||
ftln_given = true |
|||
elseif pframe.args[4] then |
|||
line = pframe.args[4] |
|||
line_given = true |
|||
else |
|||
-- Both line_given and ftln_given will be false. |
|||
end |
|||
-- Check the line argument |
|||
local display_line = line |
|||
if line == nil or line == "" then |
|||
if mw.ustring.match(line, '^%s*%d+[-–]%d+%s*$') then |
|||
warn("No line argument provided.") |
|||
line = mw.ustring.match(line, '^%s*(%d+)[-–]%d+%s*$') |
|||
return |
|||
elseif mw.ustring.match(line, '^%s*%d+%s*$') then |
|||
end |
|||
line = mw.ustring.match(line, '^%s*(%d+)%s*$') |
|||
else |
|||
-- Gotta figure out how to signal an error to the user. |
|||
end |
|||
local display_line = line |
|||
local location |
|||
if mw.ustring.match(line, '^%s*%d+[-–]%d+%s*$') then |
|||
if ftln_given then |
|||
line = mw.ustring.match(line, '^%s*(%d+)[-–]%d+%s*$') |
|||
elseif mw.ustring.match(line, '^%s*%d+%s*$') then |
|||
elseif line_given then |
|||
line = mw.ustring.match(line, '^%s*(%d+)%s*$') |
|||
else |
|||
warn(("Could not coerce %s into a valid line specification."):format(line)) |
|||
location = mw.ustring.format('line-%d.%d.%d', act, scene, 0) |
|||
return |
|||
end |
|||
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 play_name = cfg.names[play].title |
|||
local cite = mw.ustring.format("''%s'', %s", play.title, location_link) |
|||
local result = mw.getCurrentFrame():extensionTag{ |
|||
local location_link = '' |
|||
name = 'ref', |
|||
if ftln_given then |
|||
args = {name = name}, |
|||
location_link = mw.ustring.format(cfg.ftln_format, url, display_line) |
|||
content = cite, |
|||
else |
|||
} |
|||
location_link = mw.ustring.format(cfg.location_format, url, act, scene, display_line) |
|||
return result |
|||
end |
|||
end |
|||
local cite = '\'\'' .. play_name .. '\'\', ' .. location_link |
|||
function p.main(frame) |
|||
local result = frame:extensionTag{ |
|||
local args = getArgs(frame) |
|||
name = 'ref', |
|||
return p.sfd(args) |
|||
args = {name = name}, |
|||
content = cite, |
|||
}; |
|||
return result; |
|||
end |
end |
||
Revision as of 11:24, 21 April 2024
![]() | This module depends on the following other modules: |
Implements {{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.main(frame)
local args = getArgs(frame)
return p.sfd(args)
end
return p