Editing Module:Quote
Appearance
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 7: | Line 7: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- Helpers | ||
-- ========================================================= | -- ========================================================= | ||
| Line 22: | Line 22: | ||
return nil | return nil | ||
end | |||
local function paragraph(text) | |||
return '\n' .. text .. '\n' | |||
end | end | ||
| Line 29: | Line 34: | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function parseOptions(args) | ||
local options = { | local options = { | ||
classes = {}, | classes = {}, | ||
| Line 47: | Line 51: | ||
options.extraStyles = extraStyles | options.extraStyles = extraStyles | ||
end | end | ||
local align = parameter(args, 'align') | local align = parameter(args, 'align') | ||
| Line 57: | Line 58: | ||
if align == 'left' or align == 'right' then | if align == 'left' or align == 'right' then | ||
options.classes[#options.classes + 1] = | options.align = align | ||
options.classes[#options.classes + 1] = 'pp-quote--' .. align | |||
local width = | local width = parameter(args, 'width', 'quotewidth') | ||
if width then | if width then | ||
options.styles | options.styles['width'] = width | ||
end | end | ||
end | end | ||
| Line 74: | Line 74: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- Quote builder | ||
-- ========================================================= | -- ========================================================= | ||
local function build(quoteContents, quoteSource, options) | local function build(quoteContents, quoteSource, options) | ||
local quote = mw.html.create(' | local quote = mw.html.create('div') | ||
:addClass('pp-quote') | :addClass('pp-quote') | ||
-- Alignment | -- Alignment | ||
for _, className in ipairs(options.classes) do | for _, className in ipairs(options.classes) do | ||
quote:addClass(className) | quote:addClass(className) | ||
end | end | ||
-- | -- User-supplied classes | ||
if options.extraClasses then | if options.extraClasses then | ||
quote:addClass(options.extraClasses) | quote:addClass(options.extraClasses) | ||
end | end | ||
-- | -- User-supplied styles | ||
for property, value in pairs(options.styles) do | for property, value in pairs(options.styles) do | ||
quote:css(property, value) | quote:css(property, value) | ||
| Line 101: | Line 101: | ||
end | end | ||
-- Quote | -- Quote text | ||
quote:node(quoteContents) | quote:node(quoteContents) | ||
| Line 124: | Line 124: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = | local options = parseOptions(args) | ||
local quoteText = | local quoteText = | ||
| Line 133: | Line 133: | ||
local person = | local person = | ||
args[2] | args[2] | ||
or parameter( | or parameter(args, 'person', 'speaker', 'personquoted') | ||
local source = | local source = | ||
args[3] | args[3] | ||
or parameter( | or parameter(args, 'source', 'quote_source') | ||
-- Quote text | -- Quote text container | ||
local quoteContents = mw.html.create('div') | local quoteContents = mw.html.create('div') | ||
:addClass('pp-quote__text') | :addClass('pp-quote__text') | ||
:wikitext(quoteText) | :wikitext(quoteText) | ||
-- Build source | |||
-- | |||
local quoteSource | local quoteSource | ||
| Line 165: | Line 154: | ||
quoteSource = source | quoteSource = source | ||
end | end | ||
return build( | return build( | ||
| Line 182: | Line 170: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = | local options = parseOptions(args) | ||
local quoteContents = mw.html.create('div') | local quoteContents = mw.html.create('div') | ||
:addClass('pp-quote__text') | :addClass('pp-quote__text') | ||
:addClass('pp-quote__text--dialogue') | :addClass('pp-quote__text--dialogue') | ||
-- Dialogue lines | -- Dialogue lines | ||
| Line 196: | Line 183: | ||
if speaker and line then | if speaker and line then | ||
quoteContents | quoteContents | ||
:tag('div') | :tag('div') | ||
| Line 206: | Line 192: | ||
:done() | :done() | ||
:wikitext(' ' .. line) | :wikitext(' ' .. paragraph(line)) | ||
:done() | :done() | ||
end | end | ||
end | end | ||
-- Dialogue source | -- Dialogue source | ||
local context = | local context = parameter(args, 'context') | ||
local source = parameter(args, 'source') | |||
local source = | |||
local quoteSource | local quoteSource | ||
| Line 229: | Line 211: | ||
quoteSource = source | quoteSource = source | ||
end | end | ||
return build( | return build( | ||