Module:T-LibraryInterview: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 68: | Line 68: | ||
-- Add preprocessor for semantic property extraction | -- Add preprocessor for semantic property extraction | ||
Blueprint.addPreprocessor(template, function(template, args) | Blueprint.addPreprocessor(template, function(template, args) | ||
-- Load TemplateHelpers module | |||
local TemplateHelpers = require('Module:TemplateHelpers') | |||
-- Extract names from wiki links for semantic properties | -- Extract names from wiki links for semantic properties | ||
if args.Interviewee and args.Interviewee ~= "" then | if args.Interviewee and args.Interviewee ~= "" then | ||
| Line 75: | Line 78: | ||
errorContext, | errorContext, | ||
"extractFromWikiLink_Interviewee", | "extractFromWikiLink_Interviewee", | ||
extractFromWikiLink, | TemplateHelpers.extractFromWikiLink, | ||
args.Interviewee, -- fallback to original value on error | args.Interviewee, -- fallback to original value on error | ||
args.Interviewee | args.Interviewee | ||
| Line 91: | Line 94: | ||
errorContext, | errorContext, | ||
"extractFromWikiLink_Interviewer", | "extractFromWikiLink_Interviewer", | ||
extractFromWikiLink, | TemplateHelpers.extractFromWikiLink, | ||
args.Interviewer, -- fallback to original value on error | args.Interviewer, -- fallback to original value on error | ||
args.Interviewer | args.Interviewer | ||
Revision as of 16:50, 21 April 2025
Documentation for this module may be created at Module:T-LibraryInterview/doc
--[[
* T-LibraryInterview.lua
* Module for rendering the Library Interview template using the Blueprint framework
*
* This module implements the Library Interview template functionality using the
* standardized Blueprint architecture, providing improved maintainability and
* integration with other ICANNWiki modules.
*
]]
local p = {}
-- ========== Required modules ==========
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
-- ========== Module-level caches ==========
-- Cache for current page ID (single value cache)
local currentPageIdCache = nil
-- ========== Helper Functions ==========
-- Get current page ID with caching (using centralized TemplateHelpers function)
local function getCurrentPageId()
-- Use the centralized function from TemplateHelpers
local TemplateHelpers = require('Module:TemplateHelpers')
return TemplateHelpers.getCurrentPageId()
end
-- Create error context for the module
local errorContext = ErrorHandling.createContext("T-LibraryInterview")
-- ========== Template Registration ==========
-- Register the template with the Blueprint
local template = Blueprint.registerTemplate('LibraryInterview')
-- Initialize the standard configuration
Blueprint.initializeConfig(template)
-- Set the table class to "library-box"
template.config.constants = template.config.constants or {}
template.config.constants.tableClass = "library-box"
-- ========== Custom Field Processors ==========
-- Add custom field processors
template.config.processors = {
-- ID processor - always use current page ID, ignoring any user input
ID = function(value, args, template)
local TemplateHelpers = require('Module:TemplateHelpers')
return tostring(TemplateHelpers.getCurrentPageId() or "")
end,
-- Date processor - uses date format from central configuration
Date = function(value, args, template)
local NormalizationDate = require('Module:NormalizationDate')
return NormalizationDate.formatDate(value)
end
}
-- ========== Preprocessors ==========
-- Add preprocessor to ensure ID field is always set
Blueprint.addPreprocessor(template, 'setPageIdField')
-- Add preprocessor for semantic property extraction
Blueprint.addPreprocessor(template, function(template, args)
-- Load TemplateHelpers module
local TemplateHelpers = require('Module:TemplateHelpers')
-- Extract names from wiki links for semantic properties
if args.Interviewee and args.Interviewee ~= "" then
-- If the value already has wiki links, extract the name
if args.Interviewee:match("%[%[.-%]%]") then
args._semanticInterviewee = ErrorHandling.protect(
errorContext,
"extractFromWikiLink_Interviewee",
TemplateHelpers.extractFromWikiLink,
args.Interviewee, -- fallback to original value on error
args.Interviewee
)
else
-- Otherwise, use the plain text value
args._semanticInterviewee = args.Interviewee
end
end
if args.Interviewer and args.Interviewer ~= "" then
-- If the value already has wiki links, extract the name
if args.Interviewer:match("%[%[.-%]%]") then
args._semanticInterviewer = ErrorHandling.protect(
errorContext,
"extractFromWikiLink_Interviewer",
TemplateHelpers.extractFromWikiLink,
args.Interviewer, -- fallback to original value on error
args.Interviewer
)
else
-- Otherwise, use the plain text value
args._semanticInterviewer = args.Interviewer
end
end
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 that delegates to the template's render method
function p.render(frame)
return ErrorHandling.protect(
errorContext,
"render",
function()
return template.render(frame)
end,
"<!-- Error rendering LibraryInterview template -->",
frame
)
end
return p