Module:Quote: Difference between revisions

From Heterodontosaurus Balls
Test
Tag: Reverted
Undo revision 39829 by Heterodontosaurus (talk)
Tag: Undo
 
Line 1: Line 1:
local p = {}
local Quote = {}
local getArgs = require('Module:Arguments').getArgs
local i18n = require('Module:I18n').loadMessages('Quote')


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


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


local sizes = getSizeValue(size)
function Quote.quote(frame)
    local args = getArgs(frame)


local out = {}
    local options = options(args)
 
   
table.insert(out, '<table style="margin: auto; border-collapse:collapse; border-style:none; background-color:transparent;" class="cquote">')
    local quotetext = args[1] or
table.insert(out, '<tr><td>')
                      i18n:parameter('quotetext', args) or
table.insert(out, '<div style="padding:4px ' .. sizes.pad .. ';position:relative;">')
                      i18n:parameter('quote', args) or
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>')
                      i18n:parameter('text', args)
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>')
    local person = args[2] or
table.insert(out, '<span style="font-size:16px;">' .. quote .. '</span>')
                  i18n:parameter('person', args) or
table.insert(out, '</div></td></tr>')
                  i18n:parameter('speaker', args) or
 
                  i18n:parameter('personquoted', args) or nil
if author and author ~= "" then
    local source = args[3] or
table.insert(out, '<tr><td style="padding:4px 10px 8px;font-size:14px;line-height:1.6em;text-align:right;">— ' .. author .. '</td></tr>')
                  i18n:parameter('source', args) or
end
                  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


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


return table.concat(out, "")
    for i, v in ipairs(args) do
        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 p
return Quote

Latest revision as of 07:36, 11 November 2025

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

local Quote = {}
local getArgs = require('Module:Arguments').getArgs
local i18n = require('Module:I18n').loadMessages('Quote')

local function build(quotecontents, quotesource, options)
    local quotecontainer = mw.html.create('blockquote')
        :addClass('pull-quote')
        :addClass(options.align)
        :addClass(options.extraclasses)
        :css(options.styles)
        :css('font-style', 'italic')
        :cssText(options.extrastyles)
        
    quotecontainer:node(quotecontents)
        
    if quotesource then
	    quotecontainer:tag('div')
	    	:tag('cite')
	        	:addClass('pull-quote__source')
	        	:wikitext(quotesource)
	        	:done()
        	:done()
    end
    
    return quotecontainer
end

local function options(args)
    local options = {}
    
    options.styles = {}
    options.extraclasses = i18n:parameter('class', args)
    options.extrastyles = i18n:parameter('style', args)
    options.align = ''
    local align = i18n:parameter('align', args)
    if align then
        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)
    local args = getArgs(frame)

    local options = options(args)
    
    local quotetext = args[1] or
                      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)
    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
        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

return Quote