From ea959b504c0c917e790e3819061ff40c430e60e4 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 18 May 2023 13:02:02 +0200 Subject: [PATCH 1/5] chore(luarocks): add Html reporter module --- luacov-scm-1.rockspec | 9 +++++++-- {src/luacov/reporter => static}/html/lang-lua.js | 0 {src/luacov/reporter => static}/html/prettify.js | 0 {src/luacov/reporter => static}/html/report.css | 0 {src/luacov/reporter => static}/html/report.js | 0 5 files changed, 7 insertions(+), 2 deletions(-) rename {src/luacov/reporter => static}/html/lang-lua.js (100%) rename {src/luacov/reporter => static}/html/prettify.js (100%) rename {src/luacov/reporter => static}/html/report.css (100%) rename {src/luacov/reporter => static}/html/report.js (100%) diff --git a/luacov-scm-1.rockspec b/luacov-scm-1.rockspec index 4df09b3..7ad344b 100644 --- a/luacov-scm-1.rockspec +++ b/luacov-scm-1.rockspec @@ -28,6 +28,8 @@ build = { ["luacov.linescanner"] = "src/luacov/linescanner.lua", ["luacov.reporter"] = "src/luacov/reporter.lua", ["luacov.reporter.default"] = "src/luacov/reporter/default.lua", + ["luacov.reporter.html"] = "src/luacov/reporter/html.lua", + ["luacov.reporter.html.template"] = "src/luacov/reporter/html/template.lua", ["luacov.runner"] = "src/luacov/runner.lua", ["luacov.stats"] = "src/luacov/stats.lua", ["luacov.tick"] = "src/luacov/tick.lua", @@ -36,6 +38,9 @@ build = { install = { bin = { luacov = "src/bin/luacov" - } - } + }, + }, + copy_directories = { + "static", + }, } diff --git a/src/luacov/reporter/html/lang-lua.js b/static/html/lang-lua.js similarity index 100% rename from src/luacov/reporter/html/lang-lua.js rename to static/html/lang-lua.js diff --git a/src/luacov/reporter/html/prettify.js b/static/html/prettify.js similarity index 100% rename from src/luacov/reporter/html/prettify.js rename to static/html/prettify.js diff --git a/src/luacov/reporter/html/report.css b/static/html/report.css similarity index 100% rename from src/luacov/reporter/html/report.css rename to static/html/report.css diff --git a/src/luacov/reporter/html/report.js b/static/html/report.js similarity index 100% rename from src/luacov/reporter/html/report.js rename to static/html/report.js From 3faeff123bb4379ea8de146e10a8fc0912191026 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 18 May 2023 13:04:18 +0200 Subject: [PATCH 2/5] feat(reporter/html): use datafile to open static --- src/luacov/reporter/html.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/luacov/reporter/html.lua b/src/luacov/reporter/html.lua index e0fb080..4833c4b 100644 --- a/src/luacov/reporter/html.lua +++ b/src/luacov/reporter/html.lua @@ -1,3 +1,4 @@ +local datafile = require("datafile") local luacov_reporter = require("luacov.reporter") local reporter = {} @@ -14,11 +15,6 @@ end ---------------------------------------------------------------- --- parse template do - local dir = string.gsub(debug.getinfo(1).source, "^@(.+/)[^/]+$", "%1") - local dir_sep = package.config:sub(1, 1) - if not dir_sep:find("[/\\]") then - dir_sep = "/" - end local template = require("luacov.reporter.html.template") --- Removes a prefix from a string if it's present. @@ -36,7 +32,7 @@ do -- Returns contents of a file or nil + error message. local function read_asset(name) - local f, open_err = io.open(dir .. "html" .. dir_sep .. name, "rb") + local f, open_err = datafile.open("static/html/" .. name, "r") if not f then error(unprefix(open_err, name .. ": ")) From 243de21d7a06eeeaa86b0b1212cd18cdbcf1d4a9 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Thu, 18 May 2023 13:05:20 +0200 Subject: [PATCH 3/5] doc(README): add note about deps for html reporter --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index fa39edd..39dadc2 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,13 @@ reportfile = "luacov.report.html" ![LuaCov Html Reporter](docs/luacov-html-reporter.png) +:warning: The Html reporter has an additional dependency on +[datafile](https://github.com/hishamhm/datafile). It can be installed with + +```sh +luarocks install datafile +``` + ## Custom reporter engines LuaCov supports custom reporter engines, which are distributed as separate From f578397638023aec2a4109d43d9cfce80cc0166e Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 7 Sep 2023 14:45:48 +0200 Subject: [PATCH 4/5] reorganize files, include datafile as dependency --- README.md | 7 ------- luacov-scm-1.rockspec | 2 +- src/luacov/reporter/html.lua | 2 +- .../html => src/luacov/reporter/html/static}/lang-lua.js | 0 .../html => src/luacov/reporter/html/static}/prettify.js | 0 .../html => src/luacov/reporter/html/static}/report.css | 0 {static/html => src/luacov/reporter/html/static}/report.js | 0 7 files changed, 2 insertions(+), 9 deletions(-) rename {static/html => src/luacov/reporter/html/static}/lang-lua.js (100%) rename {static/html => src/luacov/reporter/html/static}/prettify.js (100%) rename {static/html => src/luacov/reporter/html/static}/report.css (100%) rename {static/html => src/luacov/reporter/html/static}/report.js (100%) diff --git a/README.md b/README.md index 39dadc2..fa39edd 100644 --- a/README.md +++ b/README.md @@ -163,13 +163,6 @@ reportfile = "luacov.report.html" ![LuaCov Html Reporter](docs/luacov-html-reporter.png) -:warning: The Html reporter has an additional dependency on -[datafile](https://github.com/hishamhm/datafile). It can be installed with - -```sh -luarocks install datafile -``` - ## Custom reporter engines LuaCov supports custom reporter engines, which are distributed as separate diff --git a/luacov-scm-1.rockspec b/luacov-scm-1.rockspec index 7ad344b..6fa01d6 100644 --- a/luacov-scm-1.rockspec +++ b/luacov-scm-1.rockspec @@ -41,6 +41,6 @@ build = { }, }, copy_directories = { - "static", + "src/luacov/reporter/html/static", }, } diff --git a/src/luacov/reporter/html.lua b/src/luacov/reporter/html.lua index 4833c4b..26b49a3 100644 --- a/src/luacov/reporter/html.lua +++ b/src/luacov/reporter/html.lua @@ -32,7 +32,7 @@ do -- Returns contents of a file or nil + error message. local function read_asset(name) - local f, open_err = datafile.open("static/html/" .. name, "r") + local f, open_err = datafile.open("src/luacov/reporter/html/static/" .. name, "rb") if not f then error(unprefix(open_err, name .. ": ")) diff --git a/static/html/lang-lua.js b/src/luacov/reporter/html/static/lang-lua.js similarity index 100% rename from static/html/lang-lua.js rename to src/luacov/reporter/html/static/lang-lua.js diff --git a/static/html/prettify.js b/src/luacov/reporter/html/static/prettify.js similarity index 100% rename from static/html/prettify.js rename to src/luacov/reporter/html/static/prettify.js diff --git a/static/html/report.css b/src/luacov/reporter/html/static/report.css similarity index 100% rename from static/html/report.css rename to src/luacov/reporter/html/static/report.css diff --git a/static/html/report.js b/src/luacov/reporter/html/static/report.js similarity index 100% rename from static/html/report.js rename to src/luacov/reporter/html/static/report.js From 0aaba14f460c24f6a7af9194f0e135c85afd7706 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 7 Sep 2023 14:59:38 +0200 Subject: [PATCH 5/5] fix luacheck config --- .luacheckrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 346359c..1b2b2fd 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -2,7 +2,7 @@ std = "min" include_files = {"src", "spec"} exclude_files = { "spec/*/*", - "src/luacov/reporter/html/*.js", - "src/luacov/reporter/html/*.css", + "src/luacov/reporter/html/static/*.js", + "src/luacov/reporter/html/static/*.css", } files.spec.std = "+busted"