local p =
local patterns =
local category_types =
local function create_category(category) return ""end
local function remove_the(colony) return string.gsub(colony, "the", "")end
-- 1775 -- Province of Massachusetts Bay
-- 1770s-- Province of Massachusetts Bay
-- 18th century -- Province of Massachusetts Baylocal function get_categories(category_type, time_period, colony) colony = remove_the(colony) local categories = for _, category in ipairs(category_type.categories) do local current_category = string.gsub(category, "TIME", time_period) current_category = string.gsub(current_category, "COLONY", colony) table.insert(categories, create_category(current_category)) end local frame = mw.getCurrentFrame if category_type.category_above then if category_type.level
local function get_category_see_also-- return ""end
local function get_category_main_article(time_period, colony) local article_title = string.gsub("TIME in COLONY", "TIME", time_period) article_title = string.gsub(article_title, "COLONY", colony) local article = mw.title.makeTitle(, article_title) if article.exists then return mw.getCurrentFrame:expandTemplate end return ""end
local function get_category_explanation(category_type, time_period, colony) local frame = mw.getCurrentFrame if category_type.level
"decade" then text = string.gsub(category_type.explanation, "TIME", frame:expandTemplate) else text = string.gsub(category_type.explanation, "TIME", time_period .. " century") end
text = string.gsub(text, "COLONY", remove_the(colony)) local category_explanation = mw.getCurrentFrame:expandTemplate return category_explanationend
local function get_portals(colony) local portals = local colony_portal = mw.title.makeTitle("Portal", colony) if colony_portal.exists then table.insert(portals, 1, "colony") end
if colony
local portal = mw.getCurrentFrame:expandTemplate return portal end
-- returns time period, colony namelocal function get_time_period_and_colony_name(title, category_type) return mw.ustring.match(title, patterns[category_type])end
local function get_category_type(title) for category_type, pattern in pairs(patterns) do if mw.ustring.match(title, pattern) then return category_type end end return ""end
-- Order of operations:-- 1. Get category title parameters-- 2. Get the category type from title parameters-- 3. Get categories for category type-- 4. Replace placehodlers with actual values-- 5. Add: -- 6. Add: -- 7. Add: -- 8. Add: -- 9. Add: -- 10. Add: -- 11. Add: Categoriesfunction p.main(frame) local getArgs = require("Module:Arguments").getArgs local args = getArgs(frame) local title = args.title local category_type = get_category_type(title) if category_type
local time_period local colony if category_types[category_type].ctype < 3 then --TODO: refactor at the end time_period, colony = get_time_period_and_colony_name(title, category_type) end local action if ctype
local portals = get_portals(colony) local explanation = get_category_explanation(category_types[category_type], time_period, colony) local main_article = get_category_main_article(time_period, colony) local see_also = get_category_see_also local series_navigation = frame:expandTemplate local CatAutoTOC = frame:expandTemplate local categories = get_categories(category_types[category_type], time_period, colony) local layout = portals .. '\n' .. explanation .. '\n' .. main_article .. '\n' .. see_also ..'\n' .. series_navigation .. '\n' .. CatAutoTOC .. '\n' .. categories return layoutend
return p