FANDOM


local getArgs = require('Dev:Arguments').getArgs
 
local LinkConcat = {}
 
function LinkConcat.concatCard(frame)
    return LinkConcat._concatCard(getArgs(frame))
end
 
function LinkConcat._concatCard(args)
    local last_arg = 0
    while args[last_arg + 1] do
        last_arg = last_arg + 1
    end
    if last_arg < 1 then return nil end
 
    local span_wrapper = mw.html.create('span')
        :addClass('card-tooltip')
        :attr('data-card', args[1]:gsub('"', '&quot;'))
 
    if last_arg == 1 then
        span_wrapper:wikitext('[['..args[1]..']]')
    elseif last_arg == 2 then
        span_wrapper:wikitext('[['..args[1]..'|'..LinkConcat._parse(args[1], args[2])..']]')
    else
        local words = {}
        for w in string.gmatch(args[1], "%S+") do
           table.insert(words, w)
        end
        for i = #words, 1, -1 do
            if last_arg - #words + i > 1 then
                words[i] = LinkConcat._parse(words[i], args[last_arg - #words + i])
            end
        end
        span_wrapper:wikitext('[['..args[1]..'|'..table.concat(words, ' ')..']]')
    end
 
    return span_wrapper
end
 
function LinkConcat.concatWW(frame)
    return LinkConcat._concatWW(getArgs(frame))
end
 
function LinkConcat._concatWW(args)
    local last_arg = 0
    while args[last_arg + 1] do
        last_arg = last_arg + 1
    end
    if last_arg < 1 then return nil end
 
    local span_wrapper = mw.html.create('span')
 
    if last_arg == 1 then
        span_wrapper:wikitext('[[w:c:wiedzmin:'..args[1]..'|'..args[1]..']]')
    elseif last_arg == 2 then
        span_wrapper:wikitext('[[w:c:wiedzmin:'..args[1]..'|'..LinkConcat._parse(args[1], args[2])..']]')
    else
        local words = {}
        for w in string.gmatch(args[1], "%S+") do
           table.insert(words, w)
        end
        for i = #words, 1, -1 do
            if last_arg - #words + i > 1 then
                words[i] = LinkConcat._parse(words[i], args[last_arg - #words + i])
            end
        end
        span_wrapper:wikitext('[[w:c:wiedzmin:'..args[1]..'|'..table.concat(words, ' ')..']]')
    end
 
    return span_wrapper
end
 
function LinkConcat._parse(word, arg)
    local text = ''
    if arg == '*' then
        text = ''
    elseif arg:sub(1, 1) == '-' then
        local i = 1
        while arg:sub(i+1, i+1) == '-' do i = i + 1 end
        text = word:sub(1, #word + 1 - i)..arg:sub(i + 1)
    else
        text = arg
    end
    return text
end
 
return LinkConcat
Treści społeczności są dostępne na podstawie licencji CC-BY-SA , o ile nie zaznaczono inaczej.