Module:T-Norm
Documentation for this module may be created at Module:T-Norm/doc
--Module:T-Organization
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Norm" template
local p = {}
-- ==================== Required modules ====================
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')
local LinkParser = require('Module:LinkParser')
-- ==================== Helper Functions ====================
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-Norm")
-- ================================================================================
-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS
-- CONTROL OF TEMPLATE FEATURES: THIS LIST SPECIFIES IN AN EXPLICIT MANNER WHAT FEATURES ARE TO BE CALLED/RENDERED BY THE TEMPLATE.
local template = Blueprint.registerTemplate('Norm', {
features = {
title = true,
logo = true,
fields = true,
socialMedia = true,
semanticProperties = true,
categories = true,
errorReporting = true,
}
})
-- Blueprint default: Initialize standard configuration
Blueprint.initializeConfig(template)
-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
template.config.blockSequence = {
'title',
'logo',
'fields',
'socialMedia',
'semanticProperties',
'categories',
'errors'
}
-- ================================================================================
-- TEMPLATE-SPECIFIC CALLS AND CODE
-- SPECIAL SEMANTIC MAPPINGS GO HERE
-- Add a custom field processor that will trigger an error for testing
template.processors = template.processors or {}
template.processors.testErrorField = function(value, args, template)
-- This will cause a controlled error: attempt to index a nil value
local nilTable = nil
local result = nilTable.nonExistentProperty -- This will trigger "attempt to index a nil value"
return value
end
-- ================================================================================
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField') -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry') -- Possible blueprint default
-- Test error: Add a controlled error within the rendering pipeline
Blueprint.addPreprocessor(template, function(template, args)
-- Add a test field that will cause an error during field processing
if args.name and args.name:lower():find("test") then
args.testErrorField = "trigger_error"
end
return args
end)
-- ==================== Main Render Function ====================
-- Blueprint default: Render
function p.render(frame)
return ErrorHandling.protect(
errorContext,
"render",
function()
-- Test error: Add a direct error that will be caught by our error handling
local args = frame.args or {}
if args.name and args.name:lower():find("test") then
-- This will trigger "attempt to perform arithmetic on a string value"
local errorResult = args.name + 42
end
return template.render(frame)
end,
ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
frame
)
end
return p