FANDOM

 
34,653 Pages

local Theme = {}
----------------------------
-- Libraries of functions --
----------------------------
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Dev:Arguments').getArgs
-- stands for High Frequency
local HF = require('Module:HF')
 
-----------------------
-- Libraries of data --
-----------------------
-- local Colors = mw.loadData( 'Module:Theme/data' )
-- local headerColors = Colors.Header
-- local backgroundColors = Colors.Background
-- local titleTextColors = Colors.TitleText
 
------------------------------------------------
-- Local functions (used only in this Module) --
------------------------------------------------
local function GetTheme( theme, position )
    local pos = tonumber(position)
        and ( tonumber(position) * 2 )
        or 1
    local properTheme = theme:gsub(string.char( 0x27 ), '') -- removes apostrophe / single quote
        :gsub( '[', pos ):gsub( ']', '' )
        :gsub('{{si}}', '')
        :gsub('<br%s*/?>', '')
        :upper()
    return properTheme
end
 
local function Si( spaces )
    local nbsps = tonumber( spaces ) 
        and tonumber( spaces ) * 4
        or 4
    return '<br/>' .. ('&nbsp;'):rep(nbsps)
end
 
 
local function headerColor(term, frame)
    -- This should use a data table instead of {{Header}}
    return frame:expandTemplate{
        title = 'Header',
        args = { Theme = term }
    }
end
local function backgroundColor(term, frame)
    -- This should use a data table instead of {{Background}}
    return frame:expandTemplate{
        title = 'Background',
        args = { Theme = term }
    }
end
local function titleTextColor(term, frame)
    -- This should use a data table instead of {{TitleTextColour}}
    return frame:expandTemplate{
        title = 'TitleTextColour',
        args = { Theme = term }
    }
end
 
local function ThemeSet(page, img)
    local nbsp = '&nbsp;'
    local info = mw.smw.ask{ 
        HF.Link(page),
        '?Image',
        '?Pieces',
        '?Minifigures',
        '?USPrice',
        '?DEPrice',
        '?Released',
        'mainlabel=-'
    }
    info = type(info) == 'table'
        and info[1]
        or nil
    if not info then return nil end
 
    local image = (img or info['Image']) 
    image = image 
        and HF.Link('File:'..image, '100px')
        or 'No image'
    local row = mw.html.create('tr')
    :css('border', '1px solid #aaa')
    :css('background','#fff')
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(image):done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(tostring(page):match('^%S*')):done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(
            HF.Link( page:sub(0), page:match('%s(.*)$') or page:sub(0) )
        )
        :done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(info['Pieces'] and info['Pieces'] .. '' or nbsp):done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(
            info['Minifigures']
            and info['Minifigures']:gsub('<br%s*/?>', ', '):gsub('"%n"', '')
        )
        :done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(
            (info['USPrice'] and info['DEPrice'])
            and table.concat(
                {info['USPrice'], info['DEPrice']}, 
                nbsp .. '/' .. nbsp
                )
            or info['USPrice'] 
            or info['DEPrice']
            or nbsp
        ):done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(info['Released'] or nbsp):done()
    :done()
 
    return row
end
 
local function LOW_entry(arg1, arg2, arg3)
    local info = mw.smw.ask{ 
        HF.Link(arg1 or ''),
        '?Image',
        'mainlabel=-'
    }
    info = type(info) == 'table'
        and info[1]
        or nil
    if not info then return nil end
 
    local image = (arg1 or info['Image']) 
    if arg1 == 's' then
    -- {{#show:{{#replace:{{#replace:{{#replace:{{{2}}}|{{Dlb}}}}|{{Drb}}}}|''}}|?Image}}
    else
    end
 
    image = image 
        and HF.Link('File:'..image, 'x60px|center')
        or 'No image'
 
    arg3 = arg3 == 'mp'
        and "Minifigure based on actor's portrayal of the character."
        or arg3
    arg3 = arg3 == 'mv'
        and "Minifigure based on an animated/CGI character that this actor voiced."
        or arg3
    arg3 = arg3 ~= nil
        and arg3
        or ''
 
    local row = mw.html.create('tr')
    :tag('td')
        :wikitext(image):done()
    :tag('td')
        :wikitext(arg2):done()
    :tag('td')
        :wikitext(arg3):done()
    :done()
 
    return row
end
 
 
 
----------------------------------------------------------
-- Public functions (called from a Template or article) --
----------------------------------------------------------
-- Helper for the {{Theme}} infobox template
function Theme.Theme(frame)
end
 
-- Lua analogue for {{ThemeSet}}
function Theme.ThemeSet(frame)
    local args = getArgs(frame)
    return tostring( ThemeSet( args[1], args['image'] ) )
end
 
-- Lua analogue for {{Si}}
function Theme.Si(frame)
    return Si( getArgs(frame)[1] )
end
 
-- Interacts with the {{ThemeTable/renovations}} template
function Theme.makeTable(frame)
  local t = getArgs(frame, { trim = true, removeBlanks = true })
  PageTitle = mw.title.getCurrentTitle().text
  local PageSMW = mw.smw.ask{ PageTitle, '?Title', '?Subtheme of', 'mainlabel=-'}
 
  PageSMW = type(PageSMW) == 'table'
        and PageSMW[1]
        or nil
 
  local title = PageSMW and PageSMW['Title'] or ''
  local subtheme = PageSMW and PageSMW['Subtheme of'] or ''
 
    -- This color checking should not involve templates, but it does, so we need to shoehorn in "frame"   
    local colorCheck = headerColor(HF.Link(title), frame) == '#4F778B'
        and true or nil
 
    local background = colorCheck
        and backgroundColor(subthemeOf .. Si() .. HF.Link(title), frame)
        or backgroundColor(HF.Link(title), frame)
 
    local header = colorCheck
        and headerColor(subthemeOf .. Si() .. HF.Link(title), frame)
        or headerColor(HF.Link(title), frame)
 
    local titletext = colorCheck
        and titleTextColor(subthemeOf .. Si() .. HF.Link(title), frame)
        or titleTextColor(HF.Link(title), frame)
 
  local envelope = mw.html.create('div'):addClass('ttbutton'):wikitext('<span class="top">top</span> &bull; <span class="bottom">bottom</span>'):done()
  return (t[1])
    and tostring(Theme._makeTable(t, title, subthemeOf, background, header, titletext))
    or nil
end
 
-- Internal logic for ThemeTable/renovations
function Theme._makeTable(args, title, subthemeOf, background, header, titletext)
    -- See {{ThemeTable/renovations}}
 
 
    local wikitable = mw.html.create('table')
    :addClass('themetable'):addClass('sortable')
    :attr('cellspacing',0):attr('cellpadding',4):attr('border',1)
    :css('border','1px #cfcfcf solid'):css('border-radius','5px'):css('font-size','90%'):css('width','98.5%')
    :css('background-color', background)
 
    :tag('tr'):attr('bgcolor', header):css('border','1px #cfcfcf solid;'):css('border-radius','5px 0 0 5px'):css('color', titletext)
 
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :css('border-radius','5px'):attr('width','100pt')
        :wikitext("Image"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :wikitext("#"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :wikitext("Set"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :wikitext("Number of pieces"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :wikitext("Minifigures"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :wikitext("Price"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :css('border-radius','0 5px 5px 0')
        :wikitext("Release"):done()
    :done()
 
    for itemno, item in ipairs(args) do
        wikitable:node( ThemeSet(item, nil) )
    end
 
    wikitable:done()
    return wikitable
end
 
-- Interacts with the {{ListOfWorks}} template
function Theme.ListOfWorks_Table(frame)
  local t = getArgs(frame, { trim = true, removeBlanks = true })
  return (t[1])
    and tostring(Theme._ListOfWorks_Table(t))
    or nil
end
 
-- Internal logic for ListOfWorks
function Theme._ListOfWorks_Table(args)
    -- See https://en.brickimedia.org/w/Template:ListOfWorks
-- <table class="worktable" cellspacing="0" cellpadding="4" border="0" style="margin: 0 0 1em 1em; border: 1px #666666 solid; font-size: 90%; width:98.5%; border-spacing: 0; border-radius: 7px">
 
    local wikitable = mw.html.create('table')
    :addClass('worktable'):addClass('sortable')
    :attr('cellspacing',0):attr('cellpadding',4):attr('border',0)
    :css('margin','0 0 1em 1em'):css('border','1px #666666 solid'):css('border-radius','7px'):css('border-spacing',0):css('font-size','90%'):css('width','98.5%')
    :css('background-color', background)
 
    :tag('tr'):attr('bgcolor', header):css('border','1px #cfcfcf solid;'):css('border-radius','5px 0 0 5px'):css('color', titletext)
 
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
    :css('border-radius','5px'):attr('width','100pt')
        :wikitext("Image"):done()
    :tag('th'):css('border-radius','6px 0 0 0')
        :wikitext("Work"):done()
    :tag('th'):css('border-radius','0 6px 0 0')
        :wikitext("Notes"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :css('border-radius','0 5px 5px 0')
        :wikitext("Release"):done()
    :done()
 
    for argcounter = 2, 170, 3 do
        wikitable:node( LOW_entry(args[(argcounter - 1)], argcounter, args[(argcounter + 1)]) )
    end
 
    wikitable:done()
    return wikitable
end
 
return Theme
Community content is available under CC-BY-SA unless otherwise noted.