Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Logoform: Difference between revisions

From Neodyland Wiki
first version
 
m Undo revision 1051453348 by 187.161.18.9 (talk) vandalism
 
(79 intermediate revisions by 5 users not shown)
Line 1: Line 1:
--  Module for: Formatting Logo
local p = {}


-- Parent gallery parameters
local concat = table.concat
local split = mw.text.split
local trim = mw.text.trim
local upper = mw.ustring.upper
local sub = mw.ustring.sub


local p = {}
local function ucfirst(s)
return upper(sub(s, 1, 1)) .. sub(s, 2)
end
 
function p.format(frame)
local gpar = frame.args -- global
 
local fname = ucfirst(trim(gpar[1] or ''))
if fname == '' then return '' end -- if file name is "unspecified"
 
local size = trim(gpar[2] or '') -- or '0' for "unspecified"
if size:sub(-2) == 'px' then size = size:sub(1, -3) end -- discard 'px' unit if present
size = split(size, 'x') -- {width, height} or {height}
size = size[2] and size[2] or size[1] -- keep only the specified height (in px)
 
local style = trim(gpar[3] or '') -- or '-' for "unspecified"
if style == '-' then style = '' end


--
local title = trim(gpar[4] or '') -- or '' for "unspecified"
function p.gallery ( frame )
local what = split(fname, '.', true--[[plain, not regexp]]) --[[detect a filename extension]]
local args = mw.getCurrentFrame():getParent().args;
--[[if there's a non-empty part before a supported extension, with 1 to 4 characters: 'jpg', 'jpeg', 'gif', 'png', 'svg', 'webp', 'djvu', 'tif', 'tiff'...]]
local tagtab = {};
if #what > 1 and #(what[#what]) > 0 and #(what[#what]) < 5 then
local instab = {};
if title == '' then
local fmat  = args.f or args.format;
title = concat(what, '.', 1, -2):gsub('_', ' ') --[[default title from fname without this extension, underscores replaced by spaces]]
local mode  = args.m or args.mode;
end
local insv  = "";
what = 'F' -- displaying a file
local strg  = "";
if size == '' or size == '0' then
tagtab [1]   = "\n";
size = '36' -- default file size (in px)
--
end
for _, v in ipairs(args) do
elseif fname:sub(1, 2) == 'U+' or fname:sub(1, 2) == '&#' then
strg = strg .. "/"  .. v
what = 'U' -- displaying an Unicode code point instead of a file
if size == '' or size == '0' then
size = '15' -- Unicode default font-size (in px)
end
if title == '' then
title = fname--[[default title]]
end
title = trim(title
:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return 'U+' .. upper(x) .. ' ' end)
:gsub('&#([0-9A-Fa-f]+);?', function(x) return 'U+' .. upper(x) .. ' ' end))
fname = fname
:gsub('&#([0-9A-Fa-f]+);?', function(x) return '&#x' .. upper(x) .. ';' end)
:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return '&#x' .. upper(x) .. ';' end) .. '&#xFE0F;'--[[Emoji-style variation selector 16]]
end
end
strg = mw.ustring.gsub( strg, "[\n]" , "/" );
 
for _, v in ipairs(mw.text.split(strg , "/") ) do
if what == 'F' then -- displaying a file
if fmat == "2" then  
if style ~= '' then
if insv == "" then  
style = '|' .. style
insv = v;
end
else
if title ~= '' then
if v == "" then  
title = '|' .. title
v = insv;
:gsub('%[', '&#91;')
end
:gsub('%]', '&#93;')
table.insert(instab, insv .. "|"  .. v );
:gsub('%|', '&#123;')
insv = ""
end
else
table.insert(instab, v )
end
end
end
return concat{ '[[File:', fname, '|', size, 'x22px', style--[[allow linking]], title, ']]' }
for i, v in ipairs( instab ) do
else -- displaying an Unicode code point
if v == "" then
if title ~= '' then
tagtab [1] = tagtab [1] .. "\n"
title = concat{ ' title="', title:gsub('"', '&#34;'), '"' }
else
tagtab [1] = tagtab [1] .. "\n" .. v
end end
--
if    mode == 'n' then mode = 'nolines'
elseif mode == 'p' then mode = 'packed'
elseif mode == 'o' then mode = 'packed-overlay'
elseif mode == 'h' then mode = 'packed-hover'
elseif mode == 's' then mode = 'slideshow'
end
tagtab [2]  = mode;
tagtab [3]   = args.c or args.caption;
tagtab [4]   = args.p or args.perrown;
tagtab [5]   = args.w or args.widths;
tagtab [6]   = args.h or args.heights;
tagtab [7]  = args.s or args.style;
tagtab [8]  = args.a or args.attr or args.class;
tagtab [9]  = args.t or args.text;
tagtab [10]  = fmat;
if fmat == '' then
tagtab [10] = '1';
if mode == '' then
tagtab [2] = 'nolines';
end
end
end
return concat{ '<div style="display:inline-block;position:relative;font-size:', size, 'px;line-height:22px;vertical-align:middle;top:-1px', style, '"', title, '>', fname, '</div>' }
return mw.getCurrentFrame():expandTemplate{ title = "G/layout", args = tagtab };
end
end
end -- function format


return p;
return p

Latest revision as of 11:22, 2 July 2025

Module documentation[ create · purge ]
This documentation is transcluded from Module:Logoform/doc.
--  Module for: Formatting Logo
local p = {}

local concat = table.concat
local split = mw.text.split
local trim = mw.text.trim
local upper = mw.ustring.upper
local sub = mw.ustring.sub

local function ucfirst(s)
	return upper(sub(s, 1, 1)) .. sub(s, 2)
end

function p.format(frame)
	local gpar = frame.args -- global

	local fname = ucfirst(trim(gpar[1] or ''))
	if fname == '' then return '' end -- if file name is "unspecified"

	local size = trim(gpar[2] or '') -- or '0' for "unspecified"
	if size:sub(-2) == 'px' then size = size:sub(1, -3) end -- discard 'px' unit if present
	size = split(size, 'x') -- {width, height} or {height}
	size = size[2] and size[2] or size[1] -- keep only the specified height (in px)

	local style = trim(gpar[3] or '') -- or '-' for "unspecified"
	if	style == '-' then style = '' end

	local title = trim(gpar[4] or '') -- or '' for "unspecified"
	local what = split(fname, '.', true--[[plain, not regexp]]) --[[detect a filename extension]]
	--[[if there's a non-empty part before a supported extension, with 1 to 4 characters: 'jpg', 'jpeg', 'gif', 'png', 'svg', 'webp', 'djvu', 'tif', 'tiff'...]]
	if #what > 1 and #(what[#what]) > 0 and #(what[#what]) < 5 then
		if title == '' then
			title = concat(what, '.', 1, -2):gsub('_', ' ') --[[default title from fname without this extension, underscores replaced by spaces]]
		end
		what = 'F' -- displaying a file
		if size == '' or size == '0' then
			size = '36' --	default file size (in px)
		end
	elseif fname:sub(1, 2) == 'U+' or fname:sub(1, 2) == '&#' then
		what = 'U' -- displaying an Unicode code point instead of a file
		if	size == '' or size == '0' then
			size = '15' -- Unicode default font-size (in px)
		end
		if title == '' then
			title = fname--[[default title]]
		end
		title = trim(title
			:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return 'U+' .. upper(x) .. ' ' end)
			:gsub('&#([0-9A-Fa-f]+);?', function(x) return 'U+' .. upper(x) .. ' ' end))
		fname = fname
			:gsub('&#([0-9A-Fa-f]+);?', function(x) return '&#x' .. upper(x) .. ';' end)
			:gsub('U%+([0-9A-Fa-f]+) ?', function(x) return '&#x' .. upper(x) .. ';' end) .. '&#xFE0F;'--[[Emoji-style variation selector 16]]
	end

	if what == 'F' then -- displaying a file
		if style ~= '' then
			style = '|' .. style
		end
		if title ~= '' then
			title = '|' .. title
				:gsub('%[', '&#91;')
				:gsub('%]', '&#93;')
				:gsub('%|', '&#123;')
		end
		return concat{ '[[File:', fname, '|', size, 'x22px', style--[[allow linking]], title, ']]' }
	else -- displaying an Unicode code point
		if title ~= '' then
			title = concat{ ' title="', title:gsub('"', '&#34;'), '"' }
		end
		return concat{ '<div style="display:inline-block;position:relative;font-size:', size, 'px;line-height:22px;vertical-align:middle;top:-1px', style, '"', title, '>', fname, '</div>' }
	end	
end -- function format

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.