ariadne_view_components 0.0.44-aarch64-linux → 0.0.45-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6036aff6fecc3b3efed9691b3f1c0c4f2f3233200a0563bf967bf8d2e8ef8cd5
4
- data.tar.gz: 38f1b001bee0b05cbdd7511be65fa382a3f13dace776415d5a612377a9d5984e
3
+ metadata.gz: f7de52c3295c93acdb0b1b0980a52aab4e6dc80a3b084c99ec893ae3f1caf857
4
+ data.tar.gz: 07f2eb33b3ba853dcbee6e6a0100e7a271c6fb1b404196a99f0b1906ba5f1306
5
5
  SHA512:
6
- metadata.gz: cc397fa6dd66dd646a25eb6de0183393d9edebaebf527416ce8b16966cbc43ea69069409826dfb9110ae890f7d330d0ea77778be6807c78ca1e920f766248160
7
- data.tar.gz: 62979b1361328df14345f2c14a7a09ebe3e62bf167ad174fc80f5fb771555a9c0d68e99ce39860f17bbb617c5b55971bd41a147245e55b7c74c477bdfe703ff5
6
+ metadata.gz: 034c4b68b449c77f00e1fa7b858e8c393d0cbcc76227499918d3d51bb024fbbd0312970db19e783d39601aff6b37038ee14cc14cdcd5f8ec3ac7167902b96ebf
7
+ data.tar.gz: 6e7876d06433ba3d77f897b36ae6114ca66e89d7610a348e2ac4509b64aea964f2a40389d492d81cef6fbf81481ee1ff6d162f66514d92deddebcd30a83e6c5f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.44](https://github.com/yettoapp/ariadne/tree/v0.0.44) (2023-05-04)
4
+
5
+ [Full Changelog](https://github.com/yettoapp/ariadne/compare/v0.0.43...v0.0.44)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - build\(deps-dev\): bump @typescript-eslint/eslint-plugin from 5.59.1 to 5.59.2 [\#298](https://github.com/yettoapp/ariadne/pull/298) ([dependabot[bot]](https://github.com/apps/dependabot))
10
+ - \[auto-browserslist\] Update Browserslist db [\#296](https://github.com/yettoapp/ariadne/pull/296) ([sisyphusbot](https://github.com/sisyphusbot))
11
+
3
12
  ## [v0.0.43](https://github.com/yettoapp/ariadne/tree/v0.0.43) (2023-05-02)
4
13
 
5
14
  [Full Changelog](https://github.com/yettoapp/ariadne/compare/v0.0.42...v0.0.43)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ module ActionViewExtensions
5
+ # :nodoc:
6
+ module FormHelper
7
+ include ClassNameHelper
8
+
9
+ DEFAULT_FORM_CLASSES = "ariadne-space-y-8 sm:ariadne-space-y-5"
10
+ def ariadne_form_with(model: nil, scope: nil, url: nil, format: nil, classes: "", attributes: {}, **options, &block)
11
+ options[:class] = merge_class_names(DEFAULT_FORM_CLASSES, options[:class])
12
+ options[:builder] ||= Ariadne::FormBuilder
13
+ options[:html] = attributes
14
+
15
+ data_controller = options[:html].fetch(:"data-controller", "")
16
+ options[:html][:"data-controller"] = if data_controller.present?
17
+ "#{data_controller} ariadne-form"
18
+ else
19
+ "ariadne-form"
20
+ end
21
+
22
+ form_with(model: model, scope: scope, url: url, format: format, **options, &block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ ActiveSupport.on_load(:action_view) do
29
+ include Ariadne::ActionViewExtensions::FormHelper
30
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Ariadne
6
+ # :nodoc:
7
+ module Audited
8
+ # DSL to register when a component has passed an accessibility audit.
9
+ #
10
+ # Example:
11
+ #
12
+ # class MyComponent < ViewComponent::Base
13
+ # include Ariadne::Audited::Dsl
14
+ # audited_at 'YYYY-MM-DD'
15
+ # end
16
+ module Dsl
17
+ extend ActiveSupport::Concern
18
+
19
+ included do
20
+ class_attribute :audit_date, instance_writer: false
21
+ end
22
+
23
+ class_methods do
24
+ def audited_at(date = nil)
25
+ return audit_date if date.nil?
26
+
27
+ self.audit_date = date
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Helps build a list of conditional class names
4
+ module Ariadne
5
+ # :nodoc:
6
+ module ClassNameHelper
7
+ def merge_class_names(*args)
8
+ [].tap do |classes|
9
+ args.each do |class_name|
10
+ next if class_name.blank?
11
+
12
+ case class_name
13
+ when String
14
+ classes << class_name
15
+ else
16
+ raise ArgumentError, "Expected String class name, got #{class_name.class}"
17
+ end
18
+ end
19
+ end.join(" ")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ariadne::FetchOrFallbackHelper
4
+ # A little helper to enable graceful fallbacks
5
+ #
6
+ # Use this helper to quietly ensure a value is
7
+ # one that you expect:
8
+ #
9
+ # allowed_values - allowed options for *value*
10
+ # given_value - input being coerced
11
+ # fallback - returned if *given_value* is not included in *allowed_values*
12
+ #
13
+ # fetch_or_raise([1,2,3], 5) => 2
14
+ # fetch_or_raise([1,2,3], 1) => 1
15
+ # fetch_or_raise([1,2,3], nil) => 2
16
+ module Ariadne
17
+ # :nodoc:
18
+ module FetchOrFallbackHelper
19
+ include LoggerHelper
20
+
21
+ mattr_accessor :fallback_raises, default: true
22
+
23
+ InvalidValueError = Class.new(StandardError)
24
+
25
+ TRUE_OR_FALSE = Set.new([true, false]).freeze
26
+
27
+ INTEGER_TYPES = Set.new(["Integer"]).freeze
28
+
29
+ def fetch_or_raise(allowed_values, given_value, against: nil)
30
+ if !allowed_values.is_a?(Array) && !allowed_values.is_a?(Set)
31
+ raise ArgumentError, "allowed_values must be an array or a set; it was #{allowed_values.class}"
32
+ end
33
+
34
+ check_against_given_value = against || given_value
35
+ if allowed_values.include?(check_against_given_value)
36
+ given_value
37
+ else
38
+ raise InvalidValueError, <<~MSG
39
+ fetch_or_raise was called with an invalid value.
40
+
41
+ Expected one of: #{allowed_values.inspect}
42
+ Got: #{given_value.inspect}
43
+ MSG
44
+ end
45
+ end
46
+
47
+ # TODO: use these two more
48
+ def fetch_or_raise_boolean(given_value)
49
+ fetch_or_raise(TRUE_OR_FALSE, given_value)
50
+ end
51
+
52
+ def fetch_or_raise_integer(given_value)
53
+ fetch_or_raise(INTEGER_TYPES, given_value, against: given_value.class.name)
54
+ end
55
+
56
+ # TODO: test this
57
+ def check_incoming_tag(preferred_tag, given_tag)
58
+ return preferred_tag if given_tag.blank? || preferred_tag == given_tag
59
+
60
+ unless silence_warnings?
61
+ message = <<~MSG
62
+ Ariadne: note that `#{preferred_tag}` is the preferred tag here;
63
+ you passed `#{given_tag}` (which will still be used)
64
+ MSG
65
+
66
+ logger.warn(message)
67
+ end
68
+
69
+ given_tag
70
+ end
71
+
72
+ # TODO: test this
73
+ def check_incoming_attribute(preferred_attribute, given_attribute)
74
+ return preferred_attribute if given_attribute.blank? || preferred_attribute != given_attribute
75
+
76
+ unless silence_warnings?
77
+ message = <<~MSG
78
+ Ariadne: note that `#{preferred_attribute}` is the preferred attribute here;
79
+ you passed `#{given_attribute}` (which will still be used)
80
+ MSG
81
+
82
+ logger.warn(message)
83
+ end
84
+
85
+ given_attribute
86
+ end
87
+
88
+ # TODO: test this
89
+ def check_incoming_value(preferred_value, given_pair)
90
+ return preferred_value if given_pair.blank? || !given_pair.is_a?(Hash)
91
+
92
+ given_key = given_pair.keys.first
93
+ given_value = given_pair.values.first
94
+
95
+ return preferred_value if given_value.blank?
96
+
97
+ unless silence_warnings?
98
+
99
+ message = <<~MSG
100
+ Ariadne: note that `#{preferred_value}` is the preferred value for `#{given_key}` here;
101
+ you passed `#{given_value}` (which will still be used)
102
+ MSG
103
+
104
+ logger.warn(message)
105
+ end
106
+
107
+ given_value
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # :nodoc:
5
+ # Many of the form methods simply call out to the corresponding ActionView::Helpers::FormBuilder methods,
6
+ # documented at https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html, with
7
+ # default Tailwind classes applied.
8
+ class FormBuilder < ActionView::Helpers::FormBuilder
9
+ include ClassNameHelper
10
+
11
+ DEFAULT_SECTION_CLASSES = "ariadne-space-y-6 ariadne-px-4"
12
+ def section(classes: "", attributes: {}, &block)
13
+ actual_classes = merge_class_names(DEFAULT_SECTION_CLASSES, classes)
14
+ options = { class: actual_classes, **attributes }
15
+ @template.content_tag(:div, **options, &block)
16
+ end
17
+
18
+ DEFAULT_SECTION_HEADING_CLASSES = "ariadne-text-lg ariadne-leading-6 ariadne-py-4 ariadne-font-medium ariadne-text-gray-900"
19
+ def heading(tag: :h3, classes: "", attributes: {}, &block)
20
+ actual_classes = merge_class_names(DEFAULT_SECTION_HEADING_CLASSES, classes)
21
+ options = { class: actual_classes, **attributes }
22
+ @template.content_tag(tag, **options, &block)
23
+ end
24
+
25
+ DEFAULT_SECTION_SUBHEADING_CLASSES = "ariadne-mt-1 ariadne-max-w-2xl ariadne-text-sm ariadne-text-gray-500"
26
+ def subheading(classes: "", attributes: {}, &block)
27
+ actual_classes = merge_class_names(DEFAULT_SECTION_SUBHEADING_CLASSES, classes)
28
+ options = { class: actual_classes, **attributes }
29
+ @template.content_tag(:p, **options, &block)
30
+ end
31
+
32
+ DEFAULT_LABEL_CLASSES = "ariadne-block ariadne-text-sm ariadne-font-medium ariadne-text-gray-700 ariadne-pl-2"
33
+ def label(method, text = nil, options = {}, &block)
34
+ options[:class] = merge_class_names(DEFAULT_LABEL_CLASSES, options.delete(:classes))
35
+ super(method, text, options, &block)
36
+ end
37
+
38
+ DEFAULT_TEXT_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border-gray-300 ariadne-rounded-md"
39
+ def text_field(method, options = {})
40
+ options[:class] = merge_class_names(DEFAULT_TEXT_CLASSES, options.delete(:classes))
41
+ super(method, **options)
42
+ end
43
+
44
+ DEFAULT_CHECKBOX_CLASSES = "focus:ariadne-ring-slate-500 ariadne-h-4 ariadne-w-4 ariadne-text-slate-600 ariadne-border-slate-300 ariadne-rounded"
45
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
46
+ options[:class] = merge_class_names(DEFAULT_CHECKBOX_CLASSES, options.delete(:classes))
47
+ super(method, options, checked_value, unchecked_value)
48
+ end
49
+
50
+ DEFAULT_RADIO_CLASSES = "focus:ariadne-ring-slate-500 ariadne-h-4 ariadne-w-4 ariadne-text-slate-600 ariadne-border-gray-300 ariadne-rounded"
51
+ def radio_button(method, tag_value, options = {})
52
+ options[:class] = merge_class_names(DEFAULT_RADIO_CLASSES, options.delete(:classes))
53
+ super(method, tag_value, **options)
54
+ end
55
+
56
+ DEFAULT_TEXTAREA_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border ariadne-border-gray-300 ariadne-rounded-md"
57
+ def text_area(method, options = {})
58
+ options[:class] = merge_class_names(DEFAULT_TEXTAREA_CLASSES, options.delete(:classes))
59
+ super(method, **options)
60
+ end
61
+
62
+ DEFAULT_EMAIL_CLASSES = "ariadne-shadow-sm focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 ariadne-block ariadne-w-full sm:ariadne-text-sm ariadne-border-gray-300 ariadne-rounded-md"
63
+ def email_field(method, options = {})
64
+ options[:class] = merge_class_names(DEFAULT_EMAIL_CLASSES, options.delete(:classes))
65
+ super(method, **options)
66
+ end
67
+
68
+ DEFAULT_PASSWORD_CLASSES = "ariadne-appearance-none ariadne-block ariadne-w-full ariadne-px-3 ariadne-py-2 ariadne-border ariadne-border-gray-300 ariadne-rounded-md ariadne-shadow-sm ariadne-placeholder-gray-400 focus:ariadne-outline-none focus:ariadne-ring-slate-500 focus:ariadne-border-slate-500 sm:ariadne-text-sm"
69
+ def password_field(method, options = {})
70
+ options[:class] = merge_class_names(DEFAULT_PASSWORD_CLASSES, options.delete(:classes))
71
+ super(method, **options)
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ariadne::IconHelper
4
+ # A helper that insists on certain values when
5
+ # checking herocions and their varients.
6
+ #
7
+ # Use this helper to loudly ensure a value is
8
+ # one that you expect.
9
+ module Ariadne
10
+ # :nodoc:
11
+ module IconHelper
12
+ include FetchOrFallbackHelper
13
+
14
+ def check_icon_presence!(icon, variant)
15
+ return true unless has_partial_icon?(icon, variant)
16
+
17
+ icon_presence!(icon, variant)
18
+ variant_presence!(icon, variant)
19
+ ensure_valid_variant(variant)
20
+
21
+ true
22
+ end
23
+
24
+ def ensure_valid_variant(variant)
25
+ check_variant = if variant.blank? || !variant.respond_to?(:to_s)
26
+ ""
27
+ else
28
+ variant.to_s
29
+ end
30
+
31
+ fetch_or_raise(HeroiconsHelper::Icon::VALID_VARIANTS, check_variant)
32
+ end
33
+ module_function :ensure_valid_variant
34
+
35
+ def has_partial_icon?(icon, variant)
36
+ icon.present? || variant.present?
37
+ end
38
+
39
+ def icon_presence!(icon, variant)
40
+ raise(ArgumentError, "You must provide an `icon` when providing a `variant`.") if icon.blank? && variant.present?
41
+
42
+ true
43
+ end
44
+
45
+ def variant_presence!(icon, variant)
46
+ raise(ArgumentError, "You must provide a `variant` when providing an `icon`.") if icon.present? && variant.blank?
47
+
48
+ true
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # :nodoc:
5
+ module LoggerHelper
6
+ def logger
7
+ return Rails.logger if defined?(Rails) && Rails.logger
8
+
9
+ require "logger"
10
+ Logger.new($stderr)
11
+ end
12
+
13
+ # TODO: test
14
+ def silence_deprecations?
15
+ Rails.application.config.ariadne_view_components.silence_deprecations
16
+ end
17
+
18
+ # TODO: test
19
+ def silence_warnings?
20
+ Rails.application.config.ariadne_view_components.silence_warnings
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ module Ariadne
6
+ # :nodoc:
7
+ module Status
8
+ # DSL to allow components to register their status.
9
+ #
10
+ # Example:
11
+ #
12
+ # class MyComponent < ViewComponent::Base
13
+ # include Ariadne::Status::Dsl
14
+ # status :experimental
15
+ # end
16
+ module Dsl
17
+ extend ActiveSupport::Concern
18
+
19
+ STATUSES = {
20
+ experimental: :experimental,
21
+ stable: :stable,
22
+ }.freeze
23
+
24
+ class UnknownStatusError < StandardError; end
25
+
26
+ included do
27
+ class_attribute :component_status, instance_writer: false, default: STATUSES[:stable]
28
+ end
29
+
30
+ class_methods do
31
+ def status(status = nil)
32
+ return component_status if status.nil?
33
+
34
+ raise UnknownStatusError, "status #{status} does not exist" if STATUSES[status].nil?
35
+
36
+ self.component_status = STATUSES[status]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nocov:
4
+ module Ariadne
5
+ # Module to allow shorthand calls for Ariadne components
6
+ module ViewHelper
7
+ class ViewHelperNotFound < StandardError; end
8
+
9
+ HELPERS = {
10
+ heroicon: "Ariadne::HeroiconComponent",
11
+ heading: "Ariadne::HeadingComponent",
12
+ time_ago: "Ariadne::TimeAgoComponent",
13
+ image: "Ariadne::ImageComponent",
14
+ }.freeze
15
+
16
+ HELPERS.each do |name, component|
17
+ define_method "ariadne_#{name}" do |*args, **kwargs, &block|
18
+ render component.constantize.new(*args, **kwargs), &block
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,6 +3,6 @@
3
3
  # :nocov:
4
4
  module Ariadne
5
5
  module ViewComponents
6
- VERSION = "0.0.44"
6
+ VERSION = "0.0.45"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ariadne_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.44
4
+ version: 0.0.45
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Garen J. Torikian
@@ -222,6 +222,15 @@ files:
222
222
  - app/components/ariadne/tooltip_component/tooltip-component.js
223
223
  - app/components/ariadne/tooltip_component/tooltip-component.ts
224
224
  - app/components/ariadne/tooltip_component/tooltip_component.html.erb
225
+ - app/lib/ariadne/action_view_extensions/form_helper.rb
226
+ - app/lib/ariadne/audited/dsl.rb
227
+ - app/lib/ariadne/class_name_helper.rb
228
+ - app/lib/ariadne/fetch_or_fallback_helper.rb
229
+ - app/lib/ariadne/form_builder.rb
230
+ - app/lib/ariadne/icon_helper.rb
231
+ - app/lib/ariadne/logger_helper.rb
232
+ - app/lib/ariadne/status/dsl.rb
233
+ - app/lib/ariadne/view_helper.rb
225
234
  - config/importmap.rb
226
235
  - exe/aarch64-linux/tailwindcss
227
236
  - exe/tailwindcss