Brickipedia

READ MORE

Brickipedia
Advertisement

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

Script error: Lua error at line 92: ')' expected near 'notes'.

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:ListOfWorks/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',
        '?Work',
        '?Released',
        '?Notes',
        '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)):done()
    :tag('td'):css('border', '1px solid #aaa')
    for notesEntry = 1, 60 do
        if args['notes' .. notesEntry] then
        wikitable:tag('td'):wikitext('args['notes' .. notesEntry]'):done()
    :tag('td'):css('border', '1px solid #aaa')
        :wikitext(info['Released'] or nbsp):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("Work"):done()
    :tag('th'):attr('align','center'):css('border', '1px solid #cfcfcf')
        :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 itemno, item in ipairs(args) do
        wikitable:node( ThemeSet(item, nil) )
    end
    
    wikitable:done()
    return wikitable
end
 
return Theme
Advertisement