Module:Sort list: Difference between revisions
Appearance
Content deleted Content added
add optional delimiter |
|||
Line 2: | Line 2: | ||
function p.asc(frame) |
function p.asc(frame) |
||
items = splitLine( frame.args[1] ); |
|||
items = splitLine( frame.args[1], delimiter ); |
|||
table.sort( items ); |
table.sort( items ); |
||
return table.concat( items, |
return table.concat( items, "\n" ); |
||
end |
end |
||
function p.desc(frame) |
function p.desc(frame) |
||
items = splitLine( frame.args[1] ); |
|||
items = splitLine( frame.args[1], delimiter ); |
|||
table.sort( items, revComp ); |
table.sort( items, revComp ); |
||
return table.concat( items, |
return table.concat( items, "\n" ); |
||
end |
end |
||
function splitLine( text |
function splitLine( text ) |
||
return mw.text.split( text, |
return mw.text.split( text, "\n", true ); |
||
end |
end |
||
Revision as of 23:05, 11 April 2016
A sorting module, intended to be used with {{sort list}}.
See also
local p = {}
function p.asc(frame)
items = splitLine( frame.args[1] );
table.sort( items );
return table.concat( items, "\n" );
end
function p.desc(frame)
items = splitLine( frame.args[1] );
table.sort( items, revComp );
return table.concat( items, "\n" );
end
function splitLine( text )
return mw.text.split( text, "\n", true );
end
function revComp( a, b )
return a > b;
end
return p