diff --git a/components/infobox/commons/infobox.lua b/components/infobox/commons/infobox.lua index 95bfe45fc15..7b22fb4e424 100644 --- a/components/infobox/commons/infobox.lua +++ b/components/infobox/commons/infobox.lua @@ -9,12 +9,9 @@ local Array = require('Module:Array') local Class = require('Module:Class') local Logic = require('Module:Logic') -local Lua = require('Module:Lua') local Variables = require('Module:Variables') local WarningBox = require('Module:WarningBox') -local WidgetFactory = Lua.import('Module:Widget/Factory') - ---@class Infobox ---@field frame Frame? ---@field root Html? @@ -86,7 +83,7 @@ function Infobox:build(widgets) error('Infobox:build can only accept Widgets') end - self.content:node(WidgetFactory.work(widget, self.injector)) + self.content:node(widget:tryMake(self.injector)) end self.root:node(self.content) diff --git a/components/prize_pool/commons/prize_pool_base.lua b/components/prize_pool/commons/prize_pool_base.lua index 27719bc159a..5156ade16d4 100644 --- a/components/prize_pool/commons/prize_pool_base.lua +++ b/components/prize_pool/commons/prize_pool_base.lua @@ -27,7 +27,6 @@ local Opponent = OpponentLibraries.Opponent local OpponentDisplay = OpponentLibraries.OpponentDisplay local Widgets = require('Module:Widget/All') -local WidgetFactory = Lua.import('Module:Widget/Factory') local WidgetTable = Widgets.Table local TableRow = Widgets.TableRow local TableCell = Widgets.TableCell @@ -609,7 +608,7 @@ function BasePrizePool:_buildTable(isAward) end local tableNode = mw.html.create('div'):css('overflow-x', 'auto') - tableNode:node(WidgetFactory.work(tbl, self._widgetInjector)) + tableNode:node(tbl:tryMake(self._widgetInjector)) return tableNode end diff --git a/components/squad/commons/squad.lua b/components/squad/commons/squad.lua index a52215bc08d..307322b7805 100644 --- a/components/squad/commons/squad.lua +++ b/components/squad/commons/squad.lua @@ -15,7 +15,6 @@ local String = require('Module:StringUtils') local SquadUtils = Lua.import('Module:Squad/Utils') local Widget = Lua.import('Module:Widget/All') -local WidgetFactory = Lua.import('Module:Widget/Factory') ---@class Squad ---@operator call:Squad @@ -108,7 +107,7 @@ function Squad:create() classes = {'wikitable-striped', 'roster-card'}, children = self.rows, } - return WidgetFactory.work(dataTable, self.injector) + return dataTable:tryMake(self.injector) or '' end return Squad diff --git a/components/widget/widget.lua b/components/widget/widget.lua index cc694ff91ee..7919829192b 100644 --- a/components/widget/widget.lua +++ b/components/widget/widget.lua @@ -9,11 +9,8 @@ local Array = require('Module:Array') local Class = require('Module:Class') local ErrorDisplay = require('Module:Error/Display') local Logic = require('Module:Logic') -local Lua = require('Module:Lua') local String = require('Module:StringUtils') -local WidgetFactory = Lua.import('Module:Widget/Factory') - ---@class Widget: BaseClass ---@operator call({children: Widget[]?}?): Widget ---@field children (Widget|Html|string|number)[] @@ -31,18 +28,18 @@ end ---@param injector WidgetInjector? ---@param children string[] ----@return Widget[]|string|nil +---@return string|nil function Widget:make(injector, children) error('A Widget must override the make() function!') end ---@param injector WidgetInjector? ----@return Widget[]|string|nil +---@return string|nil function Widget:tryMake(injector) local processedChildren = self:tryChildren(injector) return Logic.tryOrElseLog( function() return self:make(injector, processedChildren) end, - function(error) return {ErrorDisplay.InlineError(error)} end, + function(error) return tostring(ErrorDisplay.InlineError(error)) end, function(error) error.header = 'Error occured in widget: (caught by Widget:tryMake)' return error @@ -57,12 +54,12 @@ function Widget:tryChildren(injector) if self.makeChildren then children = self:makeChildren(injector) or {} end - return Array.flatMap(children, function(child) + return Array.map(children, function(child) if type(child) == 'table' and type(child['is_a']) == 'function' and child:is_a(Widget) then ---@cast child Widget return Logic.tryOrElseLog( - function() return WidgetFactory.work(child, injector) end, - function(error) return {ErrorDisplay.InlineError(error)} end, + function() return child:tryMake(injector) end, + function(error) return tostring(ErrorDisplay.InlineError(error)) end, function(error) error.header = 'Error occured in widget: (caught by Widget:tryChildren)' return error @@ -70,7 +67,7 @@ function Widget:tryChildren(injector) ) end ---@cast child -Widget - return {tostring(child)} + return tostring(child) end) end diff --git a/components/widget/widget_factory.lua b/components/widget/widget_factory.lua deleted file mode 100644 index bf5074b64dc..00000000000 --- a/components/widget/widget_factory.lua +++ /dev/null @@ -1,34 +0,0 @@ ---- --- @Liquipedia --- wiki=commons --- page=Module:Widget/Factory --- --- Please see https://github.com/Liquipedia/Lua-Modules to contribute --- - -local Array = require('Module:Array') -local Class = require('Module:Class') - ----@class WidgetFactory -local WidgetFactory = Class.new() - ----@param widget Widget ----@param injector WidgetInjector? ----@return string -function WidgetFactory.work(widget, injector) - local children = widget:tryMake(injector) - - if not children then - return '' - end - - if type(children) == 'string' then - return children - end - - return table.concat(Array.map(children, function(child) - return WidgetFactory.work(child, injector) - end)) -end - -return WidgetFactory