Module:StyleUtils
From Against the Storm Official Wiki
Documentation for this module may be created at Module:StyleUtils/doc
--- --- Provides common shortcuts to css classes, markup, and other needed --- MediaWiki things. --- ---@module StyleUtils local StyleUtils = {} local DEBUG_INLINE_STYLE_BEFORE_CSS = true --region Public constants -- Lazy load template calls so we aren't expanding templates until they're needed StyleUtils.IMG_S = function() return mw.getCurrentFrame():expandTemplate{ title = "ImgS" } end StyleUtils.IMG_M = function() return mw.getCurrentFrame():expandTemplate{ title = "ImgM" } end StyleUtils.IMG_L = function() return mw.getCurrentFrame():expandTemplate{ title = "ImgL" } end StyleUtils.IMG_H = function() return mw.getCurrentFrame():expandTemplate{ title = "ImgH" } end StyleUtils.STARS = { [0] = function() return mw.getCurrentFrame():expandTemplate{ title = "0Star" } end, [1] = function() return mw.getCurrentFrame():expandTemplate{ title = "1Star" } end, [2] = function() return mw.getCurrentFrame():expandTemplate{ title = "2Star" } end, [3] = function() return mw.getCurrentFrame():expandTemplate{ title = "3Star" } end } StyleUtils.PAREN_STARS = { [0] = function() return mw.getCurrentFrame():expandTemplate{ title = "P0Star" } end, [1] = function() return mw.getCurrentFrame():expandTemplate{ title = "P1Star" } end, [2] = function() return mw.getCurrentFrame():expandTemplate{ title = "P2Star" } end, [3] = function() return mw.getCurrentFrame():expandTemplate{ title = "P3Star" } end } StyleUtils.RESOURCE_LINK = function(name, size) return mw.getCurrentFrame():expandTemplate{ title = "rl", args= { resource=name, iconsize = size } } end StyleUtils.CLASS_WIKITABLE_SORTABLE_COLLAPSIBLE = "wikitable sortable mw-collapsible ats-wikitable" StyleUtils.BR = "<br />" StyleUtils.NBSP = " " StyleUtils.BOLD = "'''" StyleUtils.ITALIC = "'" StyleUtils.CLASS_INFOBOX = "ats-infobox" StyleUtils.CLASS_INFOBOX_BORDER = "ats-infobox-border" StyleUtils.CLASS_INFOBOX_HEADER = "ats-infobox-header" StyleUtils.CLASS_INFOBOX_HEADER_BORDER = "ats-infobox-header-border" StyleUtils.CLASS_INFOBOX_HEADER_TITLE = "ats-infobox-header-title" StyleUtils.CLASS_INFOBOX_HEADER_ICON_BORDER = "ats-infobox-header-icon-border" StyleUtils.CLASS_INFOBOX_INNER = "ats-infobox-innerinfo" StyleUtils.CLASS_INFOBOX_INNER_BORDER = "ats-infobox-innerinfo-border" StyleUtils.CLASS_INFOBOX_INNER_NEXT_SECTION = "ats-infobox-separator" StyleUtils.CLASS_FLAVORTEXT = "ats-flavor-text" --endregion --region Public methods --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfobox(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then htmlNode:css("clear:right;border-collapse:collapse;margin:0.5em 0 0.5em 1em;float:right;border-spacing:3px;border:1px solid #a2a9b1;width:256px;") end htmlNode:addClass(StyleUtils.CLASS_INFOBOX) htmlNode:addClass(StyleUtils.CLASS_INFOBOX_BORDER) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxHeader(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then -- no op end htmlNode:addClass(StyleUtils.CLASS_INFOBOX_HEADER) htmlNode:addClass(StyleUtils.CLASS_INFOBOX_HEADER_BORDER) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxTitle(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then -- no op end htmlNode:addClass(StyleUtils.CLASS_INFOBOX_HEADER_TITLE) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxFlavorText(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then -- no op end htmlNode:addClass(StyleUtils.CLASS_FLAVORTEXT) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxTitleIcon(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then htmlNode:css("width:256px; height: 256px;") end htmlNode:addClass(StyleUtils.CLASS_INFOBOX_HEADER_ICON_BORDER) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxInnerTable(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then htmlNode:css("border-collapse:collapse;") end htmlNode:addClass(StyleUtils.CLASS_INFOBOX_INNER) htmlNode:addClass(StyleUtils.CLASS_INFOBOX_INNER_BORDER) return htmlNode end --- --- Adds css-related classes to the provided html node. ---@param htmlNode table mw.html object that we're styling ---@return table the same htmlNode function StyleUtils.styleInfoboxSeparator(htmlNode) if DEBUG_INLINE_STYLE_BEFORE_CSS then htmlNode:css("border-top:1px solid #a2a9b1;") end htmlNode:addClass(StyleUtils.CLASS_INFOBOX_INNER_NEXT_SECTION) return htmlNode end --endregion return StyleUtils