Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 43: | Zeile 43: | ||
:addClass('cmdreflink') |
:addClass('cmdreflink') |
||
:attr('id',name .. '-Line' .. k) |
:attr('id',name .. '-Line' .. k) |
||
− | : |
+ | :wikitext(line) |
− | :addClass('linenumber') |
||
− | :attr('href','#' .. name .. '-Line' .. k) |
||
− | :wikitext(' ') |
||
− | span:wikitext(line) |
||
lines[#lines + 1] = '\n ' .. tostring(span) |
lines[#lines + 1] = '\n ' .. tostring(span) |
||
end |
end |
||
Zeile 88: | Zeile 84: | ||
end |
end |
||
− | return p.datei{ table.concat( lines, '' ), name = args.name or 'function', link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'Editor Icon.png', extension = '.mcfunction', offen = '1' } |
+ | return p.datei{ table.concat( lines, '' ), name = args.name or 'function', link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'Editor Icon.png', extension = '.mcfunction', offen = args.offen or '1' } |
end |
end |
||
Zeile 108: | Zeile 104: | ||
line = Formatierung.json(line, type) |
line = Formatierung.json(line, type) |
||
+ | |||
+ | if type == 'advancement' then |
||
+ | line = line:gsub( '"criteria":', '"<span id="' .. ( args.name or 'file' ) .. '-criteria">criteria</span>":' ) |
||
+ | end |
||
lines[#lines + 1] = '\n' .. tostring(line) |
lines[#lines + 1] = '\n' .. tostring(line) |
||
end |
end |
||
− | return p.datei{ table.concat( lines, '' ), name = args.name, link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'JSON Icon.png', extension = '.json', offen = '1' } |
+ | return p.datei{ table.concat( lines, '' ), name = args.name, link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'JSON Icon.png', extension = '.json', offen = args.offen or '1' } |
end |
end |
||
Version vom 21. Dezember 2020, 16:54 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 |
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 = f:callParserFunction( '#var_final:' .. args.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>' .. f:callParserFunction( '#vardefine:' .. ( args.alias or name ), name ), 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, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'Editor Icon.png', extension = '.mcfunction', offen = args.offen or '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)
if type == 'advancement' then
line = line:gsub( '"criteria":', '"<span id="' .. ( args.name or 'file' ) .. '-criteria">criteria</span>":' )
end
lines[#lines + 1] = '\n' .. tostring(line)
end
return p.datei{ table.concat( lines, '' ), name = args.name, link = args.link, alias = args.alias, line = args.line, text = args.text, up = args.up, icon = 'JSON Icon.png', extension = '.json', offen = args.offen or '1' }
end
return p