<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AClass%2Fsandbox</id>
	<title>Module:Class/sandbox - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AClass%2Fsandbox"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Class/sandbox&amp;action=history"/>
	<updated>2026-04-04T10:40:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Class/sandbox&amp;diff=135672&amp;oldid=prev</id>
		<title>imported&gt;WOSlinker: move templatestyles within td tag</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Class/sandbox&amp;diff=135672&amp;oldid=prev"/>
		<updated>2022-11-19T12:41:59Z</updated>

		<summary type="html">&lt;p&gt;move templatestyles within td tag&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements [[Template:Class]], [[Template:Class/icon]] and&lt;br /&gt;
-- [[Template:Class/colour]].&lt;br /&gt;
&lt;br /&gt;
local mArguments -- lazily loaded&lt;br /&gt;
local definitions = mw.loadJsonData(&amp;#039;Module:Class/definition.json&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Local configuration and messages&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local cfg = {&lt;br /&gt;
	defaultCode = &amp;#039;DEFAULT&amp;#039;,&lt;br /&gt;
	classPrefix = &amp;#039;assess-&amp;#039;,&lt;br /&gt;
	globalClass = &amp;#039;assess&amp;#039;,&lt;br /&gt;
	defaultClassSuffix = &amp;#039;default&amp;#039;,&lt;br /&gt;
	unboldClassSuffix = &amp;#039;unbold&amp;#039;,&lt;br /&gt;
	catRootFormat = &amp;#039;%s %s&amp;#039;,&lt;br /&gt;
	catTopicFormat = &amp;#039;%s %s articles&amp;#039;,&lt;br /&gt;
	catBasicFormat = &amp;#039;%s articles&amp;#039;,&lt;br /&gt;
	categoryFormat = &amp;#039;[[:Category:%s|%s]]&amp;#039;,&lt;br /&gt;
	templateLocation = &amp;#039;Template:Class&amp;#039;,&lt;br /&gt;
	iconTemplateLocation = &amp;#039;Template:Class/icon&amp;#039;,&lt;br /&gt;
	colourTemplateLocation = &amp;#039;Template:Class/colour&amp;#039;,&lt;br /&gt;
	stylesLocation = &amp;#039;Module:Class/styles.css&amp;#039;,&lt;br /&gt;
	baseColourPath = {&amp;#039;colour&amp;#039;, &amp;#039;base&amp;#039;},&lt;br /&gt;
	iconPath = {&amp;quot;icon&amp;quot;, &amp;quot;file&amp;quot;},&lt;br /&gt;
	iconDefaultPath = {&amp;quot;icon&amp;quot;, &amp;quot;default&amp;quot;},&lt;br /&gt;
	iconAttribPath = {&amp;quot;icon&amp;quot;, &amp;quot;requiresAttribution&amp;quot;},&lt;br /&gt;
	fullLabelPath = {&amp;quot;labels&amp;quot;, &amp;quot;full&amp;quot;},&lt;br /&gt;
	shortLabelPath = {&amp;quot;labels&amp;quot;, &amp;quot;short&amp;quot;},&lt;br /&gt;
	categoryRootPath = {&amp;quot;categoryRoot&amp;quot;},&lt;br /&gt;
	tooltipPath = {&amp;quot;labels&amp;quot;, &amp;quot;tooltip&amp;quot;},&lt;br /&gt;
	yes = &amp;quot;yes&amp;quot;,&lt;br /&gt;
	no = &amp;quot;no&amp;quot;, &lt;br /&gt;
	argumentNames = {&lt;br /&gt;
		class = &amp;quot;class&amp;quot;,&lt;br /&gt;
		style = &amp;quot;style&amp;quot;&lt;br /&gt;
	},&lt;br /&gt;
	getOptions = {&lt;br /&gt;
		--First item is localized argument name, second is case-sensitivity&lt;br /&gt;
		bold = {&amp;quot;bold&amp;quot;, false},&lt;br /&gt;
		header = {&amp;quot;header&amp;quot;, false},&lt;br /&gt;
		image = {&amp;quot;image&amp;quot;, false},&lt;br /&gt;
		rowspan = {&amp;quot;rowspan&amp;quot;, false},&lt;br /&gt;
		fullcategory = {&amp;quot;fullcategory&amp;quot;, true},&lt;br /&gt;
		category = {&amp;quot;category&amp;quot;, true},&lt;br /&gt;
		topic = {&amp;quot;topic&amp;quot;, true}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Argument helper functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local function getRawArgs(frame, wrapper)&lt;br /&gt;
	--Retrieves the arguments from the frame&lt;br /&gt;
	mArguments = mArguments or require(&amp;#039;Module:Arguments&amp;#039;)&lt;br /&gt;
	return mArguments.getArgs(frame, {&lt;br /&gt;
		wrappers = wrapper,&lt;br /&gt;
		trim = false,&lt;br /&gt;
		removeBlanks = false&lt;br /&gt;
	})&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function makeInvokeFunction(func, wrapper)&lt;br /&gt;
	--Wraps a general function into an invokable version&lt;br /&gt;
	return function (frame)&lt;br /&gt;
		local args = getRawArgs(frame, wrapper)&lt;br /&gt;
		return func(args)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- String helper functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local function trim(str)&lt;br /&gt;
	--Trims strings, passes through non-strings without modification&lt;br /&gt;
	return (type(str) == &amp;#039;string&amp;#039;) and mw.text.trim(str) or str&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function normalizeValue(val)&lt;br /&gt;
	--Normalizes strings, particularly class codes&lt;br /&gt;
	if type(val) == &amp;#039;string&amp;#039; then val = trim(val):lower() end&lt;br /&gt;
	if val == &amp;#039;&amp;#039; then val = nil end&lt;br /&gt;
	return val&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function ucfirst(str)&lt;br /&gt;
	--Capitalizes the first character of a string&lt;br /&gt;
	return mw.ustring.upper(mw.ustring.sub(str, 1, 1)) .. mw.ustring.sub(str, 2)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Definition helper functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
local function getDefinition(code)&lt;br /&gt;
	--Retrieves the definition and canonical class code for a given code.&lt;br /&gt;
	--Returns two values: the definition object and the canonical class code&lt;br /&gt;
	--string.&lt;br /&gt;
	local canonicalCode = normalizeValue(code)&lt;br /&gt;
	if code == cfg.defaultCode then canonicalCode = code end&lt;br /&gt;
	local class = definitions[canonicalCode]&lt;br /&gt;
	while class and class.alias do&lt;br /&gt;
		canonicalCode = class.alias&lt;br /&gt;
		class = definitions[class.alias]&lt;br /&gt;
	end&lt;br /&gt;
	if not class then&lt;br /&gt;
		return nil, nil&lt;br /&gt;
	end&lt;br /&gt;
	return class, canonicalCode&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getDefault()&lt;br /&gt;
	--Shortcut function for retrieving the default definition&lt;br /&gt;
	return getDefinition(cfg.defaultCode) end&lt;br /&gt;
&lt;br /&gt;
local function getProperty(class, default, map)&lt;br /&gt;
	--Retrieves a given property from a string given a class definition, a&lt;br /&gt;
	--default class definition, and a map for the path to traverse through the&lt;br /&gt;
	--class object. The map should be a sequential table of string property&lt;br /&gt;
	--names, e.g. {&amp;quot;colour&amp;quot;, &amp;quot;base&amp;quot;} would retrieve someClass.colour.base&lt;br /&gt;
	local prop, dProp = class, default&lt;br /&gt;
	for k, v in ipairs(map) do&lt;br /&gt;
		prop = ((type(prop) == &amp;#039;table&amp;#039;) or nil) and prop[v]&lt;br /&gt;
		dProp = ((type(dProp) == &amp;#039;table&amp;#039;) or nil) and dProp[v]&lt;br /&gt;
	end&lt;br /&gt;
	if prop == nil then prop = dProp end&lt;br /&gt;
	return prop&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Color functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p._colour(code)&lt;br /&gt;
	--Retrieves the base colour for a given code&lt;br /&gt;
	return getProperty(getDefinition(code), getDefault(), cfg.baseColourPath)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.colour(frame)&lt;br /&gt;
	--Retrieves the base colour for a given code; is invokable&lt;br /&gt;
	local args = getRawArgs(frame, cfg.colourTemplateLocation)&lt;br /&gt;
	-- Nowiki tags prevent output beginning with &amp;quot;#&amp;quot; from triggering bug 14974.&lt;br /&gt;
	return frame:extensionTag(&amp;#039;nowiki&amp;#039;, p._colour(args[1]))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Icon functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p._icon(args)&lt;br /&gt;
	--Retrieves an icon image and formats it as wikitext&lt;br /&gt;
	local class = getDefinition(args[cfg.argumentNames.class] or args[1])&lt;br /&gt;
	local default = getDefault()&lt;br /&gt;
	local file = getProperty(class, default, cfg.iconPath)&lt;br /&gt;
	local label = &lt;br /&gt;
		getProperty(class, default, cfg.tooltipPath) or&lt;br /&gt;
		ucfirst(getProperty(class, default, cfg.fullLabelPath))&lt;br /&gt;
	local attrib = getProperty(class, default, cfg.iconAttribPath)&lt;br /&gt;
	local span = mw.html.create(&amp;#039;span&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
	span&lt;br /&gt;
		:cssText(args[cfg.argumentNames.style])&lt;br /&gt;
		:attr(&amp;#039;title&amp;#039;, label)&lt;br /&gt;
		:wikitext(&lt;br /&gt;
			string.format(&lt;br /&gt;
				&amp;#039;[[File:%s|%s|16px%s|class=noviewer|alt=]]&amp;#039;,&lt;br /&gt;
				file,&lt;br /&gt;
				label,&lt;br /&gt;
				attrib and &amp;#039;&amp;#039; or &amp;#039;|link=&amp;#039;&lt;br /&gt;
			)&lt;br /&gt;
		)&lt;br /&gt;
	return tostring(span)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.icon = makeInvokeFunction(p._icon, cfg.iconTemplateLocation)&lt;br /&gt;
--Invokable version of p._icon&lt;br /&gt;
&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
-- Class functions&lt;br /&gt;
--------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
function p._class(args)&lt;br /&gt;
	--Parses its arguments into a table cell with an optional icon, a name&lt;br /&gt;
	--linked to an appropriate category, and appropriate colour styling&lt;br /&gt;
	local classDef, classCode =&lt;br /&gt;
		getDefinition(args[cfg.argumentNames.class] or args[1])&lt;br /&gt;
	local default = getDefault()&lt;br /&gt;
	local iconDefault = getProperty(classDef, default, cfg.iconDefaultPath)&lt;br /&gt;
	local shortLabel = getProperty(classDef, default, cfg.shortLabelPath)&lt;br /&gt;
	local categoryRoot = getProperty(classDef, default, cfg.categoryRootPath)&lt;br /&gt;
	--o is short for &amp;quot;options&amp;quot;, go for &amp;quot;get options&amp;quot;. Bool true → case-sensitive&lt;br /&gt;
	local o, go = {}, cfg.getOptions&lt;br /&gt;
	for k, v in pairs(go) do&lt;br /&gt;
		o[k] = v[2] and trim(args[v[1]]) or normalizeValue(args[v[1]])&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local cell = mw.html.create(o.header and &amp;#039;th&amp;#039; or &amp;#039;td&amp;#039;)&lt;br /&gt;
	--image=yes forces icon, image=no disables it, otherwise checks default&lt;br /&gt;
	local icon = iconDefault and (o.image ~= cfg.no) or (o.image == cfg.yes)&lt;br /&gt;
	icon = icon and p.icon(args) .. &amp;#039;&amp;amp;nbsp;&amp;#039; or &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	local category&lt;br /&gt;
	if o.fullcategory then&lt;br /&gt;
		category = o.fullcategory&lt;br /&gt;
	elseif o.category then&lt;br /&gt;
		category = string.format(cfg.catRootFormat, categoryRoot, o.category)&lt;br /&gt;
	elseif o.topic then&lt;br /&gt;
		category = string.format(cfg.catTopicFormat, categoryRoot, o.topic)&lt;br /&gt;
	else&lt;br /&gt;
		category = string.format(cfg.catBasicFormat, categoryRoot)&lt;br /&gt;
	end&lt;br /&gt;
	local text = string.format(cfg.categoryFormat, category, shortLabel)&lt;br /&gt;
	cell&lt;br /&gt;
		:addClass(cfg.globalClass)&lt;br /&gt;
		:addClass(&lt;br /&gt;
			o.bold == cfg.no and cfg.classPrefix .. cfg.unboldClassSuffix or nil&lt;br /&gt;
		)&lt;br /&gt;
		:addClass(cfg.classPrefix .. (classCode or cfg.defaultClassSuffix))&lt;br /&gt;
		:attr(&amp;#039;rowspan&amp;#039;, tonumber(o.rowspan))&lt;br /&gt;
		:wikitext(mw.getCurrentFrame():extensionTag{ name = &amp;#039;templatestyles&amp;#039;, args = {src = cfg.stylesLocation} }, icon, text)&lt;br /&gt;
&lt;br /&gt;
	return tostring(cell)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
p.class = makeInvokeFunction(p._class, cfg.templateLocation)&lt;br /&gt;
--Invokable version of p._class&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;WOSlinker</name></author>
	</entry>
</feed>