ariadne_view_components 0.0.10-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +49 -0
  3. data/README.md +73 -0
  4. data/app/assets/config/manifest.js +2 -0
  5. data/app/assets/javascripts/ariadne-form-with.d.ts +20 -0
  6. data/app/assets/javascripts/ariadne-form.d.ts +22 -0
  7. data/app/assets/javascripts/ariadne.d.ts +1 -0
  8. data/app/assets/javascripts/ariadne_view_components.js +8 -0
  9. data/app/assets/javascripts/ariadne_view_components.js.map +1 -0
  10. data/app/assets/javascripts/clipboard-copy-component.d.ts +4 -0
  11. data/app/assets/javascripts/comment-component.d.ts +13 -0
  12. data/app/assets/javascripts/rich-text-area-component.d.ts +4 -0
  13. data/app/assets/javascripts/slideover-component.d.ts +9 -0
  14. data/app/assets/javascripts/time-ago-component.d.ts +1 -0
  15. data/app/assets/javascripts/time_ago_component.d.ts +1 -0
  16. data/app/assets/javascripts/tooltip-component.d.ts +24 -0
  17. data/app/assets/stylesheets/ariadne_view_components.css +6 -0
  18. data/app/assets/stylesheets/prosemirror.css +323 -0
  19. data/app/assets/stylesheets/tooltip-component.css +37 -0
  20. data/app/components/ariadne/ariadne-form.ts +96 -0
  21. data/app/components/ariadne/ariadne.ts +20 -0
  22. data/app/components/ariadne/base_button.rb +61 -0
  23. data/app/components/ariadne/base_component.rb +37 -0
  24. data/app/components/ariadne/blankslate_component.html.erb +26 -0
  25. data/app/components/ariadne/blankslate_component.rb +146 -0
  26. data/app/components/ariadne/body_component.rb +30 -0
  27. data/app/components/ariadne/button_component.html.erb +4 -0
  28. data/app/components/ariadne/button_component.rb +157 -0
  29. data/app/components/ariadne/clipboard-copy-component.ts +19 -0
  30. data/app/components/ariadne/clipboard_copy_component.html.erb +9 -0
  31. data/app/components/ariadne/clipboard_copy_component.rb +90 -0
  32. data/app/components/ariadne/comment-component.ts +55 -0
  33. data/app/components/ariadne/comment_component.html.erb +22 -0
  34. data/app/components/ariadne/comment_component.rb +57 -0
  35. data/app/components/ariadne/component.rb +128 -0
  36. data/app/components/ariadne/container_component.html.erb +3 -0
  37. data/app/components/ariadne/container_component.rb +25 -0
  38. data/app/components/ariadne/content.rb +12 -0
  39. data/app/components/ariadne/counter_component.rb +100 -0
  40. data/app/components/ariadne/flash_component.html.erb +31 -0
  41. data/app/components/ariadne/flash_component.rb +125 -0
  42. data/app/components/ariadne/flex_component.rb +49 -0
  43. data/app/components/ariadne/footer_component.html.erb +7 -0
  44. data/app/components/ariadne/footer_component.rb +23 -0
  45. data/app/components/ariadne/grid_component.html.erb +26 -0
  46. data/app/components/ariadne/grid_component.rb +66 -0
  47. data/app/components/ariadne/header_component.html.erb +29 -0
  48. data/app/components/ariadne/header_component.rb +114 -0
  49. data/app/components/ariadne/heading_component.rb +49 -0
  50. data/app/components/ariadne/heroicon_component.html.erb +4 -0
  51. data/app/components/ariadne/heroicon_component.rb +129 -0
  52. data/app/components/ariadne/image_component.rb +53 -0
  53. data/app/components/ariadne/inline_flex_component.html.erb +5 -0
  54. data/app/components/ariadne/inline_flex_component.rb +65 -0
  55. data/app/components/ariadne/link_component.rb +65 -0
  56. data/app/components/ariadne/list_component.html.erb +15 -0
  57. data/app/components/ariadne/list_component.rb +68 -0
  58. data/app/components/ariadne/main_component.rb +32 -0
  59. data/app/components/ariadne/narrow_container_component.html.erb +3 -0
  60. data/app/components/ariadne/narrow_container_component.rb +30 -0
  61. data/app/components/ariadne/panel_bar_component.html.erb +20 -0
  62. data/app/components/ariadne/panel_bar_component.rb +79 -0
  63. data/app/components/ariadne/pill_component.html.erb +3 -0
  64. data/app/components/ariadne/pill_component.rb +30 -0
  65. data/app/components/ariadne/rich-text-area-component.ts +32 -0
  66. data/app/components/ariadne/rich_text_area_component.html.erb +6 -0
  67. data/app/components/ariadne/rich_text_area_component.rb +35 -0
  68. data/app/components/ariadne/slideover-component.ts +26 -0
  69. data/app/components/ariadne/slideover_component.html.erb +11 -0
  70. data/app/components/ariadne/slideover_component.rb +81 -0
  71. data/app/components/ariadne/tab_bar_component.html.erb +3 -0
  72. data/app/components/ariadne/tab_bar_component.rb +45 -0
  73. data/app/components/ariadne/tab_component.html.erb +7 -0
  74. data/app/components/ariadne/tab_component.rb +43 -0
  75. data/app/components/ariadne/text.rb +25 -0
  76. data/app/components/ariadne/time-ago-component.ts +1 -0
  77. data/app/components/ariadne/time_ago_component.rb +56 -0
  78. data/app/components/ariadne/timeline_component.html.erb +19 -0
  79. data/app/components/ariadne/timeline_component.rb +34 -0
  80. data/app/components/ariadne/tooltip-component.ts +57 -0
  81. data/app/components/ariadne/tooltip_component.html.erb +4 -0
  82. data/app/components/ariadne/tooltip_component.rb +108 -0
  83. data/app/lib/ariadne/action_view_extensions/form_helper.rb +26 -0
  84. data/app/lib/ariadne/audited/dsl.rb +32 -0
  85. data/app/lib/ariadne/class_name_helper.rb +22 -0
  86. data/app/lib/ariadne/fetch_or_fallback_helper.rb +102 -0
  87. data/app/lib/ariadne/form_builder.rb +71 -0
  88. data/app/lib/ariadne/icon_helper.rb +47 -0
  89. data/app/lib/ariadne/join_style_arguments_helper.rb +14 -0
  90. data/app/lib/ariadne/logger_helper.rb +23 -0
  91. data/app/lib/ariadne/status/dsl.rb +41 -0
  92. data/app/lib/ariadne/tab_nav_helper.rb +35 -0
  93. data/app/lib/ariadne/tabbed_component_helper.rb +39 -0
  94. data/app/lib/ariadne/test_selector_helper.rb +20 -0
  95. data/app/lib/ariadne/underline_nav_helper.rb +44 -0
  96. data/app/lib/ariadne/view_helper.rb +22 -0
  97. data/exe/tailwindcss +21 -0
  98. data/exe/x86_64-linux/tailwindcss +0 -0
  99. data/lib/ariadne/view_components/commands.rb +90 -0
  100. data/lib/ariadne/view_components/constants.rb +53 -0
  101. data/lib/ariadne/view_components/engine.rb +75 -0
  102. data/lib/ariadne/view_components/linters.rb +3 -0
  103. data/lib/ariadne/view_components/statuses.rb +14 -0
  104. data/lib/ariadne/view_components/upstream.rb +20 -0
  105. data/lib/ariadne/view_components/version.rb +7 -0
  106. data/lib/ariadne/view_components.rb +61 -0
  107. data/lib/rubocop/config/default.yml +8 -0
  108. data/lib/rubocop/cop/ariadne/base_cop.rb +26 -0
  109. data/lib/rubocop/cop/ariadne/no_tag_memoize.rb +44 -0
  110. data/lib/rubocop/cop/ariadne.rb +3 -0
  111. data/lib/tasks/ariadne_view_components.rake +48 -0
  112. data/lib/tasks/build.rake +30 -0
  113. data/lib/tasks/coverage.rake +19 -0
  114. data/lib/tasks/custom_utilities.yml +310 -0
  115. data/lib/tasks/docs.rake +524 -0
  116. data/lib/tasks/helpers/ast_processor.rb +44 -0
  117. data/lib/tasks/helpers/ast_traverser.rb +77 -0
  118. data/lib/tasks/static.rake +15 -0
  119. data/lib/yard/docs_helper.rb +83 -0
  120. data/lib/yard/renders_many_handler.rb +19 -0
  121. data/lib/yard/renders_one_handler.rb +19 -0
  122. data/static/arguments.yml +619 -0
  123. data/static/assets/view-components.svg +18 -0
  124. data/static/audited_at.json +38 -0
  125. data/static/classes.yml +291 -0
  126. data/static/constants.json +426 -0
  127. data/static/statuses.json +38 -0
  128. data/static/tailwindcss.yml +727 -0
  129. data/tailwind.config.js +65 -0
  130. metadata +264 -0
Binary file
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "upstream"
4
+
5
+ module Ariadne
6
+ module ViewComponents
7
+ # commands related to the upstream Tailwindcss project
8
+ module Commands
9
+ # raised when the host platform is not supported by upstream tailwindcss's binary releases
10
+ class UnsupportedPlatformException < StandardError
11
+ end
12
+
13
+ # raised when the tailwindcss executable could not be found where we expected it to be
14
+ class ExecutableNotFoundException < StandardError
15
+ end
16
+
17
+ class << self
18
+ def platform
19
+ [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
20
+ end
21
+
22
+ def executable(
23
+ exe_path: File.expand_path(File.join(__dir__, "..", "..", "exe"))
24
+ )
25
+ if Ariadne::ViewComponents::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match(p) }
26
+ raise UnsupportedPlatformException, <<~MESSAGE
27
+ ariadne_view_components does not support the #{platform} platform
28
+ Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation
29
+ MESSAGE
30
+ end
31
+
32
+ exe_path = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
33
+ Gem::Platform.match(File.basename(File.dirname(f)))
34
+ end
35
+
36
+ if exe_path.nil?
37
+ raise ExecutableNotFoundException, <<~MESSAGE
38
+ Cannot find the tailwindcss executable for #{platform} in #{exe_path}
39
+
40
+ If you're using bundler, please make sure you're on the latest bundler version:
41
+
42
+ gem install bundler
43
+ bundle update --bundler
44
+
45
+ Then make sure your lock file includes this platform by running:
46
+
47
+ bundle lock --add-platform #{platform}
48
+ bundle install
49
+
50
+ See `bundle lock --help` output for details.
51
+
52
+ If you're still seeing this message after taking those steps, try running
53
+ `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
54
+ https://github.com/rails/tailwindcss-rails#check-bundle_force_ruby_platform
55
+ for more details.
56
+ MESSAGE
57
+ end
58
+
59
+ exe_path
60
+ end
61
+
62
+ def compile_command(debug: false, **kwargs)
63
+ [
64
+ executable(**kwargs),
65
+ "-i", relative_path("app/assets/stylesheets/ariadne_view_components.css"),
66
+ "-o", relative_path("app/assets/builds/ariadne_view_components.css"),
67
+ "-c", relative_path("tailwind.config.js"),
68
+ ].tap do |command|
69
+ command << "--minify" unless debug
70
+ end
71
+ end
72
+
73
+ def watch_command(poll: false, **kwargs)
74
+ compile_command(**kwargs).tap do |command|
75
+ command << "-w"
76
+ command << "-p" if poll
77
+ end
78
+ end
79
+
80
+ def relative_path(path)
81
+ if defined?(Rails)
82
+ Rails.root.join(path).to_s
83
+ else
84
+ path
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Ariadne
6
+ module ViewComponents
7
+ # A module for constants that are used in the view components.
8
+ class Constants
9
+ CONSTANTS = JSON.parse(
10
+ File.read(
11
+ File.join(File.dirname(__FILE__), "../../../static/constants.json")
12
+ )
13
+ ).freeze
14
+
15
+ class << self
16
+ def get(component:, constant:, invert: true, symbolize: false)
17
+ values = CONSTANTS.dig(component, constant)
18
+
19
+ case values
20
+ when Hash
21
+ format_hash(values, invert, symbolize)
22
+ when Array
23
+ format_array(values, symbolize)
24
+ else
25
+ values
26
+ end
27
+ end
28
+
29
+ private def format_hash(values, invert, symbolize)
30
+ val = invert ? values.invert : values
31
+ # remove defaults
32
+ val = val.except("", nil)
33
+
34
+ return val.transform_values { |v| symbolize_value(v) } if symbolize
35
+
36
+ val
37
+ end
38
+
39
+ private def format_array(values, symbolize)
40
+ val = values.select(&:present?)
41
+
42
+ return val.map { |v| symbolize_value(v) } if symbolize
43
+
44
+ val
45
+ end
46
+
47
+ private def symbolize_value(value)
48
+ ":#{value}"
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/engine"
4
+
5
+ require "view_component"
6
+
7
+ require "tailwind_merge"
8
+
9
+ module Ariadne
10
+ # The Ariadne gem is a collection of ViewComponents that can be used to build
11
+ # accessible, responsive, and consistent UIs for Yetto.
12
+ module ViewComponents
13
+ mattr_accessor :tailwind_merger
14
+
15
+ # :nodoc:
16
+ class Engine < ::Rails::Engine
17
+ isolate_namespace Ariadne::ViewComponents
18
+
19
+ config.autoload_paths = ["#{root}/lib"]
20
+ config.eager_load_paths = ["#{root}/app/components", "#{root}/app/helpers", "#{root}/app/lib"]
21
+
22
+ config.ariadne_view_components = ActiveSupport::OrderedOptions.new
23
+
24
+ config.ariadne_view_components.raise_on_invalid_options = true
25
+ config.ariadne_view_components.silence_deprecations = false
26
+ config.ariadne_view_components.silence_warnings = false
27
+ config.ariadne_view_components.validate_class_names = true
28
+ config.ariadne_view_components.raise_on_invalid_aria = true
29
+
30
+ initializer "ariadne_view_components.assets" do |app|
31
+ app.config.assets.precompile += ["ariadne_view_components"] if app.config.respond_to?(:assets)
32
+ end
33
+
34
+ initializer "ariadne_view_components.importmap", before: "importmap" do |app|
35
+ if Rails.application.respond_to?(:importmap)
36
+ app.config.importmap.paths << Engine.root.join("config/importmap.rb")
37
+ end
38
+ end
39
+
40
+ initializer "ariadne_view_components.zeitwerk_ignore" do
41
+ Rails.autoloaders.each do |autoloader|
42
+ autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "linters.rb"))
43
+ autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "linters", "**", "*.rb"))
44
+ autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "statuses.rb"))
45
+ end
46
+ end
47
+
48
+ config.after_initialize do |_app|
49
+ # TODO: is any of this necessary???
50
+ ActionView::Base.field_error_proc = proc do |html_tag, instance_tag|
51
+ fragment = Nokogiri::HTML.fragment(html_tag)
52
+ field = fragment.at("input,select,textarea")
53
+
54
+ model = instance_tag.object
55
+ error_message = model.errors.full_messages.join(", ")
56
+
57
+ html = if field
58
+ field["class"] = "#{field["class"]} invalid"
59
+ html = <<-HTML
60
+ #{fragment}
61
+ <p class="error">#{error_message}</p>
62
+ HTML
63
+ html
64
+ else
65
+ html_tag
66
+ end
67
+
68
+ html.html_safe # rubocop:disable Rails/OutputSafety
69
+ end
70
+
71
+ Ariadne::ViewComponents.tailwind_merger = TailwindMerge::Merger.new
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.join(__dir__, "linters", "*.rb")].sort.each { |file| require file }
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Ariadne
6
+ # :nodoc:
7
+ module ViewComponents
8
+ STATUSES = JSON.parse(
9
+ File.read(
10
+ File.join(File.dirname(__FILE__), "../../../static/statuses.json")
11
+ )
12
+ ).freeze
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ module ViewComponents
5
+ # constants describing the upstream tailwindcss project
6
+ module Upstream
7
+ VERSION = "v3.1.8"
8
+
9
+ # rubygems platform name => upstream release filename
10
+ NATIVE_PLATFORMS = {
11
+ "arm64-darwin" => "tailwindcss-macos-arm64",
12
+ "x64-mingw32" => "tailwindcss-windows-x64.exe",
13
+ "x64-mingw-ucrt" => "tailwindcss-windows-x64.exe",
14
+ "x86_64-darwin" => "tailwindcss-macos-x64",
15
+ "x86_64-linux" => "tailwindcss-linux-x64",
16
+ "aarch64-linux" => "tailwindcss-linux-arm64",
17
+ }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ module ViewComponents
5
+ VERSION = "0.0.10"
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ariadne/view_components/version"
4
+ require "ariadne/view_components/engine"
5
+ require "ariadne/view_components/constants"
6
+ require "ariadne/view_components/commands"
7
+
8
+ module Ariadne
9
+ # :nodoc:
10
+ module ViewComponents
11
+ DEFAULT_STATIC_PATH = File.expand_path("static")
12
+ FILE_NAMES = {
13
+ statuses: "statuses.json",
14
+ constants: "constants.json",
15
+ audited_at: "audited_at.json",
16
+ }.freeze
17
+
18
+ class << self
19
+ # generate_statuses returns a hash mapping component name to
20
+ # the component's status sorted alphabetically by the component name.
21
+ def generate_statuses
22
+ Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
23
+ mem[component.to_s] = component.status.to_s
24
+ end
25
+ end
26
+
27
+ # generate_audited_at returns a hash mapping component name to
28
+ # the day the component has passed an accessibility audit.
29
+ def generate_audited_at
30
+ Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
31
+ mem[component.to_s] = component.audited_at.to_s
32
+ end
33
+ end
34
+
35
+ # generate_constants returns a hash mapping component name to
36
+ # all of its constants.
37
+ def generate_constants
38
+ Ariadne::Component.descendants.sort_by(&:name).each_with_object({}) do |component, mem|
39
+ mem[component.to_s] = component.constants(false).sort.each_with_object({}) do |constant, h|
40
+ h[constant] = component.const_get(constant)
41
+ end
42
+ end
43
+ end
44
+
45
+ # dump generates the requested stat hash and outputs it to a file.
46
+ def dump(stats)
47
+ require "json"
48
+
49
+ File.open(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]), "w") do |f|
50
+ f.write(JSON.pretty_generate(send("generate_#{stats}")))
51
+ f.write($INPUT_RECORD_SEPARATOR)
52
+ end
53
+ end
54
+
55
+ # read returns a JSON string matching the output of the corresponding stat.
56
+ def read(stats)
57
+ File.read(File.join(DEFAULT_STATIC_PATH, FILE_NAMES[stats]))
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,8 @@
1
+ require:
2
+ - rubocop/cop/ariadne
3
+
4
+ AllCops:
5
+ DisabledByDefault: true
6
+
7
+ Ariadne/NoTagMemoize:
8
+ Enabled: true
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "ariadne/view_components/statuses"
5
+ require_relative "../../../../app/lib/ariadne/view_helper"
6
+
7
+ module RuboCop
8
+ module Cop
9
+ module Ariadne
10
+ # :nodoc:
11
+ class BaseCop < RuboCop::Cop::Cop
12
+ # We only verify SystemArguments if it's a `.new` call on a component or
13
+ # a ViewHeleper call.
14
+ def valid_node?(node)
15
+ return if node.nil?
16
+
17
+ view_helpers.include?(node.method_name) || (node.method_name == :new && !node.receiver.nil? && ::Ariadne::ViewComponents::STATUSES.key?(node.receiver.const_name))
18
+ end
19
+
20
+ private def view_helpers
21
+ ::Ariadne::ViewHelper::HELPERS.keys.map { |key| "ariadne_#{key}".to_sym }
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ # :nocov:
6
+ module RuboCop
7
+ module Cop
8
+ module Ariadne
9
+ # This cop ensures that tags are not set with ||=
10
+ #
11
+ # bad
12
+ # @attributes[:tag] ||= :h1
13
+ #
14
+ # good
15
+ # @attributes[:tag] = fetch_or_raise(TAG_OPTIONS, tag)
16
+ #
17
+ # good
18
+ # @attributes[:tag] = :h2
19
+ # TODO: TEST THIS
20
+ class NoTagMemoize < RuboCop::Cop::Cop
21
+ INVALID_MESSAGE = <<~STR
22
+ Avoid `[:tag] ||=`. Instead, try one of the following:
23
+ - Don't allow consumers to update the tag by having a fixed tag (e.g. `attributes[:tag] = :div`)
24
+ - Use the `fetch_or_raise` helper to only allow a tag from a restricted list.
25
+ STR
26
+
27
+ def_node_search :tag_memoized?, <<~PATTERN
28
+ (or-asgn
29
+ (send
30
+ _
31
+ _
32
+ (sym :tag)
33
+ )
34
+ _
35
+ )
36
+ PATTERN
37
+
38
+ def on_or_asgn(node)
39
+ add_offense(node, message: INVALID_MESSAGE) if tag_memoized?(node)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.join(__dir__, "ariadne", "*.rb")].sort.each { |file| require file }
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ ERB_GLOB = "**/*.html{+*,}.erb"
4
+ RB_GLOB = "**/*.rb"
5
+ # copied from Rails: action_view/template/handlers/erb/erubi.rb
6
+ BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
7
+
8
+ namespace :ariadne_view_components do
9
+ desc "Report arguments used in each component"
10
+ task :report, [:paths] do |_, args|
11
+ require "rubocop"
12
+ require "better_html"
13
+ require "better_html/parser"
14
+ require "erb_lint/processed_source"
15
+ require_relative "helpers/ast_processor"
16
+
17
+ paths = args[:paths].split
18
+ stats = {}
19
+
20
+ rb_files = paths.reduce([]) { |mem, path| mem + Dir[File.join(path, RB_GLOB)] }
21
+
22
+ rb_files.each do |f|
23
+ ast = RuboCop::AST::ProcessedSource.from_file(f, RUBY_VERSION.to_f).ast
24
+ AstProcessor.process_ast(ast, stats)
25
+ end
26
+
27
+ erb_files = paths.reduce([]) { |mem, path| mem + Dir[File.join(path, ERB_GLOB)] }
28
+
29
+ erb_files.each do |f|
30
+ erb_ast = ERBLint::ProcessedSource.new(f, File.read(f)).ast
31
+
32
+ erb_ast.descendants(:erb).each do |erb_node|
33
+ indicator, _, code_node, = *erb_node
34
+
35
+ next if indicator&.children&.first == "#" # don't analyze comments
36
+
37
+ trimmed_source = code_node.loc.source.sub(BLOCK_EXPR, "").strip
38
+ ast = RuboCop::AST::ProcessedSource.new(trimmed_source, RUBY_VERSION.to_f).ast
39
+ AstProcessor.process_ast(ast, stats)
40
+ end
41
+ end
42
+
43
+ File.open(".ariadne-view-components-report.json", "w") do |f|
44
+ f.write(JSON.pretty_generate(stats))
45
+ f.write($INPUT_RECORD_SEPARATOR)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ariadne/view_components/commands"
4
+
5
+ namespace :ariadne_view_components do
6
+ desc "Build Ariadne View Components CSS"
7
+ task :build do |_, args|
8
+ debug = args.extras.include?("debug")
9
+ command = Ariadne::ViewComponents::Commands.compile_command(debug: debug)
10
+ puts command.inspect
11
+ system(*command, exception: true)
12
+ end
13
+
14
+ desc "Watch and build Ariadne View Components CSS on file changes"
15
+ task :watch do |_, args|
16
+ debug = args.extras.include?("debug")
17
+ poll = args.extras.include?("poll")
18
+ command = Ariadne::ViewComponents::Commands.watch_command(debug: debug, poll: poll)
19
+ puts command.inspect
20
+ system(*command)
21
+ end
22
+ end
23
+
24
+ Rake::Task["assets:precompile"].enhance(["ariadne_view_components:build"]) if Rake::Task.task_defined?("assets:precompile")
25
+
26
+ if Rake::Task.task_defined?("test:prepare")
27
+ Rake::Task["test:prepare"].enhance(["ariadne_view_components:build"])
28
+ elsif Rake::Task.task_defined?("db:test:prepare")
29
+ Rake::Task["db:test:prepare"].enhance(["ariadne_view_components:build"])
30
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :coverage do
4
+ desc "Run coverage report. This should ideally be done only on CI."
5
+ task :report do
6
+ require "simplecov"
7
+ require "simplecov-console"
8
+
9
+ SimpleCov.minimum_coverage(100)
10
+
11
+ SimpleCov.collate(Dir["simplecov-resultset-*/.resultset.json"], "rails") do
12
+ formatter SimpleCov::Formatter::Console
13
+
14
+ add_group "Ignored Code" do |src_file|
15
+ File.readlines(src_file.filename).grep(/:nocov:/).any?
16
+ end
17
+ end
18
+ end
19
+ end