Vorlagenprogrammierung | Diskussionen | Lua | Test | Unterseiten | |||
Modul | Deutsch | English
|
Modul: | Dokumentation |
Diese Seite enthält Code in der Programmiersprache Lua. Einbindungszahl Cirrus
--[=[ 2017-10-01
Module:Text test
]=]
local Handler = { }
local Text = { }
local QuoteLang = false
local QuoteType = false
local function fault( a )
-- Formatiere Fehler mit class=error
-- Parameter:
-- a -- string mit Text
return string.format( "<span class=\"error\">%s</span>", a )
end -- fault()
Handler.quoteTable = function ( args, frame )
local longer = ( args.QuoteType == "1" )
local order = { }
local r = Text.test( "quote" )
local strip = [==[
|-
| <code>%%s</code>
| {{#language:%%s|%s}}
|class="hintergrundfarbe8"| <code>{{#invoke:Text|quoteUnquoted|1|%%s|1}}</code>
|class="hintergrundfarbe8"| <code>{{#invoke:Text|quoteUnquoted|2|%%s|2}}</code>
]==]
local s, slang, slot, v1, v2
QuoteLang = r.QuoteLang
QuoteType = r.QuoteType
r = [==[
{| class="wikitable sortable"
|-
! lang !! Name !! 1 !! 2
]==]
if not frame then
frame = mw.getCurrentFrame()
end
if longer then
r = r .. "! code\n"
strip = strip .. "| <code>%%s</code>\n"
end
slang = frame:preprocess( "{{int:lang}}" )
strip = string.format( strip, slang )
for k, v in pairs( QuoteLang ) do
table.insert( order, k )
end -- for k, v in QuoteLang
table.sort( order )
for k, v in pairs( order ) do
slot = QuoteLang[ v ]
if type( slot ) == "string" then
v1, v2 = v:match( "^(%l+)%-(%l+)$" )
if v1 then
if #v2 == 2 then
v2 = v2:upper()
else
v2 = v2:sub( 1, 1 ):upper() .. v2:sub( 2 )
end
s = string.format( "%s-%s", v1, v2 )
else
s = v
end
if longer then
s = string.format( strip, s, v, v, v, slot )
else
s = string.format( strip, s, v, v, v )
end
r = r .. frame:preprocess( s )
else
r = r .. "\n|-\n!" .. tostring( k )
end
end -- for k, v in order
r = r .. "\n|}"
if longer then
r = r .. [==[
{| class="wikitable sortable"
! code !!colspan="3"| 1 !!colspan="3"| 2
]==]
for k, v in pairs( QuoteType ) do
if type( v ) == "table" then
v1 = v[ 1 ]
v2 = v[ 2 ]
if type( v1 ) == "table" then
s = string.format( "%s1%s||%d||%d",
mw.ustring.char( v1[ 1 ] ),
mw.ustring.char( v1[ 2 ] ),
v1[ 1 ],
v1[ 2 ] )
else
s = "???"
end
s = s .. "||"
if type( v2 ) == "table" then
s = string.format( "%s%s2%s||%d||%d",
s,
mw.ustring.char( v2[ 1 ] ),
mw.ustring.char( v2[ 2 ] ),
v2[ 1 ],
v2[ 2 ] )
else
s = s .. "???"
end
else
s = "??????????"
end
r = string.format( "%s\n|-\n|<code>%s</code>||%s", r, k, s )
end -- for k, v in QuoteType
r = r .. "\n|}"
end
return r
end -- Handler.quoteTable()
-- Export
local p = { }
function p.test( frame )
local lucky, r
lucky, Text = pcall( require, "Module:Text" )
if type( Text ) == "table" then
local suite
if type( frame ) == "string" then
suite = frame
else
suite = frame.args[ 1 ]
end
Text = Text.Text()
if type( Handler[ suite ] ) == "function" then
r = Handler[ suite ]( frame.args, frame )
else
r = fault( "Unkown Handler: " .. suite )
end
else
r = fault( Text )
end
return r
end -- p.test()
return p