Module:Sandbox: Difference between revisionsGive feedback
Jump to navigation
Jump to search
test |
test |
||
| Line 1: | Line 1: | ||
local | local function process_template(text, itemName) | ||
local | -- This pattern matches {s:SomePropertyName} in the text | ||
return text:gsub("{s:([^}]+)}", function(property) | |||
-- Construct the template call using the itemName parameter | |||
local template = "{{#invoke:ItemData|get_prop|" .. itemName .. "|" .. property .. "}}" | |||
return template | |||
end) | |||
end | |||
function p.process_item_string(frame) | |||
function p. | local args = frame.args | ||
local | local parentArgs = frame:getParent().args | ||
if not | |||
return "Error: | -- Get parameters - either from direct invocation or from parent frame | ||
local stringKey = args[1] or parentArgs[1] | |||
local itemName = args.item or parentArgs.item | |||
if not stringKey or not itemName then | |||
return "Error: Missing required parameters. Usage: {{#invoke:ItemStringProcessor|process_item_string|string_key|item=item_name}}" | |||
end | end | ||
-- First get the base string from the Lang module | |||
local langModule = require("Module:Lang") | |||
-- | local baseString = langModule.get_string(frame, stringKey) | ||
if not baseString then | |||
return "Error: String key '" .. stringKey .. "' not found" | |||
end | end | ||
-- Process the string to replace property placeholders | |||
local processedString = process_template(baseString, itemName) | |||
return processedString | |||
end | end | ||
Revision as of 20:43, 11 April 2025
Documentation for this module may be created at Module:Sandbox/doc
local function process_template(text, itemName)
-- This pattern matches {s:SomePropertyName} in the text
return text:gsub("{s:([^}]+)}", function(property)
-- Construct the template call using the itemName parameter
local template = "{{#invoke:ItemData|get_prop|" .. itemName .. "|" .. property .. "}}"
return template
end)
end
function p.process_item_string(frame)
local args = frame.args
local parentArgs = frame:getParent().args
-- Get parameters - either from direct invocation or from parent frame
local stringKey = args[1] or parentArgs[1]
local itemName = args.item or parentArgs.item
if not stringKey or not itemName then
return "Error: Missing required parameters. Usage: {{#invoke:ItemStringProcessor|process_item_string|string_key|item=item_name}}"
end
-- First get the base string from the Lang module
local langModule = require("Module:Lang")
local baseString = langModule.get_string(frame, stringKey)
if not baseString then
return "Error: String key '" .. stringKey .. "' not found"
end
-- Process the string to replace property placeholders
local processedString = process_template(baseString, itemName)
return processedString
end