From 8784ab04d80e6153ccc4482c89492d56771dde97 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Fri, 6 Sep 2024 13:15:46 +0200 Subject: [PATCH] revert fun header, use logic instead of DU --- components/infobox/commons/infobox_widget.lua | 10 +++++----- .../infobox/commons/infobox_widget_breakdown.lua | 4 ++-- components/infobox/commons/infobox_widget_builder.lua | 6 +++--- components/infobox/commons/infobox_widget_cell.lua | 4 ++-- components/infobox/commons/infobox_widget_center.lua | 4 ++-- .../infobox/commons/infobox_widget_chronology.lua | 4 ++-- .../infobox/commons/infobox_widget_customizable.lua | 8 ++++---- components/infobox/commons/infobox_widget_header.lua | 4 ++-- .../infobox/commons/infobox_widget_highlights.lua | 4 ++-- components/infobox/commons/infobox_widget_links.lua | 4 ++-- components/infobox/commons/infobox_widget_title.lua | 4 ++-- components/widget/widget_table.lua | 6 +++--- components/widget/widget_table_cell.lua | 4 ++-- components/widget/widget_table_cell_new.lua | 4 ++-- components/widget/widget_table_new.lua | 6 +++--- components/widget/widget_table_row.lua | 6 +++--- components/widget/widget_table_row_new.lua | 6 +++--- 17 files changed, 44 insertions(+), 44 deletions(-) diff --git a/components/infobox/commons/infobox_widget.lua b/components/infobox/commons/infobox_widget.lua index 016f2491667..47922360f04 100644 --- a/components/infobox/commons/infobox_widget.lua +++ b/components/infobox/commons/infobox_widget.lua @@ -6,9 +6,8 @@ -- Please see https://github.com/Liquipedia/Lua-Modules to contribute -- local Class = require('Module:Class') -local DisplayUtil = require('Module:DisplayUtil') local ErrorDisplay = require('Module:Error/Display') -local FnUtil = require('Module:FnUtil') +local Logic = require('Module:Logic') local String = require('Module:StringUtils') ---@class Widget: BaseClass @@ -22,16 +21,17 @@ function Widget:assertExistsAndCopy(value) return assert(String.nilIfEmpty(value), 'Tried to set a nil value to a mandatory property') end ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return Widget[]|Html[]|nil -function Widget:make(props) +function Widget:make(injector) error('A Widget must override the make() function!') end ---@param injector WidgetInjector? ---@return Widget[]|Html[]|nil function Widget:tryMake(injector) - return DisplayUtil.TryPureComponent(FnUtil.curry(self.make, self), {injector = injector}, ErrorDisplay.InlineError) + local f = function() return self:make(injector) end + return Logic.tryOrElseLog(f, ErrorDisplay.InlineError) end return Widget diff --git a/components/infobox/commons/infobox_widget_breakdown.lua b/components/infobox/commons/infobox_widget_breakdown.lua index 060a4370166..91d8cbf87b8 100644 --- a/components/infobox/commons/infobox_widget_breakdown.lua +++ b/components/infobox/commons/infobox_widget_breakdown.lua @@ -25,9 +25,9 @@ local Breakdown = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html?} -function Breakdown:make(props) +function Breakdown:make(injector) return {Breakdown:_breakdown(self.contents, self.classes, self.contentClasses)} end diff --git a/components/infobox/commons/infobox_widget_builder.lua b/components/infobox/commons/infobox_widget_builder.lua index ed439de9738..ce0764f1d86 100644 --- a/components/infobox/commons/infobox_widget_builder.lua +++ b/components/infobox/commons/infobox_widget_builder.lua @@ -23,13 +23,13 @@ local Builder = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return Widget[] -function Builder:make(props) +function Builder:make(injector) local children = self.builder() local widgets = {} for _, child in ipairs(children or {}) do - Array.extendWith(widgets, WidgetFactory.work(child, props.injector)) + Array.extendWith(widgets, WidgetFactory.work(child, injector)) end return widgets end diff --git a/components/infobox/commons/infobox_widget_cell.lua b/components/infobox/commons/infobox_widget_cell.lua index f4ed0347431..fe988e2a145 100644 --- a/components/infobox/commons/infobox_widget_cell.lua +++ b/components/infobox/commons/infobox_widget_cell.lua @@ -89,9 +89,9 @@ function Cell:_content(...) return self end ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html?} -function Cell:make(props) +function Cell:make(injector) self:_new(self.name) self:_class(unpack(self.classes or {})) self:_content(unpack(self.content)) diff --git a/components/infobox/commons/infobox_widget_center.lua b/components/infobox/commons/infobox_widget_center.lua index 5589ba53488..6c7a5b214e3 100644 --- a/components/infobox/commons/infobox_widget_center.lua +++ b/components/infobox/commons/infobox_widget_center.lua @@ -24,9 +24,9 @@ local Center = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html?} -function Center:make(props) +function Center:make(injector) return {Center:_create(self.content, self.classes)} end diff --git a/components/infobox/commons/infobox_widget_chronology.lua b/components/infobox/commons/infobox_widget_chronology.lua index 7e454d0a272..0ec3ddbb96e 100644 --- a/components/infobox/commons/infobox_widget_chronology.lua +++ b/components/infobox/commons/infobox_widget_chronology.lua @@ -22,9 +22,9 @@ local Chronology = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return Html[] -function Chronology:make(props) +function Chronology:make(injector) return Chronology:_chronology(self.links) end diff --git a/components/infobox/commons/infobox_widget_customizable.lua b/components/infobox/commons/infobox_widget_customizable.lua index faa12378b28..ec6c7f52ccf 100644 --- a/components/infobox/commons/infobox_widget_customizable.lua +++ b/components/infobox/commons/infobox_widget_customizable.lua @@ -23,13 +23,13 @@ local Customizable = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return Widget[]? -function Customizable:make(props) - if props.injector == nil then +function Customizable:make(injector) + if injector == nil then return self.children end - return props.injector:parse(self.id, self.children) + return injector:parse(self.id, self.children) end return Customizable diff --git a/components/infobox/commons/infobox_widget_header.lua b/components/infobox/commons/infobox_widget_header.lua index e33ea9b3e68..27bcb7e7d15 100644 --- a/components/infobox/commons/infobox_widget_header.lua +++ b/components/infobox/commons/infobox_widget_header.lua @@ -35,9 +35,9 @@ local Header = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return Html[] -function Header:make(props) +function Header:make(injector) local header = { Header:_name(self.name), Header:_image( diff --git a/components/infobox/commons/infobox_widget_highlights.lua b/components/infobox/commons/infobox_widget_highlights.lua index 530069e4500..1bd18311cd0 100644 --- a/components/infobox/commons/infobox_widget_highlights.lua +++ b/components/infobox/commons/infobox_widget_highlights.lua @@ -22,9 +22,9 @@ local Highlights = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html}? -function Highlights:make(props) +function Highlights:make(injector) return Highlights:_highlights(self.list) end diff --git a/components/infobox/commons/infobox_widget_links.lua b/components/infobox/commons/infobox_widget_links.lua index 0a9d6a48a94..966be46edf2 100644 --- a/components/infobox/commons/infobox_widget_links.lua +++ b/components/infobox/commons/infobox_widget_links.lua @@ -27,9 +27,9 @@ local Links = Class.new( local PRIORITY_GROUPS = Lua.import('Module:Links/PriorityGroups', {loadData = true}) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function Links:make(props) +function Links:make(injector) local infoboxLinks = mw.html.create('div') infoboxLinks :addClass('infobox-center') :addClass('infobox-icons') diff --git a/components/infobox/commons/infobox_widget_title.lua b/components/infobox/commons/infobox_widget_title.lua index 1311f2fef8d..6ba2a0ae880 100644 --- a/components/infobox/commons/infobox_widget_title.lua +++ b/components/infobox/commons/infobox_widget_title.lua @@ -21,9 +21,9 @@ local Title = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function Title:make(props) +function Title:make(injector) return {Title:_create(self.content)} end diff --git a/components/widget/widget_table.lua b/components/widget/widget_table.lua index 539b1fc9a9e..88b26cb6fb3 100644 --- a/components/widget/widget_table.lua +++ b/components/widget/widget_table.lua @@ -49,9 +49,9 @@ function Table:addClass(class) return self end ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function Table:make(props) +function Table:make(injector) local displayTable = mw.html.create('div'):addClass('csstable-widget') displayTable:css{ ['grid-template-columns'] = 'repeat(' .. (self.columns or self:_getMaxCells()) .. ', auto)', @@ -64,7 +64,7 @@ function Table:make(props) displayTable:css(self.css) for _, row in ipairs(self.rows) do - for _, node in ipairs(WidgetFactory.work(row, props.injector)) do + for _, node in ipairs(WidgetFactory.work(row, injector)) do displayTable:node(node) end end diff --git a/components/widget/widget_table_cell.lua b/components/widget/widget_table_cell.lua index 557be2e17f6..53b7838f260 100644 --- a/components/widget/widget_table_cell.lua +++ b/components/widget/widget_table_cell.lua @@ -56,9 +56,9 @@ function TableCell:addCss(key, value) return self end ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function TableCell:make(props) +function TableCell:make(injector) local cell = mw.html.create('div'):addClass('csstable-widget-cell') cell:css{ ['grid-row'] = self.rowSpan and 'span ' .. self.rowSpan or nil, diff --git a/components/widget/widget_table_cell_new.lua b/components/widget/widget_table_cell_new.lua index 7a1082832cd..7b85a2e7897 100644 --- a/components/widget/widget_table_cell_new.lua +++ b/components/widget/widget_table_cell_new.lua @@ -42,9 +42,9 @@ local TableCell = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function TableCell:make(props) +function TableCell:make(injector) local cell = mw.html.create(self.isHeader and 'th' or 'td') cell:attr('colspan', self.colSpan) cell:attr('rowspan', self.rowSpan) diff --git a/components/widget/widget_table_new.lua b/components/widget/widget_table_new.lua index d05fbc80325..3b473e06596 100644 --- a/components/widget/widget_table_new.lua +++ b/components/widget/widget_table_new.lua @@ -33,9 +33,9 @@ local Table = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function Table:make(props) +function Table:make(injector) local wrapper = mw.html.create('div'):addClass('table-responsive') local output = mw.html.create('table'):addClass('wikitable') @@ -44,7 +44,7 @@ function Table:make(props) output:css(self.css) Array.forEach(self.children, function(child) - Array.forEach(WidgetFactory.work(child, props.injector), FnUtil.curry(output.node, output)) + Array.forEach(WidgetFactory.work(child, injector), FnUtil.curry(output.node, output)) end) wrapper:node(output) diff --git a/components/widget/widget_table_row.lua b/components/widget/widget_table_row.lua index e3985cfc18c..323b2c9d2c2 100644 --- a/components/widget/widget_table_row.lua +++ b/components/widget/widget_table_row.lua @@ -58,9 +58,9 @@ function TableRow:getCellCount() return #self.cells end ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function TableRow:make(props) +function TableRow:make(injector) local row = mw.html.create('div'):addClass('csstable-widget-row') for _, class in ipairs(self.classes) do @@ -70,7 +70,7 @@ function TableRow:make(props) row:css(self.css) for _, cell in ipairs(self.cells) do - for _, node in ipairs(WidgetFactory.work(cell, props.injector)) do + for _, node in ipairs(WidgetFactory.work(cell, injector)) do row:node(node) end end diff --git a/components/widget/widget_table_row_new.lua b/components/widget/widget_table_row_new.lua index 8936c5009c0..1ab3731ceed 100644 --- a/components/widget/widget_table_row_new.lua +++ b/components/widget/widget_table_row_new.lua @@ -33,9 +33,9 @@ local TableRow = Class.new( end ) ----@param props {injector: WidgetInjector?} +---@param injector WidgetInjector? ---@return {[1]: Html} -function TableRow:make(props) +function TableRow:make(injector) local row = mw.html.create('tr') Array.forEach(self.classes, FnUtil.curry(row.addClass, row)) @@ -43,7 +43,7 @@ function TableRow:make(props) row:css(self.css) Array.forEach(self.children, function(child) - Array.forEach(WidgetFactory.work(child, props.injector), FnUtil.curry(row.node, row)) + Array.forEach(WidgetFactory.work(child, injector), FnUtil.curry(row.node, row)) end) return {row}