Technik Wiki
Registrieren
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 11: Zeile 11:
 
local text = args.text
 
local text = args.text
 
if line ~= '' then
 
if line ~= '' then
text = text or ( 'Zeile ' .. line )
+
text = text or ( '<sup>[Zeile ' .. line .. ']</sup>' )
 
link = link .. '.mcfunction-Line' .. line
 
link = link .. '.mcfunction-Line' .. line
 
else
 
else

Version vom 7. September 2018, 09:10 Uhr

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.funktion( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = f:getParent().args
	end
	
	if ( args.link or '' ) ~= '' then
		local link = args.link or 'function'
		local line = args.line or ''
		local text = args.text
		if line ~= '' then
			text = text or ( '<sup>[Zeile ' .. line .. ']</sup>' )
			link = link .. '.mcfunction-Line' .. line
		else
			text = text or link
			link = link .. '.mcfunction'
		end
		
		return '[[#' .. link .. '|' .. text .. ']]'
	else
		local commands = mw.text.trim(args[1] or '<strong class="error">Befehle oder <code>1=</code> fehlt!</strong>')
		local name = ( args.name or 'function' ) .. '.mcfunction'
		
		local lines = {}
		for k, line in ipairs(mw.text.split( commands, ' *\n *' )) do
			local span = mw.html.create('span')
			:addClass('cmdreflink')
			:attr('id',name .. '-Line' .. k)
			
			if string.find( line, '^%#' ) then
				span:css({ color = 'grey' })
			else
				line = line:gsub( 'function ([%l%d/%._%-:]+)', 'function [[#%1.mcfunction|%1]]')
				line = line:gsub( '^(%l+)', '[[:de:Befehl/%1|%1]]')
				line = line:gsub( 'run (%l+)', 'run [[:de:Befehl/%1|%1]]')
			end
			span:wikitext(line)
			lines[#lines + 1] = '\n ' .. tostring(span)
		end
		
		local div = mw.html.create('div')
		:addClass('mcfunction')
		:attr('id',name)
		:wikitext('\n' .. f:expandTemplate{ title = 'Ausklappmenü', args = { '[[Datei:Editor Icon.png|32px|link=#' .. name .. ']] <code>' .. name .. '</code>', table.concat( lines, '' ), offen = 1, } })
		
		return div
	end
end
return p