From da3c4ec33c325b89ee50dbcde4efac9469be9045 Mon Sep 17 00:00:00 2001 From: Rikard Blixt Date: Thu, 12 Sep 2024 10:51:19 +0200 Subject: [PATCH] ensure we don't tostring nils --- components/widget/widget_breakdown.lua | 6 +++--- components/widget/widget_center.lua | 6 +++--- components/widget/widget_chronology.lua | 6 +++--- components/widget/widget_highlights.lua | 6 +++--- components/widget/widget_title.lua | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/components/widget/widget_breakdown.lua b/components/widget/widget_breakdown.lua index 4d4b8874666..019ed3baff2 100644 --- a/components/widget/widget_breakdown.lua +++ b/components/widget/widget_breakdown.lua @@ -28,13 +28,13 @@ local Breakdown = Class.new( ---@param injector WidgetInjector? ---@return string? function Breakdown:make(injector) - return tostring(Breakdown:_breakdown(self.contents, self.classes, self.contentClasses)) + return Breakdown:_breakdown(self.contents, self.classes, self.contentClasses) end ---@param contents (string|number)[] ---@param classes string[] ---@param contentClasses table --can have gaps in the outer table ----@return Html? +---@return string? function Breakdown:_breakdown(contents, classes, contentClasses) if type(contents) ~= 'table' or contents == {} then return nil @@ -54,7 +54,7 @@ function Breakdown:_breakdown(contents, classes, contentClasses) div:node(infoboxCustomCell) end - return div + return tostring(div) end return Breakdown diff --git a/components/widget/widget_center.lua b/components/widget/widget_center.lua index 6247b1d5af0..42551a99ffa 100644 --- a/components/widget/widget_center.lua +++ b/components/widget/widget_center.lua @@ -27,12 +27,12 @@ local Center = Class.new( ---@param injector WidgetInjector? ---@return string? function Center:make(injector) - return tostring(Center:_create(self.content, self.classes)) + return Center:_create(self.content, self.classes) end ---@param content (string|number)[] ---@param classes string[] ----@return Html? +---@return string? function Center:_create(content, classes) if Table.isEmpty(content) then return nil @@ -47,7 +47,7 @@ function Center:_create(content, classes) centered:wikitext(item) end - return mw.html.create('div'):node(centered) + return tostring(mw.html.create('div'):node(centered)) end return Center diff --git a/components/widget/widget_chronology.lua b/components/widget/widget_chronology.lua index 0fd0e436def..e7236007fd1 100644 --- a/components/widget/widget_chronology.lua +++ b/components/widget/widget_chronology.lua @@ -25,11 +25,11 @@ local Chronology = Class.new( ---@param injector WidgetInjector? ---@return string? function Chronology:make(injector) - return tostring(Chronology:_chronology(self.links)) + return Chronology:_chronology(self.links) end ---@param links table ----@return Html? +---@return string? function Chronology:_chronology(links) if links == nil or Table.size(links) == 0 then return @@ -49,7 +49,7 @@ function Chronology:_chronology(links) next = links['next' .. index] end - return chronologyContent + return tostring(chronologyContent) end ---@param previous string|number|nil diff --git a/components/widget/widget_highlights.lua b/components/widget/widget_highlights.lua index 89dc7a51e68..152b63e2f58 100644 --- a/components/widget/widget_highlights.lua +++ b/components/widget/widget_highlights.lua @@ -25,11 +25,11 @@ local Highlights = Class.new( ---@param injector WidgetInjector? ---@return string? function Highlights:make(injector) - return tostring(Highlights:_highlights(self.list)) + return Highlights:_highlights(self.list) end ---@param list (string|number)[]? ----@return Html? +---@return string? function Highlights:_highlights(list) if list == nil or Table.size(list) == 0 then return nil @@ -44,7 +44,7 @@ function Highlights:_highlights(list) div:node(highlights) - return div + return tostring(div) end return Highlights diff --git a/components/widget/widget_title.lua b/components/widget/widget_title.lua index 048368d0acd..62b4c9320cd 100644 --- a/components/widget/widget_title.lua +++ b/components/widget/widget_title.lua @@ -24,18 +24,18 @@ local Title = Class.new( ---@param injector WidgetInjector? ---@return string? function Title:make(injector) - return tostring(Title:_create(self.content)) + return Title:_create(self.content) end ---@param infoDescription string|number|nil ----@return Html +---@return string function Title:_create(infoDescription) local header = mw.html.create('div') header :addClass('infobox-header') :addClass('wiki-backgroundcolor-light') :addClass('infobox-header-2') :wikitext(infoDescription) - return mw.html.create('div'):node(header) + return tostring(mw.html.create('div'):node(header)) end return Title