Difference between pages "Module:TemplateBox" and "Module:TemplateBox/sandbox"

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
m (1 revision imported)
 
m (1 revision imported)
 
Line 196: Line 196:
 
         extract = function(item, renderCell, monolingual)
 
         extract = function(item, renderCell, monolingual)
 
             local alias, param = '', item.key
 
             local alias, param = '', item.key
             local aliasTT = '<span style="font-family: monospace; color:#777; border:1px solid #6A6A6A">'
+
             local aliasTT = '<tt style="color:#777; border:1px solid #6A6A6A">'
  
 
             param = '<code>' .. param .. '</code>'
 
             param = '<code>' .. param .. '</code>'
 
             if item.aliases then
 
             if item.aliases then
                 alias = aliasTT .. table.concat(item.aliases, '</span><br />' .. aliasTT) .. '</span>'
+
                 alias = aliasTT .. table.concat(item.aliases, '</tt><br />' .. aliasTT) .. '</tt>'
 
                 param = table.concat({param, '<br /><div>', alias, '</div>'})
 
                 param = table.concat({param, '<br /><div>', alias, '</div>'})
 
             end
 
             end
Line 304: Line 304:
 
     local maxArgLen, eachArg = 0
 
     local maxArgLen, eachArg = 0
 
     sep = sep .. sepStart
 
     sep = sep .. sepStart
   
+
 
 
     local sparseIpairs = require('Module:TableTools').sparseIpairs
 
     local sparseIpairs = require('Module:TableTools').sparseIpairs
 
     local comapareLegacyVal = function(val)
 
     local comapareLegacyVal = function(val)
Line 317: Line 317:
 
         return true
 
         return true
 
     end
 
     end
   
+
 
 
     eachArg = function(cb)
 
     eachArg = function(cb)
 
         for i, arg in sparseIpairs( pargs ) do
 
         for i, arg in sparseIpairs( pargs ) do
Line 332: Line 332:
 
         end
 
         end
 
     end
 
     end
   
+
 
 
     if align then
 
     if align then
 
         eachArg(function( arg )
 
         eachArg(function( arg )
Line 392: Line 392:
 
     local i18nTemplateArgs = {}
 
     local i18nTemplateArgs = {}
 
     -- Ensure that tables end up as array/object (esp. when they are empty)
 
     -- Ensure that tables end up as array/object (esp. when they are empty)
     local tdata = {description="", params={}, sets={}}
+
     local tdata = {description="", params={}, paramOrder={}, sets={}}
     local isObject = { __tostring = function() return "JSON object" end }   isObject.__index = isObject
+
     local isObject = { __tostring = function() return "JSON object(1)" end } isObject.__index = isObject
 
     local isArray  = { __tostring = function() return "JSON array"  end }    isArray.__index  = isArray
 
     local isArray  = { __tostring = function() return "JSON array"  end }    isArray.__index  = isArray
 
     setmetatable(tdata.params, isObject)
 
     setmetatable(tdata.params, isObject)
Line 423: Line 423:
 
             else
 
             else
 
                 tdata.params[paramKey] = paramTable
 
                 tdata.params[paramKey] = paramTable
 +
                table.insert(tdata.paramOrder, paramKey)
 
             end
 
             end
 
         end
 
         end
Line 561: Line 562:
 
         end
 
         end
 
     end
 
     end
 +
    -- Ensure that `templateArgs` contains indicies in ascending order
 +
    table.sort( templateArgs )
 
     -- Then, start building the actual template
 
     -- Then, start building the actual template
 
     if processDesc then
 
     if processDesc then
Line 566: Line 569:
 
     end
 
     end
 
     if processParams then
 
     if processParams then
        -- Ensure that `templateArgs` contains indicies in ascending order
 
        table.sort( templateArgs )
 
 
         for i, number in pairs( templateArgs ) do
 
         for i, number in pairs( templateArgs ) do
 
             extractData( paraminfoTLParams, number )
 
             extractData( paraminfoTLParams, number )
Line 674: Line 675:
 
     local useTemplateData = pargs.useTemplateData
 
     local useTemplateData = pargs.useTemplateData
  
     if  (formatting == 'pretty' and useTemplateData ~= 'export') or
+
     if  (formatting == 'pretty' and useTemplateData ~= 'export' and useTemplateData ~= 'debug') or
 
         (not useTemplateData) or
 
         (not useTemplateData) or
 
         (useTemplateData == 'export' and formatting ~= 'pretty') then
 
         (useTemplateData == 'export' and formatting ~= 'pretty') then
Line 684: Line 685:
 
      
 
      
 
     -- Load the JSON-Module which will convert LUA tables into valid JSON
 
     -- Load the JSON-Module which will convert LUA tables into valid JSON
     local JSON = require('Module:JSON')
+
     local JSON = require('Module:JSON/sandbox')
 
     JSON.strictTypes = true
 
     JSON.strictTypes = true
 
     -- Obtain the object containing info
 
     -- Obtain the object containing info
 
     tdata = p.args2table(pargs, nil, 'templatedata')
 
     tdata = p.args2table(pargs, nil, 'templatedata')
 +
    -- Store parameters in the order they were given, even if explicit paramOrder
 +
    -- is not requested. JSON key order has no impact in theory, but it does
 +
    -- have in the TemplateData params object...
 +
    local etc = {
 +
        orders = { tdata.paramOrder }
 +
    }
 +
    -- And drop the paramOrder key from TemplateData unless requested
 +
    if not pargs.useTemplateDataParamOrder then
 +
        tdata.paramOrder = nil
 +
    end
 
     -- And finally return the result
 
     -- And finally return the result
 
     if formatting == 'pretty' then
 
     if formatting == 'pretty' then
         return JSON:encode_pretty(tdata)
+
         return JSON:encode_pretty(tdata, etc)
 
     else
 
     else
         return JSON:encode(tdata)
+
         return JSON:encode(tdata, etc)
 
     end
 
     end
 
end
 
end
  
 
return p
 
return p