Editing Module:Quote

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
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 1: Line 1:
-- <nowiki>
-- This Module is used for making templates based in the Lua language.
local Quote = {}
-- See more details about Lua in [[w:Help:Lua]].
 
-- 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]]
 
-- =========================================================
-- Parameters
-- =========================================================
 
local function parameter(args, ...)
    local names = { ... }
 
    for _, name in ipairs(names) do
        local value = i18n:parameter(name, args)
 
        if value ~= nil and value ~= '' then
            return value
        end
    end
 
    return nil
end
 
 
-- =========================================================
-- Options
-- =========================================================
 
local function getOptions(args)
 
    local options = {
        classes = {},
        styles = {}
    }
 
    local extraClasses = parameter(args, 'class')
 
    if extraClasses then
        options.extraClasses = extraClasses
    end
 
    local extraStyles = parameter(args, 'style')
 
    if extraStyles then
        options.extraStyles = extraStyles
    end
 
 
    -- Alignment
 
    local align = parameter(args, 'align')
 
    if align then
        align = string.lower(align)
 
        if align == 'left' or align == 'right' then
            options.classes[#options.classes + 1] =
                'pp-quote--' .. align
 
            local width =
                parameter(args, 'width', 'quotewidth')
 
            if width then
                options.styles.width = width
            end
        end
    end
 
    return options
end
 
 
-- =========================================================
-- Build quote
-- =========================================================
 
local function build(quoteContents, quoteSource, options)
 
    local quote = mw.html.create('blockquote')
        :addClass('pp-quote')
 
    -- Alignment classes
    for _, className in ipairs(options.classes) do
        quote:addClass(className)
    end
 
    -- Extra classes
    if options.extraClasses then
        quote:addClass(options.extraClasses)
    end
 
    -- Explicit styles
    for property, value in pairs(options.styles) do
        quote:css(property, value)
    end
 
    if options.extraStyles then
        quote:cssText(options.extraStyles)
    end
 
    -- Quote content
    quote:node(quoteContents)
 
    -- Source
    if quoteSource and quoteSource ~= '' then
        quote
            :tag('div')
                :addClass('pp-quote__source')
                :wikitext(quoteSource)
                :done()
    end
 
    return quote
end
 
 
-- =========================================================
-- Normal quote
-- =========================================================
 
function Quote.quote(frame)
 
    local args = getArgs(frame)
    local options = getOptions(args)
 
    local quoteText =
        args[1]
        or parameter(args, 'quotetext', 'quote', 'text')
        or ''
 
    local person =
        args[2]
        or parameter(
            args,
            'person',
            'speaker',
            'personquoted'
        )
 
    local source =
        args[3]
        or parameter(
            args,
            'source',
            'quote_source'
        )
 
 
    -- Quote text
    local quoteContents = mw.html.create('div')
        :addClass('pp-quote__text')
        :wikitext(quoteText)
 
 
    -- Source
    local quoteSource
 
    if person and source then
        quoteSource = person .. ', ' .. source
    elseif person then
        quoteSource = person
    elseif source then
        quoteSource = source
    end
 
 
    return build(
        quoteContents,
        quoteSource,
        options
    )
end
 
 
-- =========================================================
-- Dialogue
-- =========================================================
 
function Quote.dialogue(frame)
 
    local args = getArgs(frame)
    local options = getOptions(args)
 
    local quoteContents = mw.html.create('div')
        :addClass('pp-quote__text')
        :addClass('pp-quote__text--dialogue')
 
 
    -- Dialogue lines
    for i = 1, #args, 2 do
 
        local speaker = args[i]
        local line = args[i + 1]
 
        if speaker and line then
 
            quoteContents
                :tag('div')
                    :addClass('pp-quote__line')
 
                    :tag('strong')
                        :addClass('pp-quote__speaker')
                        :wikitext(speaker .. ':')
                        :done()
 
                    :wikitext(' ' .. line)
 
                    :done()
        end
    end
 
 
    -- Dialogue source
    local context =
        parameter(args, 'context')
 
    local source =
        parameter(args, 'source')
 
    local quoteSource
 
    if context and source then
        quoteSource = context .. ', ' .. source
    elseif context then
        quoteSource = context
    elseif source then
        quoteSource = source
    end
 
 
    return build(
        quoteContents,
        quoteSource,
        options
    )
end
 


-- The last line produces the output for the template
return Quote
return Quote
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;