Skip to content

Commit

Permalink
fully fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 14, 2024
1 parent 3130184 commit d16b54a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions components/widget/infobox/widget_infobox_links.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ local Links = Class.new(Widget)

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

---@return Widget?
function Links:render()
local linkInputs = Table.copy(self.props.links or {})
if Table.isEmpty(self.props.links) then
return nil
end
local linkInputs = Table.copy(self.props.links)

local links = {}

Expand Down Expand Up @@ -53,7 +57,7 @@ function Links:render()

return HtmlWidgets.Div{children = HtmlWidgets.Div{
classes = {'infobox-center', 'infobox-icons'},
children = table.concat(links, ' ' )
children = Array.interleave(links, ' ')
}}
end

Expand Down
6 changes: 6 additions & 0 deletions spec/array_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,10 @@ describe('array', function()
assert.are_same(a, Array.parseCommaSeparatedString('test1 - test2-test3', '-'))
end)
end)

describe('Interleave', function ()
it('works', function()
assert.are_same({'a', ' ', 'b', ' ', 'c'}, Array.interleave({'a', 'b', 'c'}, ' '))
end)
end)
end)
16 changes: 16 additions & 0 deletions standard/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,20 @@ function Array.parseCommaSeparatedString(inputString, sep)
return Array.map(mw.text.split(inputString, sep or ','), String.trim)
end

---Interleaves an array with elements
---Array.interleave({4, 5, 4, 3}, 1) -- {4, 1, 5, 1, 4, 1, 3}
---@generic V, T
---@param elements V[]
---@param x T
---@return (V|T)[]
function Array.interleave(elements, x)
local size = #elements
return Array.flatMap(elements, function(element, index)
if index == size then
return {element}
end
return {element, x}
end)
end

return Array

0 comments on commit d16b54a

Please sign in to comment.