Modul:Boolean
Aus Star Citizen Wiki
Weitere Optionen
Diese Dokumentation wird von Modul:Boolean/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.
Rendert ein Tri-State-Boolean (wahr/falsch/nil) als ein einziges maschinenlesbares Icon: ein grüner Haken, ein graues Kreuz oder ein bernsteinfarbenes Hilfe-Glyph. Die einzige Quelle von Ja/Nein/Unbekannt-Icon, -Farbe und -Label.
Editoren nutzen dies über {{Boolean}}. Direkt von mehreren Entity-Facetten und von der Grid-Spalte boolean der AG-Grid-Welt required; das AG-Grid-Bindeglied läuft auf diesem Wiki nicht (keine AG-Grid-Extension).
Für Modul-Editoren
API
p.classify(value): rein. Liefert{ state, icon, label }für jeden Wert (nie nil; unbekannte Eingabe löst zumunknown-Status).stateist'yes','no'oder'unknown'.p.render(value): das reine Icon-Markup (das Infobox-Wikitext-Gesicht): eine farbigecurrentColor-Maske über Modul:Icon plustitle/data-state/Verborgen-Text-Hooks.p.gridClassify(value):{ text, state, icon }für den Grid-Pfad; auf diesem Wiki ohne AG-Grid ohne Verbraucher.p.main(frame): Wikitext-Einstieg hinter{{Boolean}}; das erste Positionsargument ist der Wert.
Anzeigelabels laufen über Modul:Entity/Message und fallen bei fehlender Nachricht auf das englische Wort zurück, statt jeden Aufruf zu fehlen.
Stolperfallen
- „Nein“ ist bewusst grau, nicht rot: das Fehlen einer Eigenschaft ist neutral, kein Fehler.
- Nur
classifyundgridClassifytragen Unit-Tests; das gerenderte HTML (render) verifiziert die Browser-QA, nach Projektkonvention.
require('strict')
--- @module Boolean
--- Renders a tri-state boolean (true / false / nil) as a machine-readable icon:
--- a green check, a grey cross, or an amber help glyph. The single source of
--- truth for the yes / no / unknown icon + colour + label, shared by the
--- {{Boolean}} wikitext template, the Entity infobox facets, and the AG Grid
--- `boolean` column kind. Modeled on Module:DietaryEffect.
local yesno = require('Module:Yesno')
local Icon = require('Module:Icon')
local p = {}
--- Localizes a display word through Module:Entity/Message. Resolved per call
--- and guarded: Message is a separate wiki page, and when it is missing or
--- fails to load the English word must still render, not error every {{Boolean}}
--- call and infobox facet.
--- @param s string
--- @return string
local function msg(s)
local ok, Message = pcall(require, 'Module:Entity/Message')
if ok then
return Message.msg(s)
end
return s
end
local ICON_SIZE = '16px'
--- @class BooleanState
--- @field state string 'yes' | 'no' | 'unknown'
--- @field icon string Codex SVG file name (without the File: prefix)
--- @field label string English word; render() and gridClassify() localize it for display
--- @type table<string, BooleanState>
local STATES = {
yes = { state = 'yes', icon = 'CdxIconSuccess.svg', label = 'Yes' },
no = { state = 'no', icon = 'CdxIconClear.svg', label = 'No' },
unknown = { state = 'unknown', icon = 'CdxIconHelpNotice.svg', label = 'Unknown' },
}
--- Classify a value into its state entry. Input runs through Module:Yesno, so
--- `yes`/`1`/`true` -> yes, `no`/`0`/`false` -> no; nil / unrecognised -> unknown.
--- @param value any
--- @return BooleanState
function p.classify(value)
local b = yesno(value)
if b == true then
return STATES.yes
end
if b == false then
return STATES.no
end
return STATES.unknown
end
--- Render an icon-only inline representation. The returned markup includes its
--- own and Module:Icon's <templatestyles> (MediaWiki dedupes repeated tags), so
--- a facet can drop the string straight into a row's `content`.
---
--- Machine-readable three ways: `title` (hover tooltip), `data-state` (scrapers /
--- AI agents query [data-state]), and a visually-hidden text span (screen
--- readers, translation tools, reader modes -- which ignore aria-label).
--- @param value any
--- @return string
function p.render(value)
local s = p.classify(value)
local glyph = Icon.render({ icon = s.icon, mask = true, size = ICON_SIZE })
local label = msg(s.label)
local span = mw.html
.create('span')
:addClass('t-boolean')
:addClass('t-boolean--' .. s.state)
:attr('data-state', s.state)
:attr('title', label)
:wikitext(glyph)
span:tag('span'):addClass('t-boolean__sr'):wikitext(label)
local frame = mw.getCurrentFrame()
local styles = frame:extensionTag({ name = 'templatestyles', args = { src = 'Module:Boolean/styles.css' } })
local iconStyles = frame:extensionTag({ name = 'templatestyles', args = { src = 'Module:Icon/styles.css' } })
return styles .. iconStyles .. tostring(span)
end
--- Classify a value for an AG Grid boolean cell (Module:AGGridColumns/Kind/Boolean).
--- `text` is the sort / set-filter key the gadget's scwBoolean column filters and
--- sorts on, so it stays the English word even on the German wiki: saved filter
--- selections match these words and localization would orphan them. `label` is the
--- localized display word for the cell tooltip and screen-reader text, with
--- render()'s wording and fallback; the set filter's value list stays English.
--- `icon` is a file name resolved downstream.
--- @param value any
--- @return { text: string, state: string, icon: string, label: string }
function p.gridClassify(value)
local s = p.classify(value)
return { text = s.label, state = s.state, icon = s.icon, label = msg(s.label) }
end
--- Wikitext entry point (backs {{Boolean}}). First positional arg is the value.
--- @param frame mw.frame
--- @return string
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return p.render(args[1])
end
return p


