Module:Hatnote: Difference between revisions
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Content deleted Content added
Tesinormed (talk | contribs) No edit summary |
Tesinormed (talk | contribs) No edit summary |
||
| Line 53: | Line 53: | ||
-- center text |
-- center text |
||
local text = content:tag('div') |
local text = content:tag('div') |
||
-- primary text |
-- primary text wrapper |
||
local primary_text = text:tag('span') |
local primary_text = text:tag('span') |
||
:css('display', 'inline-block') |
:css('display', 'inline-block') |
||
| Line 69: | Line 69: | ||
-- primary text font family |
-- primary text font family |
||
primary_text:css('font-family', args['font'] or 'var(--font-family-serif)') |
primary_text:css('font-family', args['font'] or 'var(--font-family-serif)') |
||
-- primary text |
|||
primary_text:wikitext(args['primary']) |
|||
-- right file |
-- right file |
||
Revision as of 18:31, January 13, 2025
This module is used for Template:Hatnote. See the template's page for more information.
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
function p.main(frame)
local args = getArgs(frame)
local wrapper = mw.html.create('div')
:attr('class', 'noexcerpt')
:attr('role', 'note')
-- input validation
if not args['file1'] and args['file2'] then
error('file2 is specified while file1 is not specified')
end
if not args['primary'] then
error('primary is not specified')
end
-- set the color so the look stays consistent even outside of the scope
if args['color'] then
wrapper:css('--color-amaranth-legacy-scope', args['color'])
if yesno(args['color_applies_to_links'] or true) then
wrapper:css('--color-link', args['color'])
end
end
-- top <hr>
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_top'] or false) then
wrapper:wikitext('<hr>')
end
-- content wrapper
local content = wrapper:tag('div')
if args['file1'] and args['file2'] then
content:attr('class', 'hatnote2')
elseif args['file1'] then
content:attr('class', 'hatnote1')
else
content:attr('class', 'hatnote0')
end
-- left file
if args['file1'] then
content:tag('div'):wikitext('[['
.. 'File:' .. args['file1']
.. '|' .. (args['file_size'] or '80px')
.. '|class=notpageimage'
.. '|link='
.. '|alt='
.. ']]')
end
-- center text
local text = content:tag('div')
-- primary text wrapper
local primary_text = text:tag('span')
:css('display', 'inline-block')
-- primary text color gradient
if args['primary_gradient'] then
primary_text:css('color', 'transparent')
:css('background-image', 'linear-gradient(' .. args['primary_gradient'] .. ')')
:css('-webkit-background-clip', 'text')
:css('background-clip', 'text')
else
primary_text:css('color', 'var(--color-amaranth-legacy-scope)')
end
-- primary text font size
primary_text:css('font-size', 'var(--font-size-' .. (args['primary_font_size'] or 'xx-large') .. ')')
-- primary text font family
primary_text:css('font-family', args['font'] or 'var(--font-family-serif)')
-- primary text
primary_text:wikitext(args['primary'])
-- right file
if args['file2'] then
content:tag('div'):wikitext('[['
.. 'File:' .. args['file2']
.. '|' .. (args['file_size'] or '80px')
.. '|class=notpageimage'
.. '|link='
.. '|alt='
.. ']]')
end
-- bottom <hr>
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_bottom'] or false) then
wrapper:wikitext('<hr>')
end
return tostring(wrapper)
end
return p