Skip to content

Commit

Permalink
ensure we don't tostring nils
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Sep 12, 2024
1 parent fecd7a4 commit da3c4ec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions components/widget/widget_breakdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<integer, string[]> --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
Expand All @@ -54,7 +54,7 @@ function Breakdown:_breakdown(contents, classes, contentClasses)
div:node(infoboxCustomCell)
end

return div
return tostring(div)
end

return Breakdown
6 changes: 3 additions & 3 deletions components/widget/widget_center.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions components/widget/widget_chronology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|number|nil>
---@return Html?
---@return string?
function Chronology:_chronology(links)
if links == nil or Table.size(links) == 0 then
return
Expand All @@ -49,7 +49,7 @@ function Chronology:_chronology(links)
next = links['next' .. index]
end

return chronologyContent
return tostring(chronologyContent)
end

---@param previous string|number|nil
Expand Down
6 changes: 3 additions & 3 deletions components/widget/widget_highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@ function Highlights:_highlights(list)

div:node(highlights)

return div
return tostring(div)
end

return Highlights
6 changes: 3 additions & 3 deletions components/widget/widget_title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da3c4ec

Please sign in to comment.