Module:T-LibraryInterview: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 1: | Line 1: | ||
--Module:T-LibraryInterview | --Module:T-LibraryInterview | ||
-- | -- Renders the Internet & Digital Governance Library template for Interviews, making use of ICANNWiki's "Template Blueprint" framework | ||
local p = {} | local p = {} | ||
| Line 10: | Line 10: | ||
local LinkParser = require('Module:LinkParser') | local LinkParser = require('Module:LinkParser') | ||
-- Module-level cache for lazy-loaded modules | -- Blueprint default: Module-level cache for lazy-loaded modules | ||
local moduleCache = {} | local moduleCache = {} | ||
-- Lazy module loader | -- Blueprint default: Lazy module loader | ||
local function lazyRequire(moduleName) | local function lazyRequire(moduleName) | ||
return function() | return function() | ||
| Line 22: | Line 22: | ||
end | end | ||
end | end | ||
-- ========== Helper Functions ========== | -- ========== Helper Functions ========== | ||
| Line 30: | Line 28: | ||
-- ========== Template Registration ========== | -- ========== Template Registration ========== | ||
-- Register the template with the Blueprint | -- Register the template with the Blueprint framework | ||
local template = Blueprint.registerTemplate('LibraryInterview') | local template = Blueprint.registerTemplate('LibraryInterview') | ||
| Line 39: | Line 37: | ||
local propertyMappings = ConfigRepository.templates.LibraryInterview.semantics.properties | local propertyMappings = ConfigRepository.templates.LibraryInterview.semantics.properties | ||
-- ========== Preprocessors ========== | |||
-- The ID field is handled by the 'setPageIdField' preprocessor | -- The ID field is handled by the 'setPageIdField' preprocessor | ||
Blueprint.addPreprocessor(template, 'setPageIdField') | Blueprint.addPreprocessor(template, 'setPageIdField') | ||
-- | -- Use TemplateHelpers.extractSemanticValue instead of a local implementation | ||
local TemplateHelpers = require('Module:TemplateHelpers') | |||
local function extractSemanticValue(fieldValue, fieldName) | local function extractSemanticValue(fieldValue, fieldName) | ||
return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext) | |||
end | end | ||
-- | -- Preprocessor for semantic property extraction | ||
Blueprint.addPreprocessor(template, function(template, args) | Blueprint.addPreprocessor(template, function(template, args) | ||
-- Extract names from wiki links for semantic properties | -- Extract names from wiki links for semantic properties | ||
| Line 82: | Line 63: | ||
-- ========== Main Render Function ========== | -- ========== Main Render Function ========== | ||
-- Main render function | -- Main render function which delegates to the template's render method | ||
function p.render(frame) | function p.render(frame) | ||
return ErrorHandling.protect( | return ErrorHandling.protect( | ||
| Line 90: | Line 71: | ||
return template.render(frame) | return template.render(frame) | ||
end, | end, | ||
ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR | ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"), | ||
frame | frame | ||
) | ) | ||
Revision as of 09:06, 23 April 2025
Documentation for this module may be created at Module:T-LibraryInterview/doc
--Module:T-LibraryInterview
-- Renders the Internet & Digital Governance Library template for Interviews, making use of ICANNWiki's "Template Blueprint" framework
local p = {}
-- ========== Required modules ==========
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
local LinkParser = require('Module:LinkParser')
-- Blueprint default: Module-level cache for lazy-loaded modules
local moduleCache = {}
-- Blueprint default: Lazy module loader
local function lazyRequire(moduleName)
return function()
if not moduleCache[moduleName] then
moduleCache[moduleName] = require(moduleName)
end
return moduleCache[moduleName]
end
end
-- ========== Helper Functions ==========
-- Create error context for the module
local errorContext = ErrorHandling.createContext("T-LibraryInterview")
-- ========== Template Registration ==========
-- Register the template with the Blueprint framework
local template = Blueprint.registerTemplate('LibraryInterview')
-- Initialize the standard configuration
Blueprint.initializeConfig(template)
-- Get property mappings from ConfigRepository for tooltips
local propertyMappings = ConfigRepository.templates.LibraryInterview.semantics.properties
-- ========== Preprocessors ==========
-- The ID field is handled by the 'setPageIdField' preprocessor
Blueprint.addPreprocessor(template, 'setPageIdField')
-- Use TemplateHelpers.extractSemanticValue instead of a local implementation
local TemplateHelpers = require('Module:TemplateHelpers')
local function extractSemanticValue(fieldValue, fieldName)
return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext)
end
-- Preprocessor for semantic property extraction
Blueprint.addPreprocessor(template, function(template, args)
-- Extract names from wiki links for semantic properties
args._semanticInterviewee = extractSemanticValue(args.Interviewee, "Interviewee")
args._semanticInterviewer = extractSemanticValue(args.Interviewer, "Interviewer")
return args
end)
-- Configure semantic properties to use extracted values
template.config.semantics = template.config.semantics or {}
template.config.semantics.properties = template.config.semantics.properties or {}
template.config.semantics.properties["Has interviewee"] = "_semanticInterviewee"
template.config.semantics.properties["Has interviewer"] = "_semanticInterviewer"
-- ========== Main Render Function ==========
-- Main render function which delegates to the template's render method
function p.render(frame)
return ErrorHandling.protect(
errorContext,
"render",
function()
return template.render(frame)
end,
ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
frame
)
end
return p