Module:Quote: Difference between revisions
ReisuDesign (talk | contribs) No edit summary |
ReisuDesign (talk | contribs) No edit summary |
||
| Line 7: | Line 7: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- Parameters | ||
-- ========================================================= | -- ========================================================= | ||
| Line 22: | Line 22: | ||
return nil | return nil | ||
end | end | ||
| Line 34: | Line 29: | ||
-- ========================================================= | -- ========================================================= | ||
local function | local function getOptions(args) | ||
local options = { | local options = { | ||
classes = {}, | classes = {}, | ||
| Line 51: | Line 47: | ||
options.extraStyles = extraStyles | options.extraStyles = extraStyles | ||
end | end | ||
-- Alignment | |||
local align = parameter(args, 'align') | local align = parameter(args, 'align') | ||
| Line 58: | Line 57: | ||
if align == 'left' or align == 'right' then | if align == 'left' or align == 'right' then | ||
options.classes[#options.classes + 1] = | |||
options.classes[#options.classes + 1] = 'pp-quote--' .. align | 'pp-quote--' .. align | ||
local width = parameter(args, 'width', 'quotewidth') | 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: | ||
-- ========================================================= | -- ========================================================= | ||
-- | -- Build quote | ||
-- ========================================================= | -- ========================================================= | ||
local function build(quoteContents, quoteSource, options) | local function build(quoteContents, quoteSource, options) | ||
local quote = mw.html.create(' | local quote = mw.html.create('blockquote') | ||
:addClass('pp-quote') | :addClass('pp-quote') | ||
-- Alignment | -- Alignment classes | ||
for _, className in ipairs(options.classes) do | for _, className in ipairs(options.classes) do | ||
quote:addClass(className) | quote:addClass(className) | ||
end | end | ||
-- | -- Extra classes | ||
if options.extraClasses then | if options.extraClasses then | ||
quote:addClass(options.extraClasses) | quote:addClass(options.extraClasses) | ||
end | end | ||
-- | -- Explicit 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 content | ||
quote:node(quoteContents) | quote:node(quoteContents) | ||
| Line 124: | Line 124: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = | local options = getOptions(args) | ||
local quoteText = | local quoteText = | ||
| Line 133: | Line 133: | ||
local person = | local person = | ||
args[2] | args[2] | ||
or parameter(args, 'person', 'speaker', 'personquoted') | or parameter( | ||
args, | |||
'person', | |||
'speaker', | |||
'personquoted' | |||
) | |||
local source = | local source = | ||
args[3] | args[3] | ||
or parameter(args, 'source', 'quote_source') | or parameter( | ||
args, | |||
'source', | |||
'quote_source' | |||
) | |||
-- Quote text | -- Quote text | ||
local quoteContents = mw.html.create('div') | local quoteContents = mw.html.create('div') | ||
:addClass('pp-quote__text') | :addClass('pp-quote__text') | ||
:wikitext(quoteText) | :wikitext(quoteText) | ||
-- | |||
-- Source | |||
local quoteSource | local quoteSource | ||
| Line 154: | Line 165: | ||
quoteSource = source | quoteSource = source | ||
end | end | ||
return build( | return build( | ||
| Line 170: | Line 182: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local options = | local options = getOptions(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 183: | Line 196: | ||
if speaker and line then | if speaker and line then | ||
quoteContents | quoteContents | ||
:tag('div') | :tag('div') | ||
| Line 192: | Line 206: | ||
:done() | :done() | ||
:wikitext(' ' .. | :wikitext(' ' .. line) | ||
:done() | :done() | ||
end | end | ||
end | end | ||
-- Dialogue source | -- Dialogue source | ||
local context = parameter(args, 'context') | local context = | ||
local source = parameter(args, 'source') | parameter(args, 'context') | ||
local source = | |||
parameter(args, 'source') | |||
local quoteSource | local quoteSource | ||
| Line 211: | Line 229: | ||
quoteSource = source | quoteSource = source | ||
end | end | ||
return build( | return build( | ||