Module:Quote: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
m (1 revision imported)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- This Module is used for making templates based in the Lua language.
-- <nowiki>
-- See more details about Lua in [[w:Help:Lua]].
local Quote = {}
-- The Fandom Developer's Wiki hosts Global Lua Modules that can be imported and locally overridden.
local getArgs = require('Module:Arguments').getArgs
-- The next line imports the Quote module from the [[w:c:dev:Global Lua Modules]].
local i18n = require('Module:I18n').loadMessages('Quote')
local Quote = require('Dev:Quote')
 
-- See more details about this module at [[w:c:dev:Global_Lua_Modules/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)
        :cssText(options.extrastyles)
       
    quotecontainer:node(quotecontents)
       
    if quotesource then
    quotecontainer:tag('div')
        :addClass('pull-quote__source')
        :wikitext(quotesource)
        :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 source then
        quotesource = person .. ', ' .. 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


-- The last line produces the output for the template
return Quote
return Quote

Latest revision as of 01:00, 16 May 2021

This module is used by most of the basic Quote templates and is invoked by {{Quote}}.


-- <nowiki>
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)
        :cssText(options.extrastyles)
        
    quotecontainer:node(quotecontents)
        
    if quotesource then
	    quotecontainer:tag('div')
        	:addClass('pull-quote__source')
        	:wikitext(quotesource)
        	: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 source then
        quotesource = person .. ', ' .. 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