Módulo:Título
Ir para navegação
Ir para pesquisar
Documentação do módulo
Esta documentação é transcluída de Predefinição:Sem documentação/doc. [editar] [atualizar]
Este módulo não possui nenhuma documentação. Por favor, considere adicionar uma documentação em Módulo:Título/doc. [editar]
Módulo:Título's a função main é invocada por Predefinição:Título.
Módulo:Título requer Module:Paramtest.
Módulo:Título requer Module:Yesno.
--
-- Implementa [[Predefinição:Título]]
--
local p = {}
local yesno = require('Module:Yesno')
local hc = require('Module:Paramtest').has_content
local locs = {
sim = 'p',
['não'] = 's',
nao = 's',
}
function parseColor(col)
local r,g,b = col:match('#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])')
local cstr
if r ~= nil then
r = tonumber(r .. r, 16)
g = tonumber(g .. g, 16)
b = tonumber(b .. b, 16)
else
r,g,b = col:match('#([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F]')
if r ~= nil then
return nil
end
end
if r == nil then
return ''
end
local yiq = (r * 299 + g * 587 + b * 114)/1000
if yiq > 128 then
return 'rs-title-darkbg', yiq
else
return 'rs-title-lightbg', yiq
end
end
p.parseColor = parseColor
function p.main(frame)
local args = frame:getParent().args
local title = args.t or args[1] or '<title>'
local loc = locs[string.lower(args.p or '')]
local comma = args[',']
local bg = yesno(args.bg)
local ftitle = args.f or false
-- default no colouring
local commacolor = false
if comma and comma:lower() == 'v' then
comma = true
commacolor = true
elseif comma then
comma = yesno(comma)
end
-- yesno defaults to false if the argument is nil, have it default to true
local space = yesno(args.e or 'true')
-- default colour black
local color = args.c or 'black'
local link = false
if hc(args.link) then
link = args.link
end
return p._main(title, color, bg, loc, comma, commacolor, space, link, ftitle)
end
function p._main(title, color, bg, loc, comma, commacolor, space, link, ftitle)
-- Copy title to a different variable before editing it
local titleid = title
-- If comma needs colouring
-- Edit a comma into the title before adding to span
if comma and commacolor then
if loc == 'p' then
title = title..', '
elseif loc == 's' then
title = ', '..title
end
end
-- Tag to keep everything on one line
local ret = mw.html.create('span')
:css({ ['font-weight'] = 'bold',
['white-space'] = 'nowrap',
color = bg and '#FFFFFF' or '' })
-- Background for lighter coloured titles
-- Also some padding so it isn't weird
if bg then
ret:css({ background = '#19364C',
padding = '3px 2px' })
end
local tspan
-- for "<title> [Nome]"
if loc == 'p' then
tspan = ret:tag('span')
tspan:css('color',color)
:wikitext(title)
:done()
if not commacolor then
if comma then
ret:wikitext(', ')
elseif space then
ret:wikitext(' ')
end
end
ret:wikitext('[Nome]')
-- for "[Nome] <title>"
elseif loc == 's' then
ret:wikitext('[Nome]')
if not commacolor then
if comma then
ret:wikitext(', ')
elseif space then
ret:wikitext(' ')
end
end
tspan=ret:tag('span')
tspan:css('color',color)
:wikitext(title)
:done()
-- Otherwise just do <title>
else
tspan=ret
tspan:css('color',color)
:wikitext(title)
end
if ftitle then
tspan:css('border-bottom', 'dotted 1px grey')
:attr('title', ftitle)
end
-- Don't add the anchor except on [[Titles]]
if mw.title.getCurrentTitle().text == 'Titles' then
-- Look for and strip various mark-ups for multi colored titles
-- <span>
titleid = titleid:gsub('</?span.->','')
-- Uppercase first letter
titleid = mw.text.split(titleid,'')
titleid[1] = titleid[1]:upper()
titleid = table.concat(titleid,'')
ret:attr('id',titleid)
end
-- Don't add the anchor except on [[Titles]]
if mw.title.getCurrentTitle().text == 'Titles' then
-- Look for and strip various mark-ups for multi colored titles
-- <span>
titleid = titleid:gsub('</?span.->','')
-- Uppercase first letter
titleid = mw.text.split(titleid,'')
titleid[1] = titleid[1]:upper()
titleid = table.concat(titleid,'')
ret:attr('id',titleid)
end
if link == 'não' then
ret = ret
elseif link then
ret = string.format('[[%s|%s]]', link, tostring(ret))
else
ret = string.format('[[%s|%s]]', titleid, tostring(ret))
end
return ret
end
return p