simplecov-tailwindcss 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintignore +1 -0
  3. data/.eslintrc.yml +25 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  5. data/.github/ISSUE_TEMPLATE/feature-request.md +20 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +10 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +32 -0
  8. data/.github/workflows/builds.yml +37 -0
  9. data/.github/workflows/lints.yml +38 -0
  10. data/.github/workflows/tests.yml +26 -0
  11. data/.gitignore +12 -0
  12. data/.markdownlint.yml +21 -0
  13. data/.rubocop.yml +876 -0
  14. data/.ruby-version +1 -0
  15. data/.stylelintignore +1 -0
  16. data/.stylelintrc +48 -0
  17. data/CHANGELOG.md +14 -0
  18. data/CODE_OF_CONDUCT.md +74 -0
  19. data/CONTRIBUTING.md +132 -0
  20. data/Gemfile +18 -0
  21. data/LICENSE +21 -0
  22. data/README.md +111 -0
  23. data/Rakefile +12 -0
  24. data/bin/console +12 -0
  25. data/bin/publish +82 -0
  26. data/bin/setup +7 -0
  27. data/dist/app.js +9 -0
  28. data/dist/app.scss +6 -0
  29. data/dist/scripts/controllers/toggle_controller.js +14 -0
  30. data/dist/scripts/navigation.js +44 -0
  31. data/dist/scripts/table.js +103 -0
  32. data/dist/scripts/timeago.js +3 -0
  33. data/dist/styles/dialog.scss +50 -0
  34. data/dist/styles/main.scss +3 -0
  35. data/lib/simplecov-tailwindcss.rb +156 -0
  36. data/lib/simplecov-tailwindcss/version.rb +9 -0
  37. data/package.json +69 -0
  38. data/public/application.css +201867 -0
  39. data/public/application.js +662 -0
  40. data/simplecov-tailwindcss.gemspec +32 -0
  41. data/tailwind.config.js +17 -0
  42. data/test/fixtures/app/controllers/sample_controller.rb +12 -0
  43. data/test/fixtures/app/models/user.rb +12 -0
  44. data/test/fixtures/sample.rb +12 -0
  45. data/test/simplecov-tailwindcss/simplecov_tailwindcss_test.rb +40 -0
  46. data/test/test_helper.rb +18 -0
  47. data/views/dialog.erb +88 -0
  48. data/views/group_page.erb +133 -0
  49. data/views/main.erb +187 -0
  50. data/views/stat_card.erb +12 -0
  51. data/views/table_column_head.erb +13 -0
  52. data/webpack.config.js +82 -0
  53. data/yarn.lock +7537 -0
  54. metadata +122 -0
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pathname"
5
+ require "fileutils"
6
+ require "json"
7
+
8
+ # path to your application root.
9
+ APP_ROOT = Pathname.new File.expand_path("..", __dir__)
10
+ MAIN_CHECK = <<~MAIN_CHECK
11
+ if [ $(git symbolic-ref --short -q HEAD) != 'main' ];
12
+ then exit 1;
13
+ fi
14
+ MAIN_CHECK
15
+ VERSION_TYPES = %w(major minor patch).freeze
16
+
17
+ def system!(*args)
18
+ system(*args) || abort("\n== Command #{args} failed ==")
19
+ end
20
+
21
+ abort("\n== Version Type incorrect ==") unless VERSION_TYPES.include?(ARGV[0])
22
+
23
+ abort("\n== Not on main") unless system(MAIN_CHECK)
24
+
25
+ current_version =
26
+ JSON.parse(File.read("package.json"))["version"].split(".").map(&:to_i)
27
+
28
+ case ARGV[0]
29
+ when "major"
30
+ current_version[0] += 1
31
+ current_version[1] = 0
32
+ current_version[2] = 0
33
+ when "minor"
34
+ current_version[1] += 1
35
+ current_version[2] = 0
36
+ when "patch"
37
+ current_version[2] += 1
38
+ end
39
+
40
+ joined_version = current_version.join(".")
41
+
42
+ FileUtils.chdir APP_ROOT do # rubocop:disable Metrics/BlockLength
43
+ contents = <<~FILE
44
+ # frozen_string_literal: true
45
+
46
+ module SimpleCov
47
+ module Formatter
48
+ class MaterialFormatter
49
+ VERSION = "#{joined_version}"
50
+ end
51
+ end
52
+ end
53
+ FILE
54
+
55
+ package = JSON.parse(File.read("package.json"))
56
+ package["version"] = joined_version.to_s
57
+
58
+ puts "== Updating version in Version file to #{joined_version} =="
59
+ File.write("lib/simplecov-tailwindcss/version.rb", contents)
60
+
61
+ puts "== Updated version in package.json file to #{joined_version} =="
62
+ File.open("package.json", "w") do |f|
63
+ f.write(JSON.pretty_generate(package))
64
+ end
65
+
66
+ system! "git add lib/simplecov-tailwindcss/version.rb"
67
+ system! "git add package.json"
68
+
69
+ puts "== Committing updated files =="
70
+ system! "git commit -m 'Version bump to #{joined_version}'"
71
+ system! "git push"
72
+
73
+ puts "== Building gem =="
74
+ system! "yarn gem:build"
75
+
76
+ puts "== Publishing gem =="
77
+ built_gem_path = "pkg/simplecov-tailwindcss-#{joined_version}.gem"
78
+ github_host = "https://rubygems.pkg.github.com/chiefpansancolt"
79
+
80
+ system! "gem push --key github --host #{github_host} #{built_gem_path}"
81
+ system! "gem push #{built_gem_path}"
82
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ yarn install
@@ -0,0 +1,9 @@
1
+ import {Application} from 'stimulus';
2
+ import {definitionsFromContext} from 'stimulus/webpack-helpers';
3
+ import './scripts/navigation.js';
4
+ import './scripts/table.js';
5
+ import './scripts/timeago.js';
6
+
7
+ const application = Application.start();
8
+ const context = require.context('./scripts/controllers', true, /\.js$/);
9
+ application.load(definitionsFromContext(context));
@@ -0,0 +1,6 @@
1
+ @import "tailwindcss/base";
2
+ @import "tailwindcss/components";
3
+ @import "tailwindcss/utilities";
4
+ @import url("https://rsms.me/inter/inter.css");
5
+ @import "./styles/main";
6
+ @import "./styles/dialog";
@@ -0,0 +1,14 @@
1
+ import {Controller} from 'stimulus';
2
+
3
+ export default class extends Controller {
4
+ toggle(event) {
5
+ const TARGETS = event.currentTarget.dataset.toggleTarget.split(',');
6
+ const HIDDEN_CLASS = this.element.dataset.hiddenClass || 'hidden';
7
+
8
+ TARGETS.forEach((target) =>
9
+ document
10
+ .querySelectorAll(`[data-toggle-name="${target}"]`)
11
+ .forEach((target) => target.classList.toggle(HIDDEN_CLASS)),
12
+ );
13
+ }
14
+ }
@@ -0,0 +1,44 @@
1
+ export function navigate(elementId) {
2
+ const tabGroups = document.querySelectorAll('.tab-groups');
3
+ const desktopNav = document.querySelectorAll('.desktop-nav > a');
4
+ const mobileNav = document.querySelectorAll('.mobile-nav > a');
5
+
6
+ for (var i = 0; i < tabGroups.length; i++) {
7
+ var txtValue = tabGroups[i].attributes.name.value;
8
+ if (txtValue.indexOf(elementId) > -1) {
9
+ tabGroups[i].classList.remove('hidden');
10
+ } else {
11
+ tabGroups[i].classList.add('hidden');
12
+ }
13
+ }
14
+
15
+ for (var i = 0; i < desktopNav.length; i++) {
16
+ if (desktopNav[i].attributes.name.value == elementId) {
17
+ desktopNav[i].classList.remove(
18
+ 'text-gray-300', 'hover:text-white', 'hover:bg-gray-700', 'focus:text-white', 'focus:bg-gray-700',
19
+ );
20
+ desktopNav[i].classList.add('text-white', 'bg-gray-900');
21
+ } else {
22
+ desktopNav[i].classList.remove('text-white', 'bg-gray-900');
23
+ desktopNav[i].classList.add(
24
+ 'text-gray-300', 'hover:text-white', 'hover:bg-gray-700', 'focus:text-white', 'focus:bg-gray-700',
25
+ );
26
+ }
27
+ }
28
+
29
+ for (var i = 0; i < mobileNav.length; i++) {
30
+ if (mobileNav[i].attributes.name.value == elementId) {
31
+ mobileNav[i].classList.remove(
32
+ 'text-gray-300', 'hover:text-white', 'hover:bg-gray-700', 'focus:text-white', 'focus:bg-gray-700',
33
+ );
34
+ mobileNav[i].classList.add('text-white', 'bg-gray-900');
35
+ } else {
36
+ mobileNav[i].classList.remove('text-white', 'bg-gray-900');
37
+ mobileNav[i].classList.add(
38
+ 'text-gray-300', 'hover:text-white', 'hover:bg-gray-700', 'focus:text-white', 'focus:bg-gray-700',
39
+ );
40
+ }
41
+ }
42
+ }
43
+
44
+ window.navigate = navigate;
@@ -0,0 +1,103 @@
1
+ export function searchTable(filter) {
2
+ const views = document.querySelectorAll('.tab-groups');
3
+ var view;
4
+ for (i = 0; i < views.length; i++) {
5
+ var running = views[i].classList.contains('hidden');
6
+ if (!running) {
7
+ view = views[i].attributes.name.value;
8
+ }
9
+ }
10
+ const table = document.getElementById(view + '-table');
11
+ const rows = table.getElementsByTagName('tbody')[0].getElementsByTagName('tr');
12
+
13
+ for (var i = 1; i < rows.length; i++) {
14
+ var row = rows[i].getElementsByTagName('td')[0];
15
+ var txtValue = row.textContent || row.innerText;
16
+ if (txtValue.toUpperCase().indexOf(filter) > -1) {
17
+ rows[i].classList.remove('hidden');
18
+ } else {
19
+ rows[i].classList.add('hidden');
20
+ }
21
+ }
22
+
23
+ const total = document.querySelectorAll('#' + view + '-table > tbody > tr.row').length;
24
+ const current = document.querySelectorAll('#' + view + '-table > tbody > tr.row.hidden').length;
25
+ const hiddenRow = document.getElementById(view + '-hiderow');
26
+ if (total == current) {
27
+ hiddenRow.classList.remove('hidden');
28
+ } else {
29
+ hiddenRow.classList.add('hidden');
30
+ }
31
+ }
32
+
33
+ window.searchTable = searchTable;
34
+
35
+ function sortTable(table, col, reverse) {
36
+ var tb = table.tBodies[0];
37
+ var tbh = table.tHead;
38
+ var th = Array.prototype.slice.call(tbh.rows, 0);
39
+ var tr = Array.prototype.slice.call(tb.rows, 1);
40
+ var i;
41
+ var c;
42
+ reverse = -((+reverse) || -1);
43
+ tr = tr.sort(function(a, b) {
44
+ return reverse * a.cells[col].dataset.sortVal.localeCompare(
45
+ b.cells[col].dataset.sortVal, undefined, {numeric: true},
46
+ );
47
+ });
48
+ for (i = 0; i < th.length; ++i) {
49
+ for (c = 0; c < th[i].cells.length; ++c) {
50
+ if (c != col) {
51
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[1].classList.add('hidden');
52
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[3].classList.add('hidden');
53
+ } else {
54
+ if (reverse == 1) {
55
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[1].classList.add('hidden');
56
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[3].classList.remove('hidden');
57
+ } else {
58
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[1].classList.remove('hidden');
59
+ th[i].cells[c].childNodes[1].childNodes[1].childNodes[3].classList.add('hidden');
60
+ }
61
+ }
62
+ }
63
+ }
64
+ for (i = 0; i < tr.length; ++i) tb.appendChild(tr[i]);
65
+ }
66
+
67
+ function makeSortable(table) {
68
+ var th = table.tHead;
69
+ var i;
70
+ th && (th = th.rows[0]) && (th = th.cells);
71
+ if (th) i = th.length;
72
+ else return;
73
+ while (--i >= 0) {
74
+ (function(i) {
75
+ var dir = 1;
76
+ th[i].addEventListener('click', function() {
77
+ sortTable(table, i, (dir = 1 - dir));
78
+ });
79
+ }(i));
80
+ };
81
+ }
82
+
83
+ function makeAllSortable(parent) {
84
+ parent = parent || document.body;
85
+ var t = parent.getElementsByTagName('table');
86
+ var i = t.length;
87
+ while (--i >= 0) {
88
+ makeSortable(t[i]);
89
+ };
90
+ }
91
+
92
+ function defaultSort() {
93
+ var t = document.getElementsByTagName('table');
94
+ var i;
95
+ for (i = 0; i < t.length; ++i) {
96
+ sortTable(t[i], 1, -1);
97
+ }
98
+ }
99
+
100
+ window.onload = function() {
101
+ makeAllSortable();
102
+ defaultSort();
103
+ };
@@ -0,0 +1,3 @@
1
+ import {render} from 'timeago.js';
2
+
3
+ render(document.querySelectorAll('.timeago'));
@@ -0,0 +1,50 @@
1
+ .dialog-body {
2
+
3
+ .covered {
4
+ @apply border-green-500;
5
+
6
+ &:nth-child(odd) {
7
+ @apply bg-green-400;
8
+ }
9
+
10
+ &:nth-child(even) {
11
+ @apply bg-green-300;
12
+ }
13
+ }
14
+
15
+ .missed {
16
+ @apply border-red-500;
17
+
18
+ &:nth-child(odd) {
19
+ @apply bg-red-400;
20
+ }
21
+
22
+ &:nth-child(even) {
23
+ @apply bg-red-300;
24
+ }
25
+ }
26
+
27
+ .never {
28
+ @apply border-gray-900;
29
+
30
+ &:nth-child(odd) {
31
+ @apply bg-gray-200;
32
+ }
33
+
34
+ &:nth-child(even) {
35
+ @apply bg-gray-50;
36
+ }
37
+ }
38
+
39
+ .skipped {
40
+ @apply border-yellow-500;
41
+
42
+ &:nth-child(odd) {
43
+ @apply bg-yellow-400;
44
+ }
45
+
46
+ &:nth-child(even) {
47
+ @apply bg-yellow-300;
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,3 @@
1
+ .clickable {
2
+ cursor: pointer;
3
+ }
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "cgi"
5
+ require "fileutils"
6
+ require "digest/sha1"
7
+ require "pry"
8
+
9
+ # Ensure we are using a compatible version of SimpleCov
10
+ major, minor, patch = SimpleCov::VERSION.scan(/\d+/).first(3).map(&:to_i)
11
+ if major.negative? || minor < 9 || patch.negative?
12
+ raise "The version of SimpleCov you are using is too old. "\
13
+ "Please update with `gem install simplecov` or `bundle update simplecov`"
14
+ end
15
+
16
+ module SimpleCov
17
+ module Formatter
18
+ class TailwindFormatter # rubocop:disable Metrics/ClassLength
19
+ def initialize
20
+ @branchable_result = SimpleCov.branch_coverage?
21
+ end
22
+
23
+ def format(result) # rubocop:disable Metrics/AbcSize
24
+ Dir[File.join(File.dirname(__FILE__), "../public/*")].each do |path|
25
+ FileUtils.cp_r(path, asset_output_path)
26
+ end
27
+
28
+ File.open(File.join(output_path, "index.html"), "wb") do |file|
29
+ file.puts template("main").result(binding)
30
+ end
31
+ puts output_message(result)
32
+ end
33
+
34
+ def output_message(result)
35
+ "Coverage report generated for #{result.command_name} to " \
36
+ "#{output_path}. #{result.covered_lines} / #{result.total_lines} LOC" \
37
+ " (#{result.covered_percent.round(2)}%) covered."
38
+ end
39
+
40
+ def branchable_result?
41
+ @branchable_result
42
+ end
43
+
44
+ def line_status?(source_file, line)
45
+ if branchable_result? && source_file.line_with_missed_branch?(line.number)
46
+ "missed-branch"
47
+ else
48
+ line.status
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def template(name)
55
+ ERB.new(File.read(File.join(
56
+ File.dirname(__FILE__), "../views/", "#{name}.erb"
57
+ )))
58
+ end
59
+
60
+ def output_path
61
+ SimpleCov.coverage_path
62
+ end
63
+
64
+ def asset_output_path
65
+ return @asset_output_path if defined?(@asset_output_path) &&
66
+ @asset_output_path
67
+
68
+ @asset_output_path = File.join(
69
+ output_path, "dist", SimpleCov::Formatter::TailwindFormatter::VERSION
70
+ )
71
+ FileUtils.mkdir_p(@asset_output_path)
72
+ @asset_output_path
73
+ end
74
+
75
+ def assets_path(name)
76
+ File.join(
77
+ "./dist", SimpleCov::Formatter::TailwindFormatter::VERSION, name
78
+ )
79
+ end
80
+
81
+ def generate_dialog(file)
82
+ template("dialog").result(binding)
83
+ rescue Encoding::CompatibilityError => e
84
+ puts "Encoding problems with file #{file.filename}. Simplecov/ERB "\
85
+ "can't handle non ASCII characters in filenames. Error: " \
86
+ "#{e.message}."
87
+ end
88
+
89
+ def generate_stat_card(title, stat, color)
90
+ template("stat_card").result(binding)
91
+ end
92
+
93
+ def generate_table_column_head(name)
94
+ template("table_column_head").result(binding)
95
+ end
96
+
97
+ # rubocop:disable Lint/SelfAssignment, Style/RedundantRegexpEscape
98
+ def generate_group_page(title, files)
99
+ title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
100
+ title_id = title_id
101
+ template("group_page").result(binding)
102
+ end
103
+
104
+ def remove_spaces(name)
105
+ name.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
106
+ end
107
+ # rubocop:enable Lint/SelfAssignment, Style/RedundantRegexpEscape
108
+
109
+ def format_number(number)
110
+ whole, decimal = number.to_s.split(".")
111
+ whole_with_commas =
112
+ whole.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse
113
+ [whole_with_commas, decimal].compact.join(".")
114
+ end
115
+
116
+ def coverage_class(covered_percent)
117
+ if covered_percent > 90
118
+ "text-green-500"
119
+ elsif covered_percent > 80
120
+ "text-yellow-500"
121
+ else
122
+ "text-red-500"
123
+ end
124
+ end
125
+
126
+ def strength_class(covered_strength)
127
+ if covered_strength > 1
128
+ "text-green-500"
129
+ elsif covered_strength == 1
130
+ "text-yellow-500"
131
+ else
132
+ "text-red-500"
133
+ end
134
+ end
135
+
136
+ def id(source_file)
137
+ Digest::SHA1.hexdigest(source_file.filename)
138
+ end
139
+
140
+ def shortened_filename(file)
141
+ file.filename.sub(SimpleCov.root, ".").gsub(/^\.\//, "")
142
+ end
143
+
144
+ def hide_show(title)
145
+ if title == "AllFiles"
146
+ ""
147
+ else
148
+ "hidden"
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
156
+ require "simplecov-tailwindcss/version"