Module:Utilities: Difference between revisions
From devsummit
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
s = frame.args[1] | s = frame.args[1] | ||
if ( #s < 100 ) then | if ( #s < 100 ) then | ||
return | return s | ||
else | else | ||
return | return string.sub( s, 1, 200 ) .. '...' | ||
end | end | ||
end | end |
Latest revision as of 18:53, 13 November 2017
Documentation for this module may be created at Module:Utilities/doc
local p = {}
function p.truncate(frame)
s = frame.args[1]
if ( #s < 100 ) then
return s
else
return string.sub( s, 1, 200 ) .. '...'
end
end
function p.process_param(param)
s = mw.text.trim( param )
s = string.gsub( s, '%s*,%s*', ',' )
s = string.gsub( s, ',+', ',' )
if ( string.match( s, ',$' ) ) then
s = string.sub( s, 1, #s - 1 )
end
if ( string.find( s, ',' ) == 1 ) then
length = 0 - #s + 1
s = string.sub( s, length )
end
if #s == 0 then
return ''
end
return mw.text.split( s, ",", true )
end
function p.parseMultiple(frame)
items = p.process_param(frame.args[1])
table.sort( items, lowercompare )
links = {}
for k,v in pairs(items) do
links[k] = frame:expandTemplate{ title = frame.args[2], args = { v } }
end
return table.concat( links, frame.args[3] );
end
function lowercompare(a,b)
return string.lower(a) < string.lower(b)
end
return p