Emperor's Domination Wiki
Advertisement

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

local p = {}
local m = require("Module:Main")
local chapters = require("Module:Chapters")
local getArgs = require('Dev:Arguments').getArgs


function p.lua_main(eng, zh, speaker, source, font_size, namespace, about)
    font_size = font_size or '150%'
    local right_mark = p.quotation_mark(' „', font_size)
    local left_mark = p.quotation_mark('“ ', font_size)   
    local quote_eng
    local quote_zh = ''
    local categories = {}
    local output = {}

    table.insert(output, left_mark)
    if not m.empty(zh)
        then 
            quote_zh = p.quote(zh, 'quote_zh')
            quote_eng = p.quote(eng, 'quote_eng')
            table.insert(output, p.quote(quote_eng..quote_zh, 'quote', font_size) )
        else
            table.insert(output, p.quote(eng, 'quote', font_size) )
            table.insert(categories, 'Quote Chinese Version Needed')
    end
    table.insert(output, right_mark)

    if not m.empty(speaker)
        then 
            if namespace ~= 'Category'
                then 
                    if m.link(speaker)
                        then table.insert(categories, m.break_link({speaker, 1})..'/Quotes')
                        elseif string.lower(speaker) == 'narrator'
                            then table.insert(categories, 'Quotes by Narrator')
                    end
            end
            if string.lower(speaker) ~= 'narrator'
                then 
                    if not m.empty(about)
                        then speaker = speaker..' about '..about
                    end
                    table.insert(output, p.speaker(speaker) )
            end
        else table.insert(categories, 'Quote Speaker Needed')
    end
    if not m.empty(about)
        then table.insert(categories, 'Quotes about '..m.break_link({about, 1}))
    end

    if namespace ~= 'Chapter'
        then
            if not m.empty(source)
                then table.insert(output, chapters.lua_ref(source) )
                elseif namespace ~= 'Category'
                    then table.insert(categories, 'Quote Source Needed')
            end
    end
    
    return table.concat(output)..m.add_categories(categories)
end

function p.main(frame)
    local args = getArgs(frame)
    local eng = args[1]
    local zh = args['zh'] or ''
    local speaker = args['speaker'] or ''
    local about = args['about'] or ''
    local source = args['source'] or ''
    local font_size = args['font-size'] or args['font_size']
    local namespace = mw.title.getCurrentTitle().nsText
    
    output = p.lua_main(eng, zh, speaker, source, font_size, namespace, about)

    return frame:preprocess(output)
end


function p.speaker(text)
    local output = mw.html.create( 'span' )
                :css( 'font-family', 'serif' )
                :css( 'font-size', '100%' )
                :css( 'font-weight', 'bold' )
                :css( 'color', 'firebrick' )
                :css( 'padding-left', '3em' )
                :wikitext('— '..text)
                :done()
    return '<br />'..tostring(output)
end


function p.quote(text, class, font_size)
    local output = mw.html.create( 'span' )
                :attr( 'class', class )
                :wikitext(text)
                :done()
    if not m.empty(font_size)
        then output:css( 'font-size', font_size )
    end
                
    return tostring(output)
end


function p.quotation_mark(text, font_size)
    local size
    local output
    
    if not m.empty(font_size)
        then size = string.gsub(font_size, '%%', '')
        else size = 200
    end
    size = tostring( tonumber(size) + 50 )..'%'

    output = mw.html.create( 'span' )
                :css( 'font-family', 'serif' )
                :css( 'font-size', size )
                :css( 'font-weight', 'bold' )
                :css( 'color', 'firebrick' )
                :wikitext(text)
                :done()
    
    return tostring(output)
end


function p.lua_div_quote(quote)
    local tag = mw.html.create('div')
                :css('border', '1px solid #AAAAAA')
                :css('border-radius', '10px')
                :css('padding', '5px')
                :css('margin', '5px')
    quote = string.gsub(quote, '%[%[Category:.-%]%]', '')
    return tostring( tag:wikitext(quote) )
end


function p.list_of_quotes(frame)
    local args = getArgs(frame)
    local category = args[1] or mw.title.getCurrentTitle().text
    local namespace = mw.title.getCurrentTitle().nsText
    --local category = pagename..'/Quotes'
    local quote = ''
    local speaker = ''
    local source = ''
    local zh = ''
    local s = ''
    local i
    local dpl_chapter = {}
    local dpl_main = {}
    local output = {}
    
    -------------------------- CHAPTER NAMESPACE --------------------------
    table.insert(dpl_chapter, '{{#dpl:')
    table.insert(dpl_chapter, '|category = '..category)
    table.insert(dpl_chapter, '|namespace = Chapter')
    table.insert(dpl_chapter, '|include  = {Infobox Chapter}:quote')
    table.insert(dpl_chapter, '|mode = userformat')
    table.insert(dpl_chapter, '|secseparators = %PAGE%~,@@@')
    table.insert(dpl_chapter, '|noresultsheader = &#x20;')
    table.insert(dpl_chapter, '}}')
    
    dpl_chapter = frame:preprocess( table.concat(dpl_chapter) )
    dpl_chapter = string.gsub(dpl_chapter, '&#x20;', '')
    
    if not m.empty(dpl_chapter)
        then
            dpl_chapter = mw.text.split(dpl_chapter, '@@@')
            for i = 1,#dpl_chapter do
                if not m.empty(dpl_chapter[i])
                    then
                        s = mw.text.split(dpl_chapter[i], '~')
                        source = string.gsub(s[1], 'Chapter:', '')
                        quote = s[2]..chapters.lua_ref(source)
                        table.insert( output, p.lua_div_quote(quote) )
                end
            end
    end
                        
    -------------------------- MAIN NAMESPACE --------------------------
    table.insert(dpl_main, '{{#dpl:')
    table.insert(dpl_main, '|category = '..category)
    table.insert(dpl_main, '|namespace = 0')
    table.insert(dpl_main, '|include  = {Quote}:1, {Quote}:speaker, {Quote}:source, {Quote}:zh')
    table.insert(dpl_main, '|mode = userformat')
    table.insert(dpl_main, '|secseparators = %PAGE%~,~,,~,,~,,~@@@')
    table.insert(dpl_main, '|noresultsheader = &#x20;')
    table.insert(dpl_main, '}}')
    
    dpl_main = frame:preprocess( table.concat(dpl_main) )
    dpl_main = string.gsub(dpl_main, '&#x20;', '')
    
    if not m.empty(dpl_main)
        then
            dpl_main = mw.text.split(dpl_main, '@@@')
            for i = 1,#dpl_main do
                if not m.empty(dpl_main[i])
                    then
                        s = mw.text.split(dpl_main[i], '~')
                        quote = s[2] or ''
                        speaker = s[3] or ''
                        zh = s[5] or ''
                        if not m.empty(s[4])
                            then source = s[4]
                            elseif string.find(s[1], 'Chapter:', 1, true)  ~= nil
                                then source = string.gsub(s[1], 'Chapter:', '')
                        end
                        s = p.lua_main(quote, zh, speaker, source, '150%', namespace)
                        table.insert( output, p.lua_div_quote(s) )
                end
            end
    end
    
    return frame:preprocess( table.concat(output) )
end


function p.test_list()
    local pagename = 'Li Qiye/Personality'
    local pagetype = require("Module:PageType")
    local content = pagetype.lua_getContent(pagename)
    local s = ''
    local quote = ''
    local zh = ''
    local speaker = ''
    local about = ''
    local source = ''
    local output = {}
    
    
    for s in mw.ustring.gmatch(content, '{{Quote|(.-)}}') do
        --s = string.gsub(s, '|font-size=%d+%%', '')
        s = s..'|'
        mw.log(s)
        --quote = string.match(s, '^(.-)|')
        --mw.log(quote)
        source = string.match(s, 'source=(.-)|') or ''
        mw.log(source)
        s = string.gsub(s, 'source='..source..'|', '')
        mw.log(s)
        speaker = string.match(s, 'speaker=(.-)|')
        s = string.gsub(s, 'speaker=%'..speaker..'%|', '')
        mw.log('speaker='..speaker)
        mw.log(s)
        table.insert(output, s)
    end    
    
    return output[2]
end

return p
Advertisement