Module:WikiProjectBanner/AssessmentRow

MyWikiBiz, Author Your Legacy — Sunday December 22, 2024
Jump to navigationJump to search

Documentation for this module may be created at Module:WikiProjectBanner/AssessmentRow/doc

-------------------------------------------------------------------------------
--                           AssessmentRow class                             --
-- This module contains the AssessmentRow class used in                      --
-- Module:WikiProjectBanner. It is used to generate the quality row and the  --
-- importance row, and can be used to generate other kinds of assessment     --
-- rows if they are needed.                                                  --
-------------------------------------------------------------------------------
 
local Row = require('Module:WikiProjectBanner/Row')
local mShared = require('Module:WikiProjectBanner/shared')
 
local AssessmentRow = setmetatable({}, Row)
AssessmentRow.__index = AssessmentRow
 
function AssessmentRow.new(args, bannerData, cfg, rowCfg, gradeObj)
	local obj = Row.new(args, bannerData, cfg, rowCfg)
	setmetatable(obj, AssessmentRow)

	obj.grade = gradeObj
	obj.assessmentType = obj.grade.assessmentType

	local gradeData = obj.grade:exportData()
	local assessmentCfg = obj.cfg.assessment[obj.assessmentType]

	-- Icon
	do
		-- Icon style
		local style = {
			['text-align'] = 'center',
			['white-space'] = 'nowrap',
			['font-weight'] = 'bold',
			['background'] = gradeData.color
		}

		-- Icon class
		local class = assessmentCfg.classes
		if class then
			class = mShared.substituteParams(
				class,
				mw.ustring.lower(gradeData.short)
			)
		end

		-- Icon image
		local image
		if gradeData.image then
			image = string.format('[[File:%s|16px]] ', gradeData.image)
			if gradeData.hideImage then
				image = string.format(
					'<span style="display:none;">%s</span>',
					image
				)
			end
		else
			image = ''
		end

		-- Icon category link
		local link
		if gradeData.assessmentCategory then
			link = string.format(
				'[[:%s:%s|%s]]',
				mw.site.namespaces[14].name,
				gradeData.assessmentCategory,
				gradeData.short
			)
		else
			link = gradeData.short
		end

		obj:setIcon(image .. link, {class = class, style = style})
	end

	-- Text
	do
		local msg = gradeData.blurb or assessmentCfg.blurb or error(string.format(
			"no blurb found for assessment type '%s'",
			obj.assessmentType
		))
		obj:setText(mShared.substituteParams(
			msg,
			gradeData.full,
			obj.bannerData.assessmentLink,
			obj.bannerData.pageType
		))
	end

	return obj
end

return AssessmentRow