Module:User:Catonif/RQ:xum:TI

local p = {};

local year = {}; year["1"] = "early 2nd";

local lines = {}; local text = {}; local tr = {}; local t = {};

local roman = {}; roman["1"] = "I"; roman["2"] = "II"; roman["3"] = "III"; roman["4"] = "IV"; roman["5"] = "V"; roman["6"] = "VI"; roman["7"] = "VII";

local reg = "<([^:<>]+):([^:<>]+)>"; local reg_simple = "<([^:<>]+)>";

local function wrapInCollapsible(always, off, on)

return ' ' .. always .. ' ' .. off .. ' ' .. ' \n' .. on .. ' ';

end

local function formatText(here_text, isLemma, bold, indent)

local final_bold;

if (isLemma) then here_text, _ = here_text:gsub(reg, function (str, id)			id = id:gsub("%-.+", ""); local str_display = str:gsub("%[.+%]", ""); str = str:gsub("[%[%]]", "")			if (id == bold) then return "" .. str_display .. "";			else return "" .. str_display .. ""; end		end); else here_text, _ = here_text:gsub(reg, function (str, id)			local str_display = str:gsub("%[.+%]", ""); str = str:gsub("[%[%]]", "")			if (str == bold) then final_bold = id; return "" .. str_display .. "";			else return str_display; end		end) end

here_text = here_text:gsub("{", ""):gsub("}", " ") :gsub("([0-9]+a?)", "%1"):gsub("%.", "[...]")

return indent .. here_text .. "\n", final_bold;

end

local function format(here_tr, bold, it, isLemma, indent)

local function boldify (str, id) if (id == bold) then return "'''" .. str .. "'''";		elseif (isLemma) then if (id:gsub("%-.+", "") == bold) then return "'''" .. str .. "'''";			else return str; end else return str; end end

local r, _ = here_tr:gsub(reg, boldify):gsub(reg_simple, function (x) return boldify(x, x) end)

if (it) then return indent .. ":''" .. r .. "''\n"; else return indent .. ":" .. r .. "\n"; end

end

local function getEntry(table, quote, precise, isLemma, bold, trad, indent)

local r = ""; local r_;

local here_text, here_tr;

if (precise == nil) then here_text = text[quote]; here_tr = tr[quote]; else here_text = text[quote .. "/" .. precise]; here_tr = tr[quote .. "/" .. precise] end

if (here_text:match(",")) then for v in string.gmatch(here_text, "([^,]+)") do			r_, _ = getEntry(table, quote, v, isLemma, bold, false, indent); r = r .. r_; end else r_, bold = formatText(here_text, isLemma, bold, indent); r = r .. r_; if (here_tr ~= nil) then r = r .. format(here_tr, bold, true, isLemma, indent); end end

if (trad) then r = r .. format(t[quote], bold, false, isLemma, indent); else local here_t = t[quote .. "/" .. precise]; if (here_t ~= nil) then r = r .. format(here_t, bold, false, isLemma, indent); end end

return r, bold;

end

function p.quote(frame)

local number = frame.args["number"]; local face = frame.args["face"];

local table = number .. face;

local list = require("Module:User:Catonif/RQ:xum:TI/" .. table);

lines = list["lines"]; text = list["text"]; tr = list["tr"]; t = list["t"];

local here_year = year[number];

local quote = frame.args["quote"];

local precise = frame.args["precise"]; if (precise == "") then precise = nil; end

local here_lines; if (precise == nil) then here_lines = lines[quote]; else here_lines = lines[quote .. "/" .. precise]; if (here_lines == nil) then here_lines = "line " .. precise; end end

local always = "'''" .. here_year .. " century BCE ', Iguvine Tablets'', table " .. roman[number] .. ", face " .. face:upper .. " (.. roman[number .. face .. ".jpg photo]; .. table .. ".jpg facsimile), " .. here_lines;

local show = ":\n";

local bold = frame.args["bold"]; local isLemma = frame.args["lemma"] == "1";

local indent = ":";

local hide = getEntry(table, quote, precise, isLemma, bold, true, indent);

local r = wrapInCollapsible(always, show, hide);

return r;

end

return p;