Jackmcbarn has uploaded a new change for review.
https://gerrit.wikimedia.org/r/178244
Change subject: Simplify code in mw.html
......................................................................
Simplify code in mw.html
Replace numeric loops with iteration, don't unnecessarily check for nil
before table.insert (since it's a no-op in that case anyway), and similar
restructuring.
Change-Id: I155839a648f242a1b1de35f4081d8bcfa34f6933
---
M engines/LuaCommon/lualib/mw.html.lua
1 file changed, 13 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto
refs/changes/44/178244/1
diff --git a/engines/LuaCommon/lualib/mw.html.lua
b/engines/LuaCommon/lualib/mw.html.lua
index c143266..7411de5 100644
--- a/engines/LuaCommon/lualib/mw.html.lua
+++ b/engines/LuaCommon/lualib/mw.html.lua
@@ -195,18 +195,16 @@
-- Appends some markup to the node. This will be treated as wikitext.
methodtable.wikitext = function( t, ... )
- local vals = {...}
- for i = 1, #vals do
- checkTypeMulti( 'wikitext', i, vals[i], { 'string', 'number' } )
- appendBuilder( t, vals[i] )
+ for k,v in ipairs{...} do
+ checkTypeMulti( 'wikitext', k, v, { 'string', 'number' } )
+ appendBuilder( t, v )
end
return t
end
-- Appends a newline character to the node.
methodtable.newline = function( t )
- t:wikitext( '\n' )
- return t
+ return t:wikitext( '\n' )
end
-- Appends a new child node to the builder, and returns an HtmlBuilder instance
@@ -232,10 +230,7 @@
checkType( 'getAttr', 1, name, 'string' )
local attr = getAttr( t, name )
- if attr then
- return attr.val
- end
- return nil
+ return attr and attr.val
end
-- Set an HTML attribute on the node.
@@ -307,17 +302,14 @@
methodtable.addClass = function( t, class )
checkTypeMulti( 'addClass', 1, class, { 'string', 'number', 'nil' } )
- if class == nil then
- return t
+ if class ~= nil then
+ local attr = getAttr( t, 'class' )
+ if attr then
+ attr.val = attr.val .. ' ' .. class
+ else
+ t:attr( 'class', class )
+ end
end
-
- local attr = getAttr( t, 'class' )
- if attr then
- attr.val = attr.val .. ' ' .. class
- else
- t:attr( 'class', class )
- end
-
return t
end
@@ -379,9 +371,7 @@
-- @param css
methodtable.cssText = function( t, css )
checkTypeMulti( 'cssText', 1, css, { 'string', 'number', 'nil' } )
- if css ~= nil then
- table.insert( t.styles, css )
- end
+ table.insert( t.styles, css )
return t
end
--
To view, visit https://gerrit.wikimedia.org/r/178244
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I155839a648f242a1b1de35f4081d8bcfa34f6933
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits