summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-02-08 22:31:47 +0100
committerAki <please@ignore.pl>2024-02-08 22:35:46 +0100
commit2b961ff5c3058b477e1ead61d8fa139f126509fd (patch)
tree1191780309675195806c9d63446ab10f8314220a
parent89b7fc43530535ea0fb2114e5fa0cf5660ca37a0 (diff)
downloadactivity-2b961ff5c3058b477e1ead61d8fa139f126509fd.zip
activity-2b961ff5c3058b477e1ead61d8fa139f126509fd.tar.gz
activity-2b961ff5c3058b477e1ead61d8fa139f126509fd.tar.bz2
Generate empty rolling table
-rw-r--r--activity.lua27
-rw-r--r--generate.lua7
-rw-r--r--spec/activity_spec.lua15
3 files changed, 47 insertions, 2 deletions
diff --git a/activity.lua b/activity.lua
index 9a602b5..405dc05 100644
--- a/activity.lua
+++ b/activity.lua
@@ -3,7 +3,32 @@ local git = require "activity.git"
local activity = {}
-function activity.generate_table (year, lookup, format)
+local
+function generate_rolling (lookup, format, date)
+ date = date or os.date"*t"
+ local rows = ""
+ local weekdays = {"", "Mon", "", "Wed", "", "Fri", ""}
+
+ for index, weekday in pairs(weekdays) do
+ rows = rows .. format.label(weekday)
+ for week=0,51 do
+ rows = rows .. format.cell(0)
+ end
+ if date.wday >= index then
+ rows = rows .. format.cell(0)
+ else
+ rows = rows .. format.spot()
+ end
+ rows = rows .. "\n"
+ end
+ return format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document()
+end
+
+
+function activity.generate_table (year, lookup, format, ...)
+ if year == "rolling" then
+ return generate_rolling(lookup, format, ...)
+ end
year = year or dates.this_year()
local function day_of_year (first_weekday, week, weekday)
diff --git a/generate.lua b/generate.lua
index a216808..cea6a87 100644
--- a/generate.lua
+++ b/generate.lua
@@ -3,6 +3,7 @@ local args = require "pl.lapp" [[
Generates activity chart
-f (string default 'ansi') Output format of the chart
-y (optional number) Year of the chart
+ -R Generate rolling chart
<repos...> (optional string) Paths to repositories with activity
]]
local activity = require "activity"
@@ -12,4 +13,8 @@ if not ok then
io.stderr:write(("couldn't find specified format: %q\n"):format(args.f))
os.exit(1)
end
-io.write(activity.generate_table(args.y, git.lookup(args.repos), maybe_format))
+local maybe_year = args.y
+if args.R then
+ maybe_year = "rolling"
+end
+io.write(activity.generate_table(maybe_year, git.lookup(args.repos), maybe_format))
diff --git a/spec/activity_spec.lua b/spec/activity_spec.lua
index 197b57f..581b0ba 100644
--- a/spec/activity_spec.lua
+++ b/spec/activity_spec.lua
@@ -32,6 +32,16 @@ Fri 0000000000000000000000000000000000000000000000000000_
0000000000000000000000000000000000000000000000000000_
]]
+local ROLL = [[
+ 00000000000000000000000000000000000000000000000000000
+Mon 00000000000000000000000000000000000000000000000000000
+ 00000000000000000000000000000000000000000000000000000
+Wed 00000000000000000000000000000000000000000000000000000
+ 00000000000000000000000000000000000000000000000000000
+Fri 0000000000000000000000000000000000000000000000000000_
+ 0000000000000000000000000000000000000000000000000000_
+]]
+
describe("Generator", function()
describe("shall generate correct table for year", function()
@@ -66,4 +76,9 @@ describe("Generator", function()
assert.are.equal(Y2024:gsub("0", "1"), activity.generate_table(2024, lookup, plain))
end)
end)
+
+ it("shall support generating rolling table", function()
+ local date = os.date("*t", os.time{year=2024, month=2, day=8})
+ assert.are.equal(ROLL, activity.generate_table("rolling", lookup, plain, date))
+ end)
end)