본문으로 이동

모듈:Deck: 두 판 사이의 차이

Kawa
잔글편집 요약 없음
잔글편집 요약 없음
 
(같은 사용자의 중간 판 19개는 보이지 않습니다)
2번째 줄: 2번째 줄:


function p.render(f)
function p.render(f)
    local args = f:getParent().args
local args = f:getParent().args
    if args['items'] == nil then
if args['items'] == nil then
        args = f.args
args = f.args
    end
end


return args['items'] or 'GONE?!'
local lines = (args['items'] or ''):gmatch("([^\n]+)")
local items = {}


-- local lines = mw.text.gsplit(args['items'] or '', '\n')
for line in lines do
-- local items = {}
line = mw.text.trim(line)


-- for line in lines do
if line ~= '' then
-- line = mw.text.trim(line)
local key, value = line:match('^([%w%s]+)=(.+)$')
if key and value then
key = mw.text.trim(key):lower()
value = mw.text.trim(value)
if key ~= '' then
items[#items][key] = value
end
else
table.insert(items, {
url = line
})
end
end
end


-- if line == '' then
-- HTML
-- table.insert(items, {})
local decks = {''}
-- else
-- local key, value = line:gmatch('([^=]+)=([^=]+)')
-- if key and value then
-- key = mw.text.trim(key):lower()
-- value = mw.text.trim(value)
-- if key ~= '' then
-- items[#items][key] = value
-- end
-- end
-- end
-- end


-- -- HTML
for _, item in ipairs(items) do
-- local nav = mw.html.create('nav')
local url = item.url or '#'
-- :addClass('kawa-deck-grid')
if url:match('^-+$') then
decks[#decks + 1] = ''
else
local icon = item.icon or ''
local title = mw.text.trim(item.title or '')


-- for _, item in ipairs(items) do
local wikitext = '<span>' .. icon .. '</span>' .. '<span>' .. title .. '</span>'
-- local url = item.url or '#'
-- local icon = item.icon or '🔗'
-- local title = mw.text.trim(item.title or '')
-- if title == '' then
-- title = url:match("^%a+://([^/:]+)") or url
-- end


-- local anchor = mw.html.create('a')
decks[#decks] = decks[#decks] .. '[' .. url .. ' ' .. wikitext .. ']'
-- :addClass('kawa-deck-item')
end
end


-- anchor:attr('href', url)
local html = ''
-- if url:match('^(https?:)?//') then
for _, deck in ipairs(decks) do
-- anchor:attr('target', '_blank')
html = html .. '<div class="kawa-deck">' .. deck .. '</div>'
-- anchor:attr('rel', 'noopener noreferrer')
end
-- end


-- local iconSpan = mw.html.create('span')
return f:preprocess(html)
-- :addClass('kawa-deck-icon')
-- :attr('aria-hidden', 'true')
 
-- if icon:match('^(https?:)?//') then
-- iconSpan:tag('img'):attr('src', icon):attr('alt', '')
-- else
-- iconSpan:wikitext(icon)
-- end
 
-- local titleSpan = mw.html.create('span')
-- :addClass('kawa-deck-title')
-- :wikitext(title)
-- local contentSpan = mw.html.create('span')
-- :addClass('kawa-deck-content')
-- contentSpan:node(titleSpan)
-- anchor:node(iconSpan)
-- anchor:node(contentSpan)
-- nav:node(anchor)
-- end
 
--    return tostring(nav)
end
end


return p
return p

2026년 5월 27일 (수) 10:34 기준 최신판

이 모듈에 대한 설명문서는 모듈:Deck/설명문서에서 만들 수 있습니다

local p = {}

function p.render(f)
	local args = f:getParent().args
	if args['items'] == nil then
		args = f.args
	end

	local lines = (args['items'] or ''):gmatch("([^\n]+)")
	local items = {}

	for line in lines do
		line = mw.text.trim(line)

		if line ~= '' then
			local key, value = line:match('^([%w%s]+)=(.+)$')
			if key and value then
				key = mw.text.trim(key):lower()
				value = mw.text.trim(value)
				if key ~= '' then
					items[#items][key] = value
				end
			else
				table.insert(items, {
					url = line
				})
			end
		end
	end

	-- HTML
	local decks = {''}

	for _, item in ipairs(items) do
		local url = item.url or '#'
		if url:match('^-+$') then
			decks[#decks + 1] = ''
		else
			local icon = item.icon or ''
			local title = mw.text.trim(item.title or '')

			local wikitext = '<span>' .. icon .. '</span>' .. '<span>' .. title .. '</span>'

			decks[#decks] = decks[#decks] .. '[' .. url .. ' ' .. wikitext .. ']'
		end
	end

	local html = ''
	for _, deck in ipairs(decks) do
		html = html .. '<div class="kawa-deck">' .. deck .. '</div>'
	end

	return f:preprocess(html)
end

return p