Content deleted Content added
No edit summary |
No edit summary |
||
Line 196:
local starttitle,endtitle = ""
-- user calculator supplied date (json.usercalc)
if usercalc then
startdate = usercalc
enddate = dateOffset(startdate, json.days - 1)
else
-- Get first and last date of holiday
local numRecords = tableLength(json.items)
Line 278 ⟶ 280:
end
--[[--------------------------< isAvail >-----------------------
Given the Configuration.js and name of holiday return if data type is usercalc, jsonfile or not-found (nil)
]]
function p.isHolidayAvail(cfg, holiday)
local numRecords = tableLength(cfg.items)
for i = 1, numRecords do
if cfg.main.event.items[i].holiday == holiday then
return "usercalc", i
else▼
return "jsonfile", i
end▼
end
end
return nil
end
Line 296 ⟶ 319:
local df = nil -- date format (mdy, dmy, iso - default: iso)
local format = nil -- template display format options
local cite = nil -- leave a citation at end
track = {} -- global tracking-category table
Line 325 ⟶ 348:
end
--- Parse JSON
local
local cfg, json = nil▼
if not version.exists then▼
return inlineError("holiday", "File missing Template:" .. tname .. "/holidays/" .. holiday .. ".js", tname) .. createTracking()▼
local isAvail, it = isHolidayAvail( cfg, holiday )
▲ end
if isAvail then
▲ local json = nil
if isAvail == "jsonfile" then -- dates are contained in a JSON file
if version.isRedirect then▼
local version = mw.title.makeTitle( 'Template', tname .. '/holidays/' .. holiday .. '.js' )
json = mw.text.jsonDecode( version.redirectTarget:getContent() )▼
▲ if not version.exists then
▲ return inlineError("holiday", "File missing Template:" .. tname .. "/holidays/" .. holiday .. ".js", tname) .. createTracking()
end
▲ if version.isRedirect then
▲ json = mw.text.jsonDecode( version.redirectTarget:getContent() )
else
json = mw.text.jsonDecode( version:getContent() )
end
elseif isAvail == "usercalc" then -- dates are calculated with a user-provided calculator
else
return inlineError("holiday", 'Unknown holiday [1]' )
end
else
return inlineError("holiday", 'Unknown holiday [2]' )
▲ json = mw.text.jsonDecode( version:getContent() )
end
--- Determine df - priority to |df in template, otherwise df in datafile, otherwise default to dmy
Line 360 ⟶ 400:
else
cite = ""
▲ end
▲ if json.usercalc then
▲ json.usercalc = json.usercalc:gsub("^<nowiki>", '')
▲ json.usercalc = json.usercalc:gsub("</[ ]*nowiki>$", '')
▲ json.usercalc = json.usercalc:gsub("YYYY", date)
▲ json.usercalc = frame:preprocess(json.usercalc)
▲ else
end
Line 384 ⟶ 415:
-- Render
local rend = renderHoli( json,holiday,date,df,format,tname,cite,
if not rend then
rend = '<span style="font-size:100%" class="error citation-comment">Error in [[:Template:' .. tname .. ']]: Unknown problem. Please report on template talk page.</span>'
|