Jump to content

Module:T-LibraryInterview: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
--Module:T-LibraryInterview
--Module:T-LibraryInterview
-- Module for rendering the Library Interview template using the Blueprint framework
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Internet & Digital Governance Library" template


local p = {}
local p = {}
Line 7: 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 ==========
-- Create error context for the module
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-LibraryInterview")
local errorContext = ErrorHandling.createContext("T-LibraryInterview")


-- ========== Template Registration ==========
-- ================================================================================
-- Register the template with the Blueprint
local template = Blueprint.registerTemplate('LibraryInterview')


-- Initialize the standard configuration
-- 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. 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 template = Blueprint.registerTemplate('LibraryInterview', {
    features = {
        title = true,
        fields = true,
        semanticProperties = true,
        categories = true,
        errorReporting = true
    }
})
 
-- Blueprint default: Initialize the standard configuration
Blueprint.initializeConfig(template)
Blueprint.initializeConfig(template)


-- Get property mappings from ConfigRepository for tooltips
-- ================================================================================
local propertyMappings = ConfigRepository.templates.LibraryInterview.semantics.properties


-- The ID field is handled by the 'setPageIdField' preprocessor
-- TEMPLATE-SPECIFIC CALLS AND CODE


-- ========== Preprocessors ==========
-- ========== Preprocessors ==========
-- Add preprocessor to ensure ID field is always set
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')
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 ==========
-- Main render function that delegates to the template's render method
-- Blueprint default: Render
function p.render(frame)
function p.render(frame)
     return ErrorHandling.protect(
     return ErrorHandling.protect(
Line 85: Line 46:
             return template.render(frame)
             return template.render(frame)
         end,
         end,
         "<!-- Error rendering LibraryInterview template -->",
         ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
         frame
         frame
     )
     )

Latest revision as of 23:38, 9 May 2025

Documentation for this module may be created at Module:T-LibraryInterview/doc

--Module:T-LibraryInterview
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Internet & Digital Governance Library" template

local p = {}

-- ========== Required modules ==========
local Blueprint = require('Module:LuaTemplateBlueprint')
local ErrorHandling = require('Module:ErrorHandling')

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

-- ================================================================================

-- 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. 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 template = Blueprint.registerTemplate('LibraryInterview', {
    features = {
        title = true,
        fields = true,
        semanticProperties = true,
        categories = true,
        errorReporting = true
    }
})

-- Blueprint default: Initialize the standard configuration
Blueprint.initializeConfig(template)

-- ================================================================================

-- TEMPLATE-SPECIFIC CALLS AND CODE

-- ========== Preprocessors ==========
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')

-- ========== Main Render Function ==========
-- Blueprint default: Render
function p.render(frame)
    return ErrorHandling.protect(
        errorContext,
        "render",
        function()
            return template.render(frame)
        end,
        ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
        frame
    )
end

return p