Module:CraftingRecipe

From Azmarin Wiki
Revision as of 10:36, 24 June 2025 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

function p.show(frame)
    local ingredients = frame.args['ingredients']
    local products = frame.args['products']

    local ingredientList = mw.text.split(ingredients, ',')
    local productList = mw.text.split(products, ',')

    local result = '{| class="wikitable"\n'

    -- Ingredients Header
    result = result .. '! colspan="2" style="text-align:center;" | Ingredients\n'
    result = result .. '|-\n! Item !! Amount\n'

    -- Ingredients Rows
    for _, item in ipairs(ingredientList) do
        local parts = mw.text.split(item, ':')
        result = result .. '|-\n| ' .. parts[1] .. ' || ' .. parts[2] .. '\n'
    end

    -- Products Header
    result = result .. '|-\n! colspan="2" style="text-align:center;" | Products\n'
    result = result .. '|-\n! Item !! Amount\n'

    -- Products Rows
    for _, product in ipairs(productList) do
        local parts = mw.text.split(product, ':')
        result = result .. '|-\n| ' .. parts[1] .. ' || ' .. parts[2] .. '\n'
    end

    result = result .. '|}'

    return result
end

return p