Skip to content

Commit

Permalink
refactor(widget): improve building part 6 - remove injector from make…
Browse files Browse the repository at this point in the history
…() (#4743)

* refactor(widget): improve building part 6 - remove injector from make()

* update widget also

* needed for this one too
  • Loading branch information
Rathoz authored Sep 17, 2024
1 parent cbebb22 commit 6f00fa5
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 37 deletions.
5 changes: 2 additions & 3 deletions components/widget/widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ function Widget:assertExistsAndCopy(value)
return assert(String.nilIfEmpty(value), 'Tried to set a nil value to a mandatory property')
end

---@param injector WidgetInjector?
---@param children string[]
---@return string|nil
function Widget:make(injector, children)
function Widget:make(children)
error('A Widget must override the make() function!')
end

Expand All @@ -38,7 +37,7 @@ end
function Widget:tryMake(injector)
local processedChildren = self:tryChildren(injector)
return Logic.tryOrElseLog(
function() return self:make(injector, processedChildren) end,
function() return self:make(processedChildren) end,
function(error) return tostring(ErrorDisplay.InlineError(error)) end,
function(error)
error.header = 'Error occured in widget: (caught by Widget:tryMake)'
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_breakdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ local Breakdown = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Breakdown:make(injector, children)
function Breakdown:make(children)
return Breakdown:_breakdown(children, self.classes, self.contentClasses)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ local Builder = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string
function Builder:make(injector, children)
function Builder:make(children)
return table.concat(children)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_cell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ function Cell:_content(...)
return self
end

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Cell:make(injector, children)
function Cell:make(children)
self:_new(self.name)
self:_class(unpack(self.classes or {}))
self:_content(unpack(children))
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_center.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ local Center = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Center:make(injector, children)
function Center:make(children)
return Center:_create(children, self.classes)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_chronology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ local Chronology = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Chronology:make(injector, children)
function Chronology:make(children)
return Chronology:_chronology(self.links)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_customizable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ local Customizable = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string
function Customizable:make(injector, children)
function Customizable:make(children)
return table.concat(children)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_div.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ local Div = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Div:make(injector, children)
function Div:make(children)
local div = mw.html.create('div')
Array.forEach(self.classes, FnUtil.curry(div.addClass, div))
Array.forEach(children, FnUtil.curry(div.node, div))
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ local Header = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string
function Header:make(injector, children)
function Header:make(children)
local header = {
Header:_name(self.name),
Header:_image(
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ local Highlights = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Highlights:make(injector, children)
function Highlights:make(children)
return Highlights:_highlights(children)
end

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ local Links = Class.new(

local PRIORITY_GROUPS = Lua.import('Module:Links/PriorityGroups', {loadData = true})

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Links:make(injector, children)
function Links:make(children)
local infoboxLinks = mw.html.create('div')
infoboxLinks :addClass('infobox-center')
:addClass('infobox-icons')
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ function Table:addClass(class)
return self
end

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Table:make(injector, children)
function Table:make(children)
local displayTable = mw.html.create('div'):addClass('csstable-widget')
displayTable:css{
['grid-template-columns'] = 'repeat(' .. (self.columns or self:_getMaxCells()) .. ', auto)',
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table_cell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ function TableCell:addCss(key, value)
return self
end

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function TableCell:make(injector, children)
function TableCell:make(children)
local cell = mw.html.create('div'):addClass('csstable-widget-cell')
cell:css{
['grid-row'] = self.rowSpan and 'span ' .. self.rowSpan or nil,
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table_cell_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ local TableCell = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function TableCell:make(injector, children)
function TableCell:make(children)
local cell = mw.html.create(self.isHeader and 'th' or 'td')
cell:attr('colspan', self.colSpan)
cell:attr('rowspan', self.rowSpan)
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ local Table = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Table:make(injector, children)
function Table:make(children)
local wrapper = mw.html.create('div'):addClass('table-responsive')
local output = mw.html.create('table'):addClass('wikitable')

Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table_row.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ function TableRow:getCellCount()
return #self.children
end

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function TableRow:make(injector, children)
function TableRow:make(children)
local row = mw.html.create('div'):addClass('csstable-widget-row')

for _, class in ipairs(self.classes) do
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_table_row_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ local TableRow = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function TableRow:make(injector, children)
function TableRow:make(children)
local row = mw.html.create('tr')

Array.forEach(self.classes, FnUtil.curry(row.addClass, row))
Expand Down
3 changes: 1 addition & 2 deletions components/widget/widget_title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ local Title = Class.new(
end
)

---@param injector WidgetInjector?
---@param children string[]
---@return string?
function Title:make(injector, children)
function Title:make(children)
return Title:_create(children[1])
end

Expand Down

0 comments on commit 6f00fa5

Please sign in to comment.