Content added Content deleted
NotAracham (talk | contribs) m (1 revision imported) |
NotAracham (talk | contribs) (replacing dialogue module with local version) |
||
Line 1: | Line 1: | ||
--| Creates dialogue definition lists |
|||
-- This Module is used for making templates based in the Lua language. |
|||
--- For whatever reason, refuses to make blockquotes |
|||
-- See more details about Lua in [[w:Help:Lua]]. |
|||
--- <nowiki> |
|||
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden. |
|||
local Dialogue = {} |
|||
-- The next line imports the Dialogue module from the [[w:c:dev:Global Lua Modules]]. |
|||
local Dialogue = require('Dev:Dialogue') |
|||
---- |
|||
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/Dialogue]] |
|||
-- Libraries and Globals |
|||
---- |
|||
-- The last line produces the output for the template |
|||
-- Parses invocation and template parameters, trims whitespace, and removes blanks. |
|||
local getArgs = require('Module:Arguments').getArgs |
|||
---- |
|||
-- Local Functions |
|||
---- |
|||
local function makeInvokeFunc(funcName) |
|||
return function (frame) |
|||
local args = getArgs(frame) |
|||
return Dialogue[funcName](args) |
|||
end |
|||
end |
|||
---- |
|||
-- Public Functions |
|||
---- |
|||
--% Formats dialogue between multiple speakers |
|||
--- Intended to replace {{Dialogue}}. |
|||
--- Syntax compliant with [[wikipedia:Template:Dialogue]] |
|||
--- with portability and citation modifications |
|||
--@ frame (table) Invokes the frame from {{Dialogue}}. See [[Template:Dialogue/doc]]. |
|||
--: (string) HTML <dl /> |
|||
Dialogue.main = makeInvokeFunc('dialogue') |
|||
--% & crafts the Dialogue definition list |
|||
--@ args (table) Arguments passed from Module function call <code>[.main]</code> or other Lua Modules |
|||
function Dialogue.dialogue (args) |
|||
local block = mw.html.create('dl'):addClass('dialogue-wrapper') |
|||
for i,v in ipairs(args) do |
|||
local next_param = i + 1 |
|||
local mood_line = next_param / 2 |
|||
if i == 1 then |
|||
if v == 'action' then |
|||
block:tag('dd') |
|||
:tag('small'):attr('data-dialogue','action') |
|||
:tag('u') |
|||
:wikitext('['..args[next_param]..']') |
|||
:done():done():done() |
|||
else |
|||
local speaker = |
|||
(args[i] and args[args[i]]) |
|||
and args[args[i]] |
|||
or ( |
|||
type(args[i]) == 'string' |
|||
and mw.text.trim(args[i]):len() > 0 |
|||
) |
|||
and args[i] |
|||
or nil |
|||
speaker = speaker and string.format("'''%s'''", speaker) |
|||
local mood = args['mood'..mood_line] or nil |
|||
mood = mood and string.format(" ''(%s)''", mood) |
|||
if speaker or mood then |
|||
block:tag('dt') |
|||
:wikitext( |
|||
('%s%s'):format( speaker or '', mood or '') |
|||
):done() |
|||
end |
|||
if args[next_param] then |
|||
block:tag('dd'):tag('q') |
|||
:wikitext(args[next_param]) |
|||
:done():done() |
|||
else |
|||
block:tag('dd'):wikitext('...'):done() |
|||
end |
|||
end |
|||
elseif math.fmod(i, 2) == 1 then |
|||
if v == 'action' then |
|||
block:tag('dd') |
|||
:tag('small') |
|||
:attr('data-dialogue','action') |
|||
:tag('u') |
|||
:wikitext('['..args[next_param]..']') |
|||
:done():done():done() |
|||
else |
|||
local speaker = |
|||
(args[i] and args[args[i]]) |
|||
and args[args[i]] |
|||
or ( |
|||
type(args[i]) == 'string' |
|||
and mw.text.trim(args[i]):len() > 0 |
|||
) |
|||
and args[i] |
|||
or nil |
|||
speaker = speaker and string.format("'''%s'''", speaker) |
|||
local mood = args['mood'..mood_line] or nil |
|||
mood = mood and string.format(" ''(%s)''", mood) |
|||
if speaker or mood then |
|||
block:tag('dt') |
|||
:wikitext( |
|||
('%s%s'):format( speaker or '', mood or '') |
|||
) |
|||
:done() |
|||
end |
|||
if args[next_param] then |
|||
block:tag('dd'):tag('q') |
|||
:wikitext(args[next_param]) |
|||
:done():done() |
|||
else |
|||
block:tag('dd'):wikitext('...'):done() |
|||
end |
|||
end |
|||
end |
|||
end |
|||
block:done() |
|||
if args['cite'] then |
|||
block:tag('cite'):wikitext(string.format("— %s", args['cite'])):done() |
|||
end |
|||
return tostring(block) |
|||
end |
|||
---- |
|||
-- Output |
|||
---- |
|||
return Dialogue |
return Dialogue |
Latest revision as of 16:35, 21 November 2022
This module is invoked by the {{Dialogue}} template.
--| Creates dialogue definition lists
--- For whatever reason, refuses to make blockquotes
--- <nowiki>
local Dialogue = {}
----
-- Libraries and Globals
----
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Module:Arguments').getArgs
----
-- Local Functions
----
local function makeInvokeFunc(funcName)
return function (frame)
local args = getArgs(frame)
return Dialogue[funcName](args)
end
end
----
-- Public Functions
----
--% Formats dialogue between multiple speakers
--- Intended to replace {{Dialogue}}.
--- Syntax compliant with [[wikipedia:Template:Dialogue]]
--- with portability and citation modifications
--@ frame (table) Invokes the frame from {{Dialogue}}. See [[Template:Dialogue/doc]].
--: (string) HTML <dl />
Dialogue.main = makeInvokeFunc('dialogue')
--% & crafts the Dialogue definition list
--@ args (table) Arguments passed from Module function call <code>[.main]</code> or other Lua Modules
function Dialogue.dialogue (args)
local block = mw.html.create('dl'):addClass('dialogue-wrapper')
for i,v in ipairs(args) do
local next_param = i + 1
local mood_line = next_param / 2
if i == 1 then
if v == 'action' then
block:tag('dd')
:tag('small'):attr('data-dialogue','action')
:tag('u')
:wikitext('['..args[next_param]..']')
:done():done():done()
else
local speaker =
(args[i] and args[args[i]])
and args[args[i]]
or (
type(args[i]) == 'string'
and mw.text.trim(args[i]):len() > 0
)
and args[i]
or nil
speaker = speaker and string.format("'''%s'''", speaker)
local mood = args['mood'..mood_line] or nil
mood = mood and string.format(" ''(%s)''", mood)
if speaker or mood then
block:tag('dt')
:wikitext(
('%s%s'):format( speaker or '', mood or '')
):done()
end
if args[next_param] then
block:tag('dd'):tag('q')
:wikitext(args[next_param])
:done():done()
else
block:tag('dd'):wikitext('...'):done()
end
end
elseif math.fmod(i, 2) == 1 then
if v == 'action' then
block:tag('dd')
:tag('small')
:attr('data-dialogue','action')
:tag('u')
:wikitext('['..args[next_param]..']')
:done():done():done()
else
local speaker =
(args[i] and args[args[i]])
and args[args[i]]
or (
type(args[i]) == 'string'
and mw.text.trim(args[i]):len() > 0
)
and args[i]
or nil
speaker = speaker and string.format("'''%s'''", speaker)
local mood = args['mood'..mood_line] or nil
mood = mood and string.format(" ''(%s)''", mood)
if speaker or mood then
block:tag('dt')
:wikitext(
('%s%s'):format( speaker or '', mood or '')
)
:done()
end
if args[next_param] then
block:tag('dd'):tag('q')
:wikitext(args[next_param])
:done():done()
else
block:tag('dd'):wikitext('...'):done()
end
end
end
end
block:done()
if args['cite'] then
block:tag('cite'):wikitext(string.format("— %s", args['cite'])):done()
end
return tostring(block)
end
----
-- Output
----
return Dialogue