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 5: | Line 5: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local |
local content = mw.html.create('div') |
||
:addClass(' |
:addClass('hatnote') |
||
:addClass('noexcerpt') |
:addClass('noexcerpt') |
||
:attr('role', 'note') |
:attr('role', 'note') |
||
| Line 24: | Line 24: | ||
-- set the color so the look stays consistent even outside of the scope |
-- set the color so the look stays consistent even outside of the scope |
||
if args['color'] then |
if args['color'] then |
||
content:css('--color-amaranth-legacy-scope', args['color']) |
|||
if yesno(args['color_applies_to_links'] or true) then |
if yesno(args['color_applies_to_links'] or true) then |
||
content:css('--color-link', args['color']) |
|||
end |
end |
||
end |
end |
||
| Line 32: | Line 32: | ||
-- top <hr> |
-- top <hr> |
||
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_top'] or false) then |
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_top'] or false) then |
||
content:wikitext('<hr>') |
|||
end |
end |
||
-- content wrapper |
-- content wrapper |
||
local content = wrapper:tag('div'):addClass('hatnote') |
|||
if args['file1'] and args['file2'] then |
if args['file1'] and args['file2'] then |
||
content:addClass('hatnote2') |
content:addClass('hatnote2') |
||
| Line 51: | Line 50: | ||
class = class .. ' ' .. args['file1_class'] |
class = class .. ' ' .. args['file1_class'] |
||
end |
end |
||
content |
content:wikitext('[[' |
||
.. 'File:' .. args['file1'] |
.. 'File:' .. args['file1'] |
||
.. '|' .. (args['file_size'] or '80px') |
.. '|' .. (args['file_size'] or '80px') |
||
| Line 61: | Line 60: | ||
-- center text |
-- center text |
||
local text = content:tag(' |
local text = content:tag('p') |
||
-- primary text wrapper |
-- primary text wrapper |
||
local primary_text = text:tag('span') |
local primary_text = text:tag('span'):addClass('hatnote-primary') |
||
:css('display', 'inline-block') |
|||
-- primary text linear-gradient |
-- primary text linear-gradient |
||
if args['primary_gradient'] then |
if args['primary_gradient'] then |
||
| Line 99: | Line 97: | ||
class = class .. ' ' .. args['file2_class'] |
class = class .. ' ' .. args['file2_class'] |
||
end |
end |
||
content |
content:wikitext('[[' |
||
.. 'File:' .. args['file2'] |
.. 'File:' .. args['file2'] |
||
.. '|' .. (args['file_size'] or '80px') |
.. '|' .. (args['file_size'] or '80px') |
||
| Line 110: | Line 108: | ||
-- bottom <hr> |
-- bottom <hr> |
||
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_bottom'] or false) then |
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_bottom'] or false) then |
||
content:wikitext('<hr>') |
|||
end |
end |
||
return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' } } |
return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' } } |
||
.. tostring( |
.. tostring(content) |
||
end |
end |
||
Revision as of 23:35, April 16, 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 content = mw.html.create('div')
:addClass('hatnote')
:addClass('noexcerpt')
:attr('role', 'note')
-- backwards compatibility
if args['file'] then args['file1'] = args['file'] end
if args['file_class'] then args['file1_class'] = args['file_class'] end
-- input validation
if not args['file1'] and args['file2'] then
error('file1 is required when file2 is specified')
end
if not args['primary'] then
error('primary is required')
end
-- set the color so the look stays consistent even outside of the scope
if args['color'] then
content:css('--color-amaranth-legacy-scope', args['color'])
if yesno(args['color_applies_to_links'] or true) then
content: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
content:wikitext('<hr>')
end
-- content wrapper
if args['file1'] and args['file2'] then
content:addClass('hatnote2')
elseif args['file1'] then
content:addClass('hatnote1')
else
content:addClass('hatnote0')
end
-- left file
if args['file1'] then
local class = 'notpageimage'
if args['file1_class'] then
class = class .. ' ' .. args['file1_class']
end
content:wikitext('[['
.. 'File:' .. args['file1']
.. '|' .. (args['file_size'] or '80px')
.. '|class=' .. class
.. '|link='
.. '|alt='
.. ']]')
end
-- center text
local text = content:tag('p')
-- primary text wrapper
local primary_text = text:tag('span'):addClass('hatnote-primary')
-- primary text linear-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-header-custom, var(--font-family-serif))')
-- primary text text-transform
primary_text:css('text-transform', args['primary_transform'] or 'none')
-- primary text
primary_text:wikitext(args['primary'])
-- secondary text
if args['secondary'] then
-- italic secondary text
if yesno(args['italic_secondary'] or true) then
args['secondary'] = '\'\'' .. args['secondary'] .. '\'\''
end
text:wikitext('<br/>' .. args['secondary'])
end
-- right file
if args['file2'] then
local class = 'notpageimage'
if args['file2_class'] then
class = class .. ' ' .. args['file2_class']
end
content:wikitext('[['
.. 'File:' .. args['file2']
.. '|' .. (args['file_size'] or '80px')
.. '|class=' .. class
.. '|link='
.. '|alt='
.. ']]')
end
-- bottom <hr>
if not yesno(args['remove_hr'] or false) and not yesno(args['remove_hr_bottom'] or false) then
content:wikitext('<hr>')
end
return frame:extensionTag { name = 'templatestyles', args = { src = 'Module:Hatnote/styles.css' } }
.. tostring(content)
end
return p