Jump to content

Module:Format TemplateData and Module:Format TemplateData/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
m Fixed error
 
Synced; some simplifications
 
Line 82: Line 82:
newlines = "*",
newlines = "*",
spaced = "inline" },
spaced = "inline" },
colors = { tableheadbg = "B3B7FF",
colors = { bg = "FFFFFF",
fg = "000000",
tableheadbg = "B3B7FF",
required = "EAF3FF",
required = "EAF3FF",
suggested = "FFFFFF",
suggested = "FFFFFF",
Line 145: Line 147:
-- ask -- string, with name
-- ask -- string, with name
-- "/global"
-- "/global"
-- "JSONutil"
-- "Multilingual"
-- "Multilingual"
-- "Text"
-- "Text"
Line 651: Line 654:
if n > 0 then
if n > 0 then
local s
local s
-- The following could be made more efficient by iterating through Data.heirs *backwards*,
-- and breaking as soon as a match is found
for k, v in pairs( Data.heirs ) do
for k, v in pairs( Data.heirs ) do
if v then
if v then
if s then
if s then
s = string.format( "%s | %s", s, k )
s = string.format( "%s | %s", s, k )
else
else
s = "Circular inherits: " .. k
s = "Circular inherits: " .. k
Line 681: Line 686:
Permit.boole = { [false] = { css = boole,
Permit.boole = { [false] = { css = boole,
lead = true,
lead = true,
show = "" },
show = "☐" },
[true] = { css = boole,
[true] = { css = boole,
lead = true,
lead = true,
show = "" } }
show = "☑" } }
Permit.css = { }
Permit.css = { }
for k, v in pairs( Permit.colors ) do
for k, v in pairs( Permit.colors ) do
Line 1,590: Line 1,595:
if r:find( "&", 1, true ) then
if r:find( "&", 1, true ) then
r = mw.text.decode( r )
r = mw.text.decode( r )
if r:find( "­", 1, true ) then
if r:find( "­", 1, true ) then
r = r:gsub( "­", "" )
r = r:gsub( "­", "" )
end
end
end
end
Line 1,699: Line 1,704:
elseif scope:find( "nowiki", 1, true ) then
elseif scope:find( "nowiki", 1, true ) then
elem = mw.text.nowiki( v )
elem = mw.text.nowiki( v )
elem = elem:gsub( "\n", "<br>" )
elem = elem:gsub( "&#13;\n", "<br>" )
v = v:gsub( string.char( 13 ), "" )
v = v:gsub( string.char( 13 ), "" )
else
else
Line 1,713: Line 1,718:
end
end
end
end
elseif k == "params" and not access then
v = nil
elem = nil
elseif k == "format" and not access then
elem = mw.text.decode( v )
v = nil
elseif k == "inherits" then
elem = v
if not Data.heirs then
Data.heirs = { }
end
Data.heirs[ slot ] = v
v = nil
elseif k == "style" then
elem = v
v = nil
elseif s == "string" then
v = mw.text.nowiki( v )
elem = v
else
else
if k == "params" and not access then
elem = v
v = nil
elem = nil
elseif k == "format" and not access then
elem = mw.text.decode( v )
v = nil
elseif k == "inherits" then
elem = v
if not Data.heirs then
Data.heirs = { }
end
Data.heirs[ slot ] = v
v = nil
elseif k == "style" then
elem = v
v = nil
elseif s == "string" then
v = mw.text.nowiki( v )
elem = v
else
elem = v
end
end
end
if type( elem ) ~= "nil" then
if type( elem ) ~= "nil" then
Line 1,753: Line 1,756:
elem = false
elem = false
end
end
if type( v ) ~= "nil" then
if v ~= nil then
if not tag then
if not tag then
if access then
if access then
Line 1,771: Line 1,774:
end
end
end
end
if type( v ) ~= "nil" and
if v ~= nil and
k ~= "suggestedvalues" then
k ~= "suggestedvalues" then
tag[ k ] = v
tag[ k ] = v
Line 1,810: Line 1,813:
code = source:gsub( "\n", "N" )
code = source:gsub( "\n", "N" )
else
else
s = mw.text.nowiki( source ):gsub( "\n", "\n" )
s = mw.text.nowiki( source ):gsub( "\n", "&#92;n" )
s = tostring( mw.html.create( "code" )
s = tostring( mw.html.create( "code" )
:wikitext( s ) )
:wikitext( s ) )
Line 1,831: Line 1,834:
Permit.builder.align then
Permit.builder.align then
Permit.builder.align = tonumber( s )
Permit.builder.align = tonumber( s )
elseif unknown then
unknown = string.format( "%s %s", unknown, s )
else
else
if unknown then
unknown = s
unknown = string.format( "%s %s", unknown, s )
else
unknown = s
end
end
end
end -- i = 1, #words
end -- i = 1, #words
Line 1,950: Line 1,951:
if code then
if code then
source = code:gsub( "N", "\n" )
source = code:gsub( "N", "\n" )
code = mw.text.nowiki( code ):gsub( "N", "\n" )
code = mw.text.nowiki( code ):gsub( "N", "&#92;n" )
code = mw.html.create( "code" )
code = mw.html.create( "code" )
:css( "margin-left", "1em" )
:css( "margin-left", "1em" )
Line 2,084: Line 2,085:
end
end
focus()
focus()
if Data.tag then
if Data.tag and type( Data.got.params ) == "table" then
if type( Data.got.params ) == "table" then
for k, v in pairs( Data.got.params ) do
for k, v in pairs( Data.got.params ) do
focus( k )
focus( k )
end -- for k, v
end -- for k, v
if Data.heirs then
if Data.heirs then
fathers()
fathers()
end
end
end
end
end
Line 2,291: Line 2,290:
-- Returns string, or not
-- Returns string, or not
if type( adapt ) == "string" then
if type( adapt ) == "string" then
local JSONutil = Fetch( "JSONutil", true )
Data.source = adapt
Data.source = adapt
free()
free()
local lucky
if JSONutil then
lucky, Data.got = pcall( mw.text.jsonDecode, Data.source )
local Multilingual = Fetch( "Multilingual", true )
local f
if Multilingual then
f = Multilingual.i18n
end
Data.got = JSONutil.fetch( Data.source, true, f )
else
local lucky
lucky, Data.got = pcall( mw.text.jsonDecode, Data.source )
end
if type( Data.got ) == "table" then
if type( Data.got ) == "table" then
full()
full()