Skip to content

Commit

Permalink
fix(widget): attr's widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Oct 19, 2024
1 parent 478030c commit 6503b92
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions components/widget/html/widget_html_all.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@ local String = require('Module:StringUtils')
local Widget = Lua.import('Module:Widget')

---@param tag? string
---@param specialMapping? fun(self: WidgetHtml)
---@return WidgetHtml
local function createHtmlTag(tag)
local function createHtmlTag(tag, specialMapping)
---@class WidgetHtml: Widget
---@operator call(table): WidgetHtml
local Html = Class.new(Widget)
Html.defaultProps = {
classes = {},
css = {},
attributes = {},
tag = tag,
}

---@return Html
function Html:render()
local htmlNode = mw.html.create(tag)
if specialMapping then
specialMapping(self)
end
local htmlNode = mw.html.create(self.props.tag)

htmlNode:addClass(String.nilIfEmpty(table.concat(self.props.classes, ' ')))
htmlNode:css(self.props.css)
Expand Down Expand Up @@ -58,10 +63,12 @@ local function createHtmlTag(tag)
return Html
end

Widgets.Abbr = createHtmlTag('abbr')
Widgets.Abbr = createHtmlTag('abbr', function (self)
self.props.attributes.title = self.props.attributes.title or self.props.title
end)
Widgets.Center = createHtmlTag('center')
Widgets.Div = createHtmlTag('div')
Widgets.Fragment = createHtmlTag()
Widgets.Fragment = createHtmlTag(nil)
Widgets.Li = createHtmlTag('li')
Widgets.Span = createHtmlTag('span')
Widgets.Table = createHtmlTag('table')
Expand Down

0 comments on commit 6503b92

Please sign in to comment.