Module:ItemEffect: Difference between revisions

From He is Coming Official Wiki
Benjiminio (talk | contribs)
mNo edit summary
Benjiminio (talk | contribs)
mNo edit summary
Line 13: Line 13:
     local normalizedName = itemName:gsub(" ", "_")
     local normalizedName = itemName:gsub(" ", "_")


     -- Construct the full page path
     -- Construct the full page path (subpage under He_is_Coming)
     local pageName = "He_is_Coming/" .. normalizedName .. "/effect"
     local pageName = "He_is_Coming/" .. normalizedName .. "/effect"
    -- Get the page object
     local effectTitle = mw.title.new(pageName)
     local effectTitle = mw.title.new(pageName)


     -- Check if the page exists
     -- Check page exists
     if not effectTitle or not effectTitle.exists then
     if not effectTitle or not effectTitle.exists then
         return "Effect page not found: " .. pageName
         return "Effect page not found: " .. pageName
     end
     end


     -- Get page content
     -- Fetch content
     local effectContent = effectTitle:getContent() or ""
     local effectContent = effectTitle:getContent() or ""
     if effectContent == "" then
     if effectContent == "" then
Line 29: Line 31:


     -- Color each keyword using ColorText
     -- Color each keyword using ColorText
    -- Only color words that exist in ColorText's table
     effectContent = effectContent:gsub("%w+", function(word)
     effectContent = effectContent:gsub("%w+", function(word)
         local lower = word:lower()
         local lower = word:lower()
         if colorModule.colors and colorModule.colors[lower] then
         if colorModule.colors and colorModule.colors[lower] then
            -- Use the ColorText module to color this keyword
             return colorModule.main({ args = { word } })
             return colorModule.main({ args = { word } })
         else
         else

Revision as of 11:24, 14 November 2025

Documentation for this module may be created at Module:ItemEffect/doc

-- Module:ItemEffect
local p = {}

-- Require the ColorText module
local colorModule = require("Module:ColorText")

-- Main function: fetch effect content and color keywords
function p.main(frame)
    local itemName = frame.args[1] or ""
    if itemName == "" then return "" end

    -- Normalize item name: replace spaces with underscores
    local normalizedName = itemName:gsub(" ", "_")

    -- Construct the full page path (subpage under He_is_Coming)
    local pageName = "He_is_Coming/" .. normalizedName .. "/effect"

    -- Get the page object
    local effectTitle = mw.title.new(pageName)

    -- Check page exists
    if not effectTitle or not effectTitle.exists then
        return "Effect page not found: " .. pageName
    end

    -- Fetch content
    local effectContent = effectTitle:getContent() or ""
    if effectContent == "" then
        return "(No effect text)"
    end

    -- Color each keyword using ColorText
    effectContent = effectContent:gsub("%w+", function(word)
        local lower = word:lower()
        if colorModule.colors and colorModule.colors[lower] then
            -- Use the ColorText module to color this keyword
            return colorModule.main({ args = { word } })
        else
            return word
        end
    end)

    return effectContent
end

return p