Module:Format TemplateData: Difference between revisions

Jump to navigation Jump to search
m (1 revision imported)
mp>ExE Boss
(Add `TNT` parameter that forwards to the `Module:TNT.getTemplateData` function)
Line 62: Line 62:
                 required    = "boolean",
                 required    = "boolean",
                 suggested  = "boolean",
                 suggested  = "boolean",
                suggestedvalues = "table",
                 type        = "string" },
                 type        = "string" },
     root    = { description = "string table I18N",
     root    = { description = "string table I18N",
Line 91: Line 92:
-- Generic utility functions
-- Generic utility functions
--
--
local function _ne( value )
-- Is string not empty?
-- Parameter:
--    value  -- the value to test
-- Return:
--    boolean -- whether `value` is truthy and not the empty string
return value and value ~= ''
end -- _ne


local function Fault( alert )
local function Fault( alert )
Line 547: Line 557:
         desc:node( s )
         desc:node( s )
     end
     end
     if param.default or param.example or param.autovalue then
     if param.suggestedvalues or param.default or param.example or param.autovalue then
         local details = { "default", "example", "autovalue" }
         local details = { "suggestedvalues", "default", "example", "autovalue" }
         local dl      = mw.html.create( "dl" )
         local dl      = mw.html.create( "dl" )
         local dd, section, show
         local dd, section, show, sv
         for i = 1, #details do
         for i = 1, #details do
             s    = details[ i ]
             s    = details[ i ]
Line 558: Line 568:
                 dt      = mw.html.create( "dt" ):wikitext( section )
                 dt      = mw.html.create( "dt" ):wikitext( section )
                 dd      = mw.html.create( "dd" )
                 dd      = mw.html.create( "dd" )
                 if (string.len(show) < 80) then
                 if type( show ) == "string" and (string.len(show) < 80) then
                 dt:cssText("float: left;margin-right: 1.6em;")
                 dt:cssText("float: left;margin-right: 1.6em;")
                 end
                 end
                 if param.type == "boolean" then
                 if param.type == "boolean" then
                if show == "0" then
                    if (type( show ) == "table") then
                    dd:wikitext("<span style=\"color: #610; font-weight: bold;\">False</span> (<code>0</code>)")
                        -- "suggestedvalues"
                        for i = 1, #show do
                            sv = show[ i ]
                            if i > 1 then
                                dd:wikitext("&#10;")
                            end
                            if sv == "0" then
                                dd:wikitext("<span style=\"color: #610; font-weight: bold;\">False</span> (<code>0</code>)")
                            elseif sv == "1" then
                                dd:wikitext("<span style=\"color: #050; font-weight: bold;\">True</span> (<code>1</code>)")
                            else
                                dd:tag("code"):wikitext( sv )
                            end
                        end
                    elseif show == "0" then
                        dd:wikitext("<span style=\"color: #610; font-weight: bold;\">False</span> (<code>0</code>)")
                     elseif show == "1" then
                     elseif show == "1" then
                    dd:wikitext("<span style=\"color: #050; font-weight: bold;\">True</span> (<code>1</code>)")
                        dd:wikitext("<span style=\"color: #050; font-weight: bold;\">True</span> (<code>1</code>)")
                     else
                     else
                    dd:wikitext( show )
                        dd:wikitext( show )
                    end
                elseif type( show ) == "table" then
                    -- "suggestedvalues"
                    for i = 1, #show do
                        sv = show[ i ]
                        if i > 1 then
                            dd:wikitext("&#10;")
                        end
                        dd:tag("code"):wikitext( sv )
                     end
                     end
                 else
                 else
                dd:wikitext( show )
                    dd:wikitext( show )
                 end
                 end
                 dl:node( dt )
                 dl:node( dt )
Line 584: Line 618:
         typed = mw.html.create( "td" )
         typed = mw.html.create( "td" )
         if s then
         if s then
             if s == "string" then
             if type( s ) == "string" then
                 Data.params[ access ].type = s
                 Data.params[ access ].type = s
                 typed:wikitext( getLocalizedText( "doc-param-type-" .. s ) )
                 typed:wikitext( getLocalizedText( "doc-param-type-" .. s ) )
Line 1,051: Line 1,085:
     if arglist.JSON then
     if arglist.JSON then
         source = arglist.JSON
         source = arglist.JSON
elseif _ne(arglist.TNT) then
local tnt = require("Module:TNT")
source = tnt.getTemplateData("Templatedata/"
.. mw.text.trim(arglist.TNT))
     elseif arglist[ 1 ] then
     elseif arglist[ 1 ] then
         local s    = mw.text.trim( arglist[ 1 ] )
         local s    = mw.text.trim( arglist[ 1 ] )