Module:T-LibraryInterview: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 61: | Line 61: | ||
-- Initialize the standard configuration | -- Initialize the standard configuration | ||
Blueprint.initializeConfig(template) | 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 ========== | -- ========== Custom Field Processors ========== | ||
Revision as of 06:12, 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.
*
* Key features:
* - Uses the Blueprint framework for standardized template rendering
* - Extracts person names from wiki links for semantic properties
* - Preserves wiki links in the displayed output
* - Automatically generates semantic properties based on ConfigRepository settings
* - Handles ID generation for templates without explicit IDs
*
* Integration with other modules:
* - LuaTemplateBlueprint: Provides the foundation and standardized architecture
* - ErrorHandling: All operations are protected with centralized error handling
* - ConfigRepository: Template loads configuration from this central repository
* including field definitions, semantic properties, and categories
* - TemplateHelpers: Common utilities for rendering and normalization
* - TemplateStructure: Block-based rendering engine
*
* ConfigRepository integration:
* - Field definitions come from ConfigRepository.templates.LibraryInterview.fields
* - Semantic properties come from ConfigRepository.templates.LibraryInterview.semantics
* - Categories come from ConfigRepository.templates.LibraryInterview.categories
* - Global property names like "Has person" come from ConfigRepository.semanticProperties
*
* Note on parameter handling:
* - Template parameters are extracted and normalized by the Blueprint framework
* - Parameters are accessible via args[paramName] regardless of case used in the template
]]
local p = {}
-- ========== Required modules ==========
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
-- ========== Helper Functions ==========
-- Extract page name from wiki link [[Name]] or [[Name|Text]]
local function extractFromWikiLink(value)
local name = value:match("%[%[([^%|%]]+)%]%]") or value:match("%[%[([^%|%]]+)%|.-%]%]")
return name or value
end
-- Get current page ID
local function getCurrentPageId()
local title = mw.title.getCurrentTitle()
return title and title.id
end
-- ========== 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 - use current page ID if not provided
ID = function(value, args, template)
if not value or value == "" then
return tostring(getCurrentPageId() or "")
end
return value
end,
-- Interviewer processor - use original value with wiki links for display
Interviewer = function(value, args, template)
return args._originalInterviewer or value
end,
-- Interviewee processor - use original value with wiki links for display
Interviewee = function(value, args, template)
return args._originalInterviewee or value
end
}
-- ========== Preprocessors ==========
-- Add preprocessor for wiki link extraction
Blueprint.addPreprocessor(template, function(template, args)
-- Process Interviewee field to extract wiki links
if args.Interviewee and args.Interviewee ~= "" then
-- Store the original value for display
args._originalInterviewee = args.Interviewee
-- Extract the name from wiki link for semantic processing
args.Interviewee = extractFromWikiLink(args.Interviewee)
end
-- Process Interviewer field to extract wiki links
if args.Interviewer and args.Interviewer ~= "" then
-- Store the original value for display
args._originalInterviewer = args.Interviewer
-- Extract the name from wiki link for semantic processing
args.Interviewer = extractFromWikiLink(args.Interviewer)
end
return args
end)
-- ========== Main Render Function ==========
-- Main render function that delegates to the template's render method
function p.render(frame)
return template.render(frame)
end
return p