Modul:rhyme
Roman
Dokumentasi untuk modul ini dapat dibuat di Modul:rhyme/doc
local p = {}
local langModule = require("Modul:lang")
local U = require("Modul:utilities")
-- Main function for Template:rhyme
-- args: 1 = language code, 2..20 = rhymes, s = optional comma-separated syllables
function p.main(frame)
local args = frame.args or {}
local langCode = args[1] or ""
-- Collect rhymes
local rhymes = {}
for i = 2, 20 do
local r = args[tostring(i)]
if r and r ~= "" then
table.insert(rhymes, r)
end
end
-- Parse optional syllables (comma-separated)
local syllables = {}
if args.s and args.s ~= "" then
for syll in string.gmatch(args.s, "([^,]+)") do
table.insert(syllables, syll)
end
end
-- Error: no rhymes at all
if #rhymes == 0 then
return U.errorcat("pengujungan")
end
local inlineParts, categoryLines = {}, {}
-- Generate categories and inline links
for i, rhyme in ipairs(rhymes) do
local safeRhyme = U.safeEscape(rhyme)
local baseCatName = "Pengujungan/" .. rhyme
-- Base category
local baseCat = U.langcat(langCode, baseCatName)
table.insert(categoryLines, baseCat)
-- Extra syllable-specific category
if syllables[i] and syllables[i] ~= "" then
local syllCat = U.langcat(langCode, baseCatName .. "/" .. syllables[i] .. " ucap")
table.insert(categoryLines, syllCat)
end
-- Inline always points to the base rhyme cat
local link = U.catlink(baseCat):gsub("%]%]$", "|<span class=\"IPA\">-" .. safeRhyme .. "</span>]]")
table.insert(inlineParts, link)
end
-- Build visible text
local visible = "Pengujungan: " .. table.concat(inlineParts, ", ")
-- Append categories
return visible .. "\n" .. table.concat(categoryLines, "\n")
end
return p