Module:The Color Printer basic tone
Appearance
This module depends on the following other modules: |
Implements {{The Color Printer basic tone}}.
require('strict')
local p = {}
local getArgs = require('Module:Arguments').getArgs
local colorData = require('Module:The Color Printer tone/data').colorData
local function capitalize(word)
return string.upper(string.sub(word, 1, 1)) .. string.sub(word, 2)
end
local function color_printer_basic_tone(args)
-- stylesheet
local stylesheet = mw.getCurrentFrame():extensionTag('templatestyles', '', {src = 'Index:The color printer (1892).djvu/styles.css'})
-- get data
local color = tonumber(args[1]) or args[1] or 'w'
if not colorData[color] then
error('Color ' .. color .. ' not found in colorData')
end
local color_name = colorData[color]['name']
if not color_name then
error('Name for color ' .. color .. ' not found in colorData')
end
color_name = mw.text.split(color_name, ' ', true)
if #color_name > 1 then
for i = 1, #color_name do
color_name[i] = capitalize(color_name[i])
end
color_name = table.concat(color_name, ' ')
else
color_name = capitalize(color_name[1])
end
local color_code = colorData[color]['rgb']
if not color_code then
error('RGB data for color ' .. color .. ' not found in colorData')
end
color_code = 'rgb(' .. table.concat(color_code, ', ') .. ')'
-- swatch
local swatch = mw.html.create('div')
:addClass('wst-color-printer-basic-tone-outer')
:css({
['color'] = color_code
})
:node(mw.html.create('div')
:addClass('wst-color-printer-basic-tone-middle')
:css({
['background-color'] = color_code,
['color'] = color_code
})
:node(mw.html.create('div')
:addClass('wst-color-printer-basic-tone-inner')
:wikitext(color)
)
)
-- caption
local caption = mw.html.create('div')
:addClass('wst-color-printer-basic-tone-caption')
:wikitext(color_name)
-- assemble
local tone_div = mw.html.create('div')
:addClass('wst-color-printer-basic-tone')
:node(swatch)
:node(caption)
return stylesheet .. tostring(tone_div)
end
function p.color_printer_basic_tone(frame)
return color_printer_basic_tone(getArgs(frame))
end
return p