From ab1cb08298363d429bc811ba2d3375a3fa647065 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2023 22:32:21 +0200 Subject: Extracted output format to own module for potential later expansion --- activity.lua | 23 +++++-------- activity/formats/html5.lua | 82 ++++++++++++++++++++++++++++++++++++++++++++++ generate.lua | 8 ++--- style.css | 58 -------------------------------- 4 files changed, 92 insertions(+), 79 deletions(-) create mode 100644 activity/formats/html5.lua delete mode 100644 style.css 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 [[]] - end - - local function day (level) - return ([[]]):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 = ([[%s]]):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 [[]] .. "\n" .. rows .. "
" + return + format.start_document"Activity" .. format.start_table() .. rows .. format.end_table() .. format.end_document() end diff --git a/activity/formats/html5.lua b/activity/formats/html5.lua new file mode 100644 index 0000000..8e6e4fd --- /dev/null +++ b/activity/formats/html5.lua @@ -0,0 +1,82 @@ +local stringx = require "pl.stringx" +local html5 = {} + + +function html5.start_document (title) + return stringx.dedent[[ + + + + + %s]]:format(title) -- dedent appends trailing newline. +end + + +function html5.end_document () + return "\n" +end + + +function html5.start_table () + return [[]] .. "\n" +end + + +function html5.end_table () + return "
" +end + + +function html5.start_row () + return "" +end + + +function html5.end_row () + return "\n" +end + + +function html5.label (name) + return ([[%s]]):format(name) +end + + +function html5.spot () + return "" +end + + +function html5.cell (level) + return ([[]]):format(level) +end + + +return html5 diff --git a/generate.lua b/generate.lua index 0486f7e..c9a21bf 100644 --- a/generate.lua +++ b/generate.lua @@ -1,9 +1,5 @@ local activity = require "activity" +local format = require "activity.formats.html5" local args = {...} local year = tonumber(table.remove(args, 1)) -print([[]]) -print([[]]) -print([[]]) -print([[]]) -print([[Activity]]) -print(activity.generate_table(year, args)) +print(activity.generate_table(year, args, format)) diff --git a/style.css b/style.css deleted file mode 100644 index e5ca66c..0000000 --- a/style.css +++ /dev/null @@ -1,58 +0,0 @@ -table.activity-chart { - border-spacing: 4px; -} - - -table.activity-chart tr { - height: 11px; -} - - -td.activity-chart-label { - position: relative; - font-size: 12px; - min-width: 2em; -} - - -td.activity-chart-label span { - position: absolute; - top: -3px; -} - - -td[data-activity-level] { - box-sizing: border-box; - outline-width: 1px; - outline-style: solid; - outline-offset: -1px; - outline-color: rgba(27, 31, 35, 0.06); - border-radius: 2px; - height: 11px; - min-width: 11px; -} - - -td[data-activity-level="0"] { - background-color: #ccc; -} - - -td[data-activity-level="1"] { - background-color: #9be9a8; -} - - -td[data-activity-level="2"] { - background-color: #40c463; -} - - -td[data-activity-level="3"] { - background-color: #30a14e; -} - - -td[data-activity-level="4"] { - background-color: #216e39; -} -- cgit v1.1