Skip to content

Commit

Permalink
revert fun header, use logic instead of DU
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Sep 6, 2024
1 parent 3bb87cf commit 8784ab0
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions components/infobox/commons/infobox_widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_breakdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions components/infobox/commons/infobox_widget_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_cell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_center.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_chronology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions components/infobox/commons/infobox_widget_customizable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions components/infobox/commons/infobox_widget_title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions components/widget/widget_table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions components/widget/widget_table_cell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions components/widget/widget_table_cell_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions components/widget/widget_table_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions components/widget/widget_table_row.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions components/widget/widget_table_row_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ 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))

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}
Expand Down

0 comments on commit 8784ab0

Please sign in to comment.