diff options
author | Aki <please@ignore.pl> | 2023-09-12 22:32:21 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-09-12 22:32:21 +0200 |
commit | ab1cb08298363d429bc811ba2d3375a3fa647065 (patch) | |
tree | 8b501e12215d6fe4d201e426fda096478160ae12 /activity.lua | |
parent | 86e7fa2004c12db0bda8e8fd7697fd8d64b2e4b6 (diff) | |
download | activity-ab1cb08298363d429bc811ba2d3375a3fa647065.zip activity-ab1cb08298363d429bc811ba2d3375a3fa647065.tar.gz activity-ab1cb08298363d429bc811ba2d3375a3fa647065.tar.bz2 |
Extracted output format to own module for potential later expansion
Diffstat (limited to 'activity.lua')
-rw-r--r-- | activity.lua | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/activity.lua b/activity.lua index 5aefbdc..8bec2a0 100644 --- a/activity.lua +++ b/activity.lua @@ -3,7 +3,7 @@ local git = require "activity.git" local activity = {} -function activity.generate_table (year, repositories) +function activity.generate_table (year, repositories, format) year = year or dates.this_year() local lookup = git.lookup(repositories) @@ -24,30 +24,22 @@ function activity.generate_table (year, repositories) return 0 end - local function spot () - return [[<td>]] - end - - local function day (level) - return ([[<td data-activity-level="%d">]]):format(level) - end - local function cell (exists) if not exists then - return spot + return format.spot end - return day + return format.cell end local function row (weekday, index, offset, first, last) first = cell(first) last = cell(last) - local row = ([[<tr><td class="activity-chart-label"><span>%s</span>]]):format(weekday) + local row = format.start_row() .. format.label(weekday) row = row .. first(count(index, offset, 0)) for week=2,52 do - row = row .. day(count(index, offset, week)) + row = row .. format.cell(count(index, offset, week)) end - row = row .. last(count(index, offset, 53)) .. "\n" + row = row .. last(count(index, offset, 53)) .. format.end_row() return row end @@ -58,7 +50,8 @@ function activity.generate_table (year, repositories) for index, weekday in pairs(weekdays) do rows = rows .. row(weekday, index, 8 - start_from, index >= start_from, index <= end_at) end - return [[<table class="activity-chart">]] .. "\n" .. rows .. "</table>" + return + format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document() end |