Technik Wiki
Advertisement

Das Modul Datei stellt die Funktionen funktion und json zur Verfügung. Die Funktion datei stellt eine Hilfsfunktion dar, die von den beiden anderen Funktionen aufgerufen wird.

Mit diesem Modul wird die Darstellung der Dateien mit ihren Rahmen ermöglicht. Die Formatierung als solches wird durch das aufgerufene Modul Datei/Formatierung durchgeführt.

Aufruf

Die Parameter des Aufrufers werden automatisch übergeben. Das sind:

für {{#invoke:Datei|funktion}} siehe Vorlage:Funktion

für {{#invoke:Datei|json}} siehe Vorlage:JSON-Datei


Zur Liste aller Vorlagen und Module

Zur Moduldokumentation


local p = {}
function p.datei( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local extension = args.extension or ''
	if ( args.link or '' ) ~= '' then
		local link = args.link
		local line = args.line or ''
		local text = args.text
		local up = args.up or ''
		if line ~= '' then
			if up ~= '' then
				text = text or ( 'Z' .. line )
			else
				text = text or ( 'Zeile ' .. line )
			end
			link = link .. '-Line' .. line
		else
			text = text or link
		end
		
		if up ~= '' then
			return '<sup>[[#' .. link .. '|[' .. text .. ']]]</sup>'
		else
			return '[[#' .. link .. '|' .. text .. ']]'
		end
	else
		local content = mw.text.trim(args[1] or '<strong class="error">Inhalt oder <code>1=</code> fehlt!</strong>')
		local name = args.name or 'file'
		local icon = '[[Datei:' .. ( args.icon or 'Editor Icon.png' ) .. '|32px|link=#' .. name .. ']] '
		if args.icon == 'none' then
			icon = ''
		end
		
		local lines = {}
		for k, line in ipairs(mw.text.split( content, ' *\n' )) do
			local span = mw.html.create('span')
				:addClass('cmdreflink')
				:attr('id',name .. '-Line' .. k)
				:wikitext(line)
			lines[#lines + 1] = '\n ' .. tostring(span)
		end
		
		local maxlines = 'maxlines-999'
		if #lines < 10 then
			maxlines = 'maxlines-9'
		elseif #lines < 100 then
			maxlines = 'maxlines-99'
		end
		
		local div = mw.html.create('div')
			:addClass('mcfile')
			:addClass(maxlines)
			:attr('id',name)
			:wikitext('\n' .. f:expandTemplate{ title = 'Ausklappmenü', args = { icon .. '<code>' .. name .. extension .. '</code>', table.concat( lines, '' ), offen = args.offen or '1' } })
		
		return div
	end
end

function p.funktion( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local Formatierung = require('Modul:Datei/Formatierung')
	
	local content = mw.text.trim(args[1] or '<strong class="error">Befehle oder <code>1=</code> fehlt!</strong>')
	
	local lines = {}
	for line in mw.text.gsplit( content, ' *\n *' ) do
		
		line = Formatierung.befehl(line)
		
		lines[#lines + 1] = '\n' .. tostring(line)
	end
	
	return p.datei{ table.concat( lines, '' ), name = args.name or 'function', link = args.link, line = args.line, text = args.text, up = args.up, icon = 'Editor Icon.png', extension = '.mcfunction', offen = '1' }
end

function p.json( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	
	local Formatierung = require('Modul:Datei/Formatierung')
	
	local content = mw.text.trim(args[1] or '<strong class="error">Inhalt oder <code>1=</code> fehlt!</strong>')
	
	local type = args.type or ''
	local lines = {}
	for line in mw.text.gsplit( content, ' *\n' ) do
		
		line = Formatierung.json(line, type)
		
		lines[#lines + 1] = '\n' .. tostring(line)
	end
	
	return p.datei{ table.concat( lines, '' ), name = args.name, link = args.link, line = args.line, text = args.text, up = args.up, icon = 'JSON Icon.png', extension = '.json', offen = '1' }
end

return p
Advertisement