Module:Sandbox/Izno
Appearance
local p = {}
function p.file() --frame
local image = 'File:US 730.svg'
local title = mw.title.new(image)
local width = title.file.width
local height = title.file.height
return string.format('%s width: %d, height: %d', image, width, height)
end
function p.basic_iteration(frame)
local pv = require('Module:If preview')
local t = { 'a', 'b', 'c', 'd', }
local t2 = { a = 'a', b = 'b', c = 'c', d = 'd' }
local preview = ''
for _, v in ipairs(t) do -- guarantees ordering
preview = preview .. pv._warning({
v
})
end
for _, v in pairs(t2) do -- doesn't guarantee ordering
preview = preview .. pv._warning({
v
})
end
return preview
end
local function has_navbar()
return true
end
function p.addListStyles()
local frame = mw.getCurrentFrame()
-- TODO?: Should maybe take a table of classes for e.g. hnum, hwrap as above
-- I'm going to do the stupid thing first though
-- Also not sure hnum and hwrap are going to live in the same TemplateStyles
-- as hlist
local function _addListStyles(htmlclass, templatestyles)
local class_args = { -- rough order of probability of use
'bodyclass', 'listclass', 'aboveclass', 'belowclass', 'titleclass',
'navboxclass', 'groupclass', 'titlegroupclass', 'imageclass'
}
local patterns = {
'^' .. htmlclass .. '$',
'%s' .. htmlclass .. '$',
'^' .. htmlclass .. '%s',
'%s' .. htmlclass .. '%s'
}
local found = false
for _, arg in ipairs(class_args) do
for _, pattern in ipairs(patterns) do
if mw.ustring.find(frame.args[arg] or '', pattern) then
found = true
break
end
end
if found then break end
end
if found then
return frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
}
else
return ''
end
end
local hlist_styles = ''
if not has_navbar() then
hlist_styles = _addListStyles('hlist', 'Flatlist/styles.css')
end
local plainlist_styles = _addListStyles('plainlist', 'Plainlist/styles.css')
return hlist_styles .. plainlist_styles
end
local msg = mw.message.newRawMessage
function p.message(frame)
local messages = {}
table.insert(messages, 'This is an inserted message')
local msg1 = msg('This is a $1 message.', 'raw')
local msg2 = msg('This is a $1 message of $2 quality.', '[[raw]]', '{{icon|fa}}')
local msg3 = msg('This is a $1 message of $2 quality.', '[[raw]]', '{{icon|fa}}'):plain()
if frame.args[1] then
table.insert(messages, frame.args[1])
end
return -- tostring(messages) .. '\n\n' .. -- this prints string 'table'
table.concat(messages) .. tostring(msg1) .. '\n\n' .. tostring(msg2) .. '\n\n' .. tostring(msg3)
end
function p.output()
local obj = mw.html.create()
obj:wikitext(p.addListStyles())
return obj
end
function p.tostringnil()
return tostring(nil)
end
function p.split_and_concatenate(frame)
local disallowed_css = {
'border',
'border%-.+',
'background',
'background%-.+',
'box-shadow',
'padding',
'padding%-.+'
}
local str = frame.args[1]
local split = mw.text.split(str, ';')
local super_split = {}
for k, v in ipairs(split) do
split[k] = mw.text.trim(v)
super_split[k] = mw.text.split(v, ':')
end
for k, t in ipairs(super_split) do
for _, v in ipairs(disallowed_css) do
if string.match(t[1], v) then
split[k] = ''
end
end
end
return table.concat(split, '\n\n')
end
function p.findColorInCSS(s)
local find = string.find
local sub = string.sub
--[[
. all characters
%a letters
%c control characters
%d digits
%l lower case letters
%p punctuation characters
%s space characters
%u upper case letters
%w alphanumeric characters
%x hexadecimal digits
%z the character with representation 0
]]
return sub(s, find(s, '[^%-]color:[^;]-;'))
end
return p