Jump to content

Module:Notice: Difference between revisions

From Ferret Software Wiki
m 1 revision imported: PS to FS migration
Gorasuhl (talk | contribs)
m removed unnecesary if-clause
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
-- Define constants --
local TEMPLATE_STYLES = 'Module:Notice/styles.css'


function p.getStyleForColor(color)
-- Define tables of valid values --
    result = {
local borderColors ={
        ["green"] = "rgb(170, 220, 0)",
["blue"] = true,
        ["teal"] = "rgb(47, 172, 172)",
["gray"] = true,
        ["blue"] = "rgb(0, 153, 255)",
["green"] = true,
        ["orange"] = "rgb(255, 128, 0)",
["maroon"] = true,
        ["yellow"] = "rgb(235, 238, 61)",
["orange"] = true,
        ["red"] = "rgb(217, 0, 0)",
["pink"] = true,
        ["pink"] = "rgb(240, 60, 120)",
["purple"] = true,
        ["maroon"] = "rgb(174, 21, 102)",
["red"] = true,
        ["gray"] = "rgb(201, 201, 201)",
["teal"] = true,
    }
["yellow"] = true
}
local backgroundColors ={
["blue"] = true,
["gray"] = true,
["green"] = true,
["maroon"] = true,
["orange"] = true,
["pink"] = true,
["purple"] = true,
["red"] = true,
["teal"] = true,
["yellow"] = true
}
local alignValues = {
["center"] = true,
["left"] = true,
["right"] = true
}
local textAlignValues = {
["center"] = true,
["left"] = true,
["right"] = true
}


    return result[color] or color
local p = {}
end


-- Entry point for the module
-- Entry point for the module --
function p.main(frame)
function p.main(frame)
    local args = frame:getParent().args
    local color = args.color or 'green'
    local align = args.align or ''
    local textAlign = args['text-align'] or 'left'
    local width = args.width or ''
    local file = args.file or ''
    local fileSize = args.filesize or '48px'
    local header = args.header or ''
    local content = args.content or ''


     local root = mw.html.create('div')
     local args = require('Module:ProcessArgs').merge(true)
        :addClass('notice')
        :attr('align', align)
local alignBox = args.align or 'left'
        :css('text-align', textAlign)
local alignContent = args.alignContent or ''
        :css('border-color', p.getStyleForColor(color))
local alignHeader = args.alignHeader or ''
        :css('border-radius', "5px 5px 5px 5px")
local alignText = args.alignText or 'left'
        :css('border-style', "solid")
local class = args.class or ''
        :css('border-width', "1px 5px 1px 5px")
local color = args.color or 'green'
        :css('column-gap', "1em")
local colorBack = args.colorBack or ''
        :css('display', "flex")
local content = args.content or ''
        :css('flex-direction', "row")
local file = args.file or ''
        :css('margin', ".5em 0")
local fileRight = args.fileRight or ''
        :css('padding', ".5em")
local fileSize = args.filesize or '48px'
local header = args.header or ''
local small = args.small or ''
local width = args.width or ''
if alignHeader == '' then alignHeader = alignText end
if alignContent == '' then alignContent = alignText end


    -- use template styles --
local root = mw.html.create()
root:wikitext(frame:extensionTag{
name = 'templatestyles',
args = { src = TEMPLATE_STYLES},
})


    if width ~= '' then
-- base div-section of the notice box --
        root:css('width', width)
local box = root:tag('div')
    end
if small == 'yes' then
box:addClass('notice-small')
else
box:addClass('notice')
if alignValues[alignBox] then
box:addClass(string.format('notice-%s', alignBox))
else
box:addClass('notice-left')
end
end
if borderColors[color] then
box:addClass(string.format('notice-border-%s', color))
else
box:css('border-color', color)
end
if colorBack ~= '' then
if backgroundColors[colorBack] then
box:addClass(string.format('notice-background-%s', colorBack))
else
box:css('background-color', colorBack)
end
end
if width ~= '' then
box:css('width', width)
end


-- add additional classes to the box (optional) --
if class ~= '' then box:addClass(class) end
-- adding elements to the box --
-- place file left --
     if file ~= '' then
     if file ~= '' then
        root:tag('div')
if fileRight == '' then
            :addClass('notice-image')
box:tag('div')
            :css('position', "relative")
  :addClass('notice-image')
            :css('top', "50%")
  :wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize))
            :wikitext(string.format('[[File:%s|%s|link=]]', file, fileSize))
end
end
-- place text content --
local contentDiv = ''
if header ~= '' then
contentDiv = box:tag('div')
:addClass('notice-content')
local headerDiv = contentDiv:tag('div')
:addClass('notice-header')
:addClass(string.format('notice-text-%s', alignHeader))
:wikitext(header)
     end
     end


    local contentDiv = root:tag('div')
if content ~= '' then
            :addClass('notice-content')
if contentDiv == '' then
            :css('flex-grow', 1)
contentDiv = box:tag('div')
 
:addClass('notice-content')
    if header ~= '' then
end
        contentDiv:tag('div')
local descriptionDiv = contentDiv:tag('div')
            :addClass('notice-header')
:addClass('notice-description')
            :css('font-weight', 600)
:addClass(string.format('notice-text-%s', alignContent))
            :wikitext(header)
:wikitext(content)
    end
end
 
    contentDiv:tag('div')
-- place file right --
            :addClass('notice-description')
if fileRight ~= '' then
            :css('font-size', "9pt")
if file ~= '' then
            :wikitext(content)
box:tag('div')
 
:addClass('notice-image')
     return tostring(root)
:wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize))
end
    end  
      
return tostring(root)
end
end


return p
return p

Latest revision as of 21:45, 16 June 2025

Documentation
This documentation is outdated and will be updated soon

An Module to create a Notice box with image (optional).

Usage

Use this template to create other Notice Templates.

Syntax: {{notice|color=|colorBack=|text-align=|width=|file=|filesize=|header=|content=}}

color Named, optional The color preset for the border. Defined options are green, blue, teal, orange, yellow, red, maroon, pink, and gray. However, if a color is a known CSS color, it can be used. Defaults to green.
colorBack Named, optional The color preset for the background color. Defined options are green, blue, teal, orange, yellow, red, maroon, pink, and gray with 0.2 for alpha channel. However, if a color is a known CSS color, it can be used. Defaults to none.
text-align Named, optional The text-align attribute of the header and content text, e.g. center. Defaults to left.
file Named, optional The file to show on the left-hand section as a filename. e.g. Example.jpg. Defaults to nothing shown.
filesize Named, optional The file's size on the left-hand section. e.g. 30px. Defaults to 48px if a file was specified, otherwise none.
header Named, optional The header text. e.g. Notice. Defaults to nothing shown.
content Named, optional The content text. e.g. Test message. Defaults to nothing shown.
width Named, optional The width attribute of the notice, e.g. 30%. Defaults to unwritten (inherit).

Examples

{{notice|file=Beans.png|header=Under Construction|content=This article is under construction.}}

Under Construction
This article is under construction.

{{notice|file=Beans.png|header=Notice with header text only.}}

Notice with header text only.

{{notice|file=Beans.png|content=Small notice without a header.}}

Small notice without a header.

{{notice|file=Beans.png|header=Green notice|color=green}}

Green notice

{{notice|file=Beans.png|header=Green notice with green background|color=green|colorBack=green}}

Green notice

{{notice|file=Beans.png|header=Blue notice with custom width|width=30%|color=blue}}

Blue notice with custom width

{{notice|file=Beans.png|header=Teal notice|color=teal}}

Teal notice

{{notice|file=Beans.png|header=Orange notice|color=orange}}

Orange notice

{{notice|file=Beans.png|header=Yellow notice|color=yellow}}

Yellow notice

{{notice|file=Beans.png|header=Red notice|color=red}}

Red notice

{{notice|file=Beans.png|header=Maroon notice|color=maroon}}

Maroon notice

{{notice|file=Beans.png|header=Pink notice|color=pink}}

Pink notice

{{notice|file=Beans.png|header=Gray notice|color=gray}}

Gray notice

{{notice|file=Beans.png|header=Custom color notice|color=slateblue|text-align=center}}

Custom color notice

-- Define constants --
local TEMPLATE_STYLES = 'Module:Notice/styles.css'

-- Define tables of valid values --
local borderColors ={
	["blue"] = true,
	["gray"] = true,
	["green"] = true,
	["maroon"] = true,	
	["orange"] = true,
	["pink"] = true,
	["purple"] = true,
	["red"] = true,
	["teal"] = true,
	["yellow"] = true
}
local backgroundColors ={
	["blue"] = true,
	["gray"] = true,
	["green"] = true,
	["maroon"] = true,	
	["orange"] = true,
	["pink"] = true,
	["purple"] = true,
	["red"] = true,
	["teal"] = true,
	["yellow"] = true
}
local alignValues = {
	["center"] = true,
	["left"] = true,
	["right"] = true
}
local textAlignValues = {
	["center"] = true,
	["left"] = true,
	["right"] = true
}

local p = {}

-- Entry point for the module --
function p.main(frame)

    local args = require('Module:ProcessArgs').merge(true)
	
	local alignBox = args.align or 'left'
	local alignContent = args.alignContent or ''
	local alignHeader = args.alignHeader or ''
	local alignText = args.alignText or 'left'
	local class = args.class or ''
	local color = args.color or 'green'
	local colorBack = args.colorBack or ''
	local content = args.content or ''
	local file = args.file or ''
	local fileRight = args.fileRight or ''
	local fileSize = args.filesize or '48px'
	local header = args.header or ''
	local small = args.small or ''
	local width = args.width or ''
	
	if alignHeader == '' then alignHeader = alignText end
	if alignContent == '' then alignContent = alignText end

    -- use template styles --
	local root = mw.html.create()
	root:wikitext(frame:extensionTag{
		name = 'templatestyles',
		args = { src = TEMPLATE_STYLES},
	})

	-- base div-section of the notice box --
	local box = root:tag('div')
	if small == 'yes' then
		box:addClass('notice-small')
	else
		box:addClass('notice')
		if alignValues[alignBox] then
			box:addClass(string.format('notice-%s', alignBox))
		else
			box:addClass('notice-left')	
		end
	end
	
	if borderColors[color] then
		box:addClass(string.format('notice-border-%s', color))
	else
		box:css('border-color', color)
	end
	
	if colorBack ~= '' then
		if backgroundColors[colorBack] then
			box:addClass(string.format('notice-background-%s', colorBack))
		else
			box:css('background-color', colorBack)
		end
	end
	
	if width ~= '' then
		box:css('width', width)
	end

	-- add additional classes to the box (optional) --
	if class ~= '' then box:addClass(class) end
	
	-- adding elements to the box --
	-- place file left --
    if file ~= '' then
		if fileRight == '' then
			box:tag('div')
			   :addClass('notice-image')
			   :wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize))
		end
	end
	
	-- place text content --
	local contentDiv = ''
	if header ~= '' then
		contentDiv = box:tag('div')
						:addClass('notice-content')
		local headerDiv = contentDiv:tag('div')
									:addClass('notice-header')
									:addClass(string.format('notice-text-%s', alignHeader))
									:wikitext(header)
    end

	if content ~= '' then
		if contentDiv == '' then
			contentDiv = box:tag('div')
							:addClass('notice-content')
		end
		local descriptionDiv = contentDiv:tag('div')
										 :addClass('notice-description')
										 :addClass(string.format('notice-text-%s', alignContent))
										 :wikitext(content)
	end
	
	-- place file right --
	if fileRight ~= '' then
		if file ~= '' then
			box:tag('div')
					:addClass('notice-image')
					:wikitext(string.format('[[File:%s|%s|link=|class=notpageimage]]', file, fileSize))
		end
    end			  
    
	return tostring(root)
end

return p