Module:Quote: Difference between revisions

From Heterodontosaurus Balls
m Removed protection from "Module:Quote"
Test
Tag: Reverted
Line 1: Line 1:
local Quote = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs
local i18n = require('Module:I18n').loadMessages('Quote')


local function build(quotecontents, quotesource, options)
-- Helper function to map size keywords to pixel values
    local quotecontainer = mw.html.create('blockquote')
local function getSizeValue(size)
        :addClass('pull-quote')
local map = {
        :addClass(options.align)
["10px"] = { pad = "40px", font = "20px" },
        :addClass(options.extraclasses)
["30px"] = { pad = "60px", font = "60px" },
        :css(options.styles)
["40px"] = { pad = "70px", font = "80px" },
        :css('font-style', 'italic')
["50px"] = { pad = "80px", font = "100px" },
        :cssText(options.extrastyles)
["60px"] = { pad = "90px", font = "120px" }
       
}
    quotecontainer:node(quotecontents)
return map[size] or { pad = "50px", font = "36px" }
       
    if quotesource then
    quotecontainer:tag('div')
    :tag('cite')
        :addClass('pull-quote__source')
        :wikitext(quotesource)
        :done()
        :done()
    end
   
    return quotecontainer
end
end


local function options(args)
function p.main(frame)
    local options = {}
local args = frame:getParent().args
   
local quote = args[1] or "Insert the text of the quote here, without quotation marks"
    options.styles = {}
local author = args[2]
    options.extraclasses = i18n:parameter('class', args)
local size = args.size or args[3] or args.quotewidth or args.width or "20px"
    options.extrastyles = i18n:parameter('style', args)
 
    options.align = ''
local sizes = getSizeValue(size)
    local align = i18n:parameter('align', args)
 
    if align then
local out = {}
        options.align = 'pull-quote--' .. align
        options.styles['width'] = i18n:parameter('width', args) or
                                  i18n:parameter('quotewidth', args) or
                                  '300px'
    end
   
    return options
end


function Quote.quote(frame)
table.insert(out, '<table style="margin: auto; border-collapse:collapse; border-style:none; background-color:transparent;" class="cquote">')
    local args = getArgs(frame)
table.insert(out, '<tr><td>')
table.insert(out, '<div style="padding:4px ' .. sizes.pad .. ';position:relative;">')
table.insert(out, '<span style="position:absolute;left:10px;top:-6px;z-index:1;font-family:\'Times New Roman\',serif;font-weight:bold;color:#B2B7F2;font-size:' .. sizes.font .. ';">“</span>')
table.insert(out, '<span style="position:absolute;right:10px;bottom:-16px;z-index:1;font-family:\'Times New Roman\',serif;font-weight:bold;color:#B2B7F2;font-size:' .. sizes.font .. ';">”</span>')
table.insert(out, '<span style="font-size:16px;">' .. quote .. '</span>')
table.insert(out, '</div></td></tr>')


    local options = options(args)
if author and author ~= "" then
   
table.insert(out, '<tr><td style="padding:4px 10px 8px;font-size:14px;line-height:1.6em;text-align:right;">— ' .. author .. '</td></tr>')
    local quotetext = args[1] or
end
                      i18n:parameter('quotetext', args) or
                      i18n:parameter('quote', args) or
                      i18n:parameter('text', args)
    local person = args[2] or
                  i18n:parameter('person', args) or
                  i18n:parameter('speaker', args) or
                  i18n:parameter('personquoted', args) or nil
    local source = args[3] or
                  i18n:parameter('source', args) or
                  i18n:parameter('quotesource', args) or nil
   
    local quotecontents = mw.html.create('p')
        :addClass('pull-quote__text')
        :wikitext(quotetext)
   
    local quotesource = person
   
    if person and source then
        quotesource = person .. ', ' .. source
    elseif source then
    quotesource = source
    end
   
    return build(quotecontents, quotesource, options)
end


function Quote.dialogue(frame)
table.insert(out, '</table>')
    local args = getArgs(frame)
   
    local options = options(args)
   
    local quotecontents = mw.html.create('div')
        :addClass('pull-quote__text')
       
    local quotesource


    for i, v in ipairs(args) do
return table.concat(out, "")
        local next_param = i + 1
       
        if i % 2 ~= 0 then
            quotecontents:tag('div')
                :addClass('pull-quote__line')
                :tag('strong')
                    :addClass('pull-quote__speaker')
                    :wikitext(v .. ':')
                    :done()
                :wikitext(' ' .. args[next_param])
                :done()
        end
    end
   
    local context = i18n:parameter('context', args)
    local source = i18n:parameter('source', args)
    if context and source then
        quotesource = context .. ', ' .. source
    elseif context and not source then
        quotesource = context
    elseif source and not context then
        quotesource = source
    end
   
    return build(quotecontents, quotesource, options)
   
end
end


return Quote
return p

Revision as of 07:35, 11 November 2025

Documentation for this module may be created at Module:Quote/doc

local p = {}

-- Helper function to map size keywords to pixel values
local function getSizeValue(size)
	local map = {
		["10px"] = { pad = "40px", font = "20px" },
		["30px"] = { pad = "60px", font = "60px" },
		["40px"] = { pad = "70px", font = "80px" },
		["50px"] = { pad = "80px", font = "100px" },
		["60px"] = { pad = "90px", font = "120px" }
	}
	return map[size] or { pad = "50px", font = "36px" }
end

function p.main(frame)
	local args = frame:getParent().args
	local quote = args[1] or "Insert the text of the quote here, without quotation marks"
	local author = args[2]
	local size = args.size or args[3] or args.quotewidth or args.width or "20px"

	local sizes = getSizeValue(size)

	local out = {}

	table.insert(out, '<table style="margin: auto; border-collapse:collapse; border-style:none; background-color:transparent;" class="cquote">')
	table.insert(out, '<tr><td>')
	table.insert(out, '<div style="padding:4px ' .. sizes.pad .. ';position:relative;">')
	table.insert(out, '<span style="position:absolute;left:10px;top:-6px;z-index:1;font-family:\'Times New Roman\',serif;font-weight:bold;color:#B2B7F2;font-size:' .. sizes.font .. ';">“</span>')
	table.insert(out, '<span style="position:absolute;right:10px;bottom:-16px;z-index:1;font-family:\'Times New Roman\',serif;font-weight:bold;color:#B2B7F2;font-size:' .. sizes.font .. ';">”</span>')
	table.insert(out, '<span style="font-size:16px;">' .. quote .. '</span>')
	table.insert(out, '</div></td></tr>')

	if author and author ~= "" then
		table.insert(out, '<tr><td style="padding:4px 10px 8px;font-size:14px;line-height:1.6em;text-align:right;">— ' .. author .. '</td></tr>')
	end

	table.insert(out, '</table>')

	return table.concat(out, "")
end

return p