Module:T-LibraryInterview: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[
--Module:T-LibraryInterview
* T-LibraryInterview.lua
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Internet & Digital Governance Library" template
* 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 = {}
local p = {}
Line 38: Line 7:
local Blueprint = require('Module:LuaTemplateBlueprint')
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')


-- ========== Helper Functions ==========
-- ========== Helper Functions ==========
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-LibraryInterview")


-- 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
-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS
local function getCurrentPageId()
-- CONTROL OF TEMPLATE FEATURES: THIS LIST SPECIFIES IN AN EXPLICIT MANNER WHAT FEATURES ARE TO BE CALLED/RENDERED BY THE TEMPLATE. EXTENSIVE TESTING WAS PERFORMED SO THAT THIS CAN BE TOGGLED AT ANY TIME WITH A TRUE/FALSE BOOLEAN CHOICE FROM THIS MODULE, AS IT CAN BE DONE IN ANY OTHER MODULE USING ICANNWIKI'S THE TEMPLATE BLUEPRINT FRAMEWORK
     local title = mw.title.getCurrentTitle()
local template = Blueprint.registerTemplate('LibraryInterview', {
     return title and title.id
     features = {
end
        title = true,
        fields = true,
        semanticProperties = true,
        categories = true,
        errorReporting = true
     }
})


-- ========== Template Registration ==========
-- Blueprint default: Initialize the standard configuration
 
-- Register the template with the Blueprint
local template = Blueprint.registerTemplate('LibraryInterview')
 
-- 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 ==========
-- TEMPLATE-SPECIFIC CALLS AND CODE
 
-- 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,
   
    -- Date processor - ensure dates are displayed with abbreviated month names
    Date = function(value, args, template)
        local NormalizationDate = require('Module:NormalizationDate')
        -- Ensure short month names are enabled
        NormalizationDate.setUseShortMonthNames(true)
        return NormalizationDate.formatDate(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 ==========
-- ========== Preprocessors ==========
 
-- Basic preprocessors
-- Add preprocessor for wiki link extraction
Blueprint.addPreprocessor(template, 'setPageIdField')
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 ==========
 
-- Blueprint default: Render
-- Main render function that delegates to the template's render method
function p.render(frame)
function p.render(frame)
     return template.render(frame)
     return ErrorHandling.protect(
        errorContext,
        "render",
        function()
            return template.render(frame)
        end,
        ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
        frame
    )
end
end


return p
return p