Модул:File

Извор: SI Wiki
Пређи на навигацију Пређи на претрагу

Овај модул служи за генерисање табеле са описом датотека. За документацију о коришћењу видети Шаблон:File. Овај модул такође довлачи потребне податке за рад из модула са подацима.


local p = {}

local title = mw.title.getCurrentTitle()
local data = mw.loadData('Module:File/data')

local function makeRow(html, title, content)
    html:tag('tr')
            :tag('th')
                :wikitext(title)
            :done()
            :tag('td')
                :wikitext(content)
            :done()
        :done()
end

function p.category(category, subcategory)
	if category == nil then
		return '[[Категорија:Остале датотеке]]'
	elseif subcategory == nil then
		return table.concat({'[[Категорија:', category, ']]'})
	else
		return table.concat({'[[Категорија:', category, '/', data.subcategories[subcategory], ']]'})
	end
end

function p.main(frame)
	local args = frame:getParent().args
	if title.namespace ~= 6 then
		return
	end
	local subject = mw.text.split(title.text, ' ', true)[1]
	local category = data.categories[subject]
	local html = mw.html.create('table')
		:attr('class', 'wikitable file-description')
	if args.description ~= nil then
		makeRow(html, 'Опис датотеке', args.description)
	end
	if category ~= nil then
		makeRow(html, 'Предмет', table.concat({'[[', category, ']]'}))
	end
	if args.author ~= nil then
		makeRow(html, 'Аутор', args.author)
	end
	makeRow(html, 'Лиценца', args.license and data.licenses[args.license] or data.licenses.default)
	if args.source ~= nil then
		makeRow(html, 'Извор', args.source)
	end
	if args.notes ~= nil then
		makeRow(html, 'Напомене', args.notes)
	end
	return tostring(html) .. p.category(category, args.type)
end

return p