Difference between revisions of "Module:Ruler"

From The Kingkiller Chronicle Wiki
Jump to navigation Jump to search
(Try to unlink {{{ruler}}})
(Credit to https://yugipedia.com/wiki/User:Becasita)
Line 1: Line 1:
 
-- <nowiki>
 
-- <nowiki>
 
local p = {}
 
local p = {}
 +
 +
local function unlink( v )
 +
    return mw.text.trim( v:match( '%[%[:?(.-)[|%]]' ) or v )
 +
end
  
 
function p.ruler(frame)
 
function p.ruler(frame)
Line 8: Line 12:
 
         v = mw.text.trim(v)
 
         v = mw.text.trim(v)
 
         if v ~= '' then
 
         if v ~= '' then
             result = result .. '[[Category:Locations ruled by ' .. v .. ']]'
+
             result = result .. '[[Category:Locations ruled by ' .. unlink( v ) .. ']]'
 
         end
 
         end
 
     end
 
     end
 
     return result
 
     return result
end
 
 
function p.unlink( frame )
 
    local args = frame:getParent().args
 
    return args[1] and ( args[1]:match( '%[%[:?(.-)[|%]]' ) or text.trim( args[1] ) )
 
 
end
 
end
  
 
return p
 
return p
 
-- </nowiki>
 
-- </nowiki>

Revision as of 00:28, 16 December 2018

Documentation for this module may be created at Module:Ruler/doc

-- <nowiki>
local p = {}

local function unlink( v )
    return mw.text.trim( v:match( '%[%[:?(.-)[|%]]' ) or v )
end

function p.ruler(frame)
    local lines = mw.text.split(frame.args[1], '*')
    local result = ''
    for k, v in ipairs(lines) do
        v = mw.text.trim(v)
        if v ~= '' then
            result = result .. '[[Category:Locations ruled by ' .. unlink( v ) .. ']]'
        end
    end
    return result
end

return p
-- </nowiki>