optics_view_components 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a06b9454efef278cd56ab9a178e0aa4567f01db54119ad83e7d972c5a2fa232f
4
- data.tar.gz: 3f0d0d5559526ba23baa50e88a4c84c4a38870e602013db702f1588be94d67e3
3
+ metadata.gz: 4a96cbd214ce4d3eb339e032c1c04ccc3435751f2618e5b41f9175114fd8e7de
4
+ data.tar.gz: 5d7edae41972ec1d189827dcdb71bdf0859cd26c7164f2de992ba282fc37df95
5
5
  SHA512:
6
- metadata.gz: 872cb462157bc5b9bcf7e610aafdb91eb2a125c042e7e9049ed38ced9f0750e54e6c8da305c8b568663bea3b3b56b72e0c8902df14758a8cfced1d3baefb8688
7
- data.tar.gz: c66b0e6b482134588976015aaabdec6997c763b54460d28215b03cfb31524eda90c2825b4f4488559a84b40707f035191fa1f31450d4fbed449dbb2fad9f7f36
6
+ metadata.gz: 9dc9e7910cdd85f698f9080704e2b16f5b8bc38e78509ddca578d7c8a4b35f9df810b06a04d6f19fe51471a81baaad88f9518a45d2091956c074117b042eaf04
7
+ data.tar.gz: fa393926ee1c68a2e14a6795f8b01c8a815aa0f324227e55df5df030e03afda1414c0cced29f4f632e56327ab5478e3925ff3315fecb3de8bc273f706a3e6ecb
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
+ SuggestExtensions: false
3
4
  TargetRubyVersion: 3.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optics_view_components (0.1.0)
4
+ optics_view_components (0.1.1)
5
5
  view_component (> 2.0, < 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -14,7 +14,17 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
14
 
15
15
  ## Usage
16
16
 
17
- TODO: Write usage instructions here
17
+ Add to `config/application.rb`:
18
+
19
+ ```
20
+ require 'optics/view_components'
21
+ require 'optics/view_components/engine'
22
+ ```
23
+
24
+ Use in a view:
25
+ ```
26
+ <%= render(Optics::Button::Component.new(label: 'Hello')) %>
27
+ ```
18
28
 
19
29
  ## Development
20
30
 
data/Rakefile CHANGED
@@ -7,6 +7,8 @@ RSpec::Core::RakeTask.new(:spec)
7
7
 
8
8
  require 'rubocop/rake_task'
9
9
 
10
- RuboCop::RakeTask.new
10
+ RuboCop::RakeTask.new(:rubocop) do |t|
11
+ t.options = ['--fail-level', 'warning', '--display-only-fail-level-offenses']
12
+ end
11
13
 
12
14
  task default: %i[spec rubocop]
@@ -1,112 +1,116 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Optics::ApplicationViewComponent < ViewComponent::Base
4
- class_attribute :optional_attributes, default: {}
5
- class_attribute :required_attributes, default: {}
3
+ module Optics
4
+ class ApplicationViewComponent < ViewComponent::Base
5
+ class_attribute :optional_attributes, default: {}
6
+ class_attribute :required_attributes, default: {}
6
7
 
7
- class << self
8
- # To allow DB queries, put this in the class definition:
9
- # self.allow_db_queries = true
10
- attr_accessor :allow_db_queries
11
- alias allow_db_queries? allow_db_queries
8
+ class << self
9
+ # To allow DB queries, put this in the class definition:
10
+ # self.allow_db_queries = true
11
+ attr_accessor :allow_db_queries
12
+ alias allow_db_queries? allow_db_queries
12
13
 
13
- def requires(parameter, default: nil)
14
- required_attributes[parameter] = default
14
+ def requires(parameter, default: nil)
15
+ required_attributes[parameter] = default
15
16
 
16
- attr_reader parameter
17
- end
17
+ attr_reader parameter
18
+ end
18
19
 
19
- def accepts(parameter, default: nil)
20
- optional_attributes[parameter] = default
20
+ def accepts(parameter, default: nil)
21
+ optional_attributes[parameter] = default
21
22
 
22
- attr_reader parameter
23
+ attr_reader parameter
24
+ end
25
+
26
+ def inherited(subclass)
27
+ subclass.optional_attributes = optional_attributes.dup
28
+ subclass.required_attributes = required_attributes.dup
29
+ super
30
+ end
23
31
  end
24
32
 
25
- def inherited(subclass)
26
- subclass.optional_attributes = optional_attributes.dup
27
- subclass.required_attributes = required_attributes.dup
33
+ def initialize(**attributes)
28
34
  super
29
- end
30
- end
31
35
 
32
- def initialize(**attributes)
33
- initialize_instance_variables(required_attributes, attributes) do |key, _default|
34
- raise ArgumentError, "Missing keyword: :#{key}"
35
- end
36
+ initialize_instance_variables(required_attributes, attributes) do |key, _default|
37
+ raise ArgumentError, "Missing keyword: :#{key}"
38
+ end
36
39
 
37
- initialize_instance_variables(optional_attributes, attributes) do |key, default|
38
- instance_variable_set("@#{key}", default)
39
- end
40
+ initialize_instance_variables(optional_attributes, attributes) do |key, default|
41
+ instance_variable_set("@#{key}", default)
42
+ end
40
43
 
41
- @attributes = attributes.except(*optional_attributes.keys, *required_attributes.keys)
42
- end
44
+ @attributes = attributes.except(*optional_attributes.keys, *required_attributes.keys)
45
+ end
43
46
 
44
- def class_for(name)
45
- "c--#{identifier}--#{name}"
46
- end
47
+ def class_for(name)
48
+ "c--#{identifier}--#{name}"
49
+ end
47
50
 
48
- def container_class
49
- "c--#{identifier}"
50
- end
51
+ def container_class
52
+ "c--#{identifier}"
53
+ end
51
54
 
52
- def class_names_for(*args)
53
- class_names(*args).map { |name| class_for(name) }.join(' ')
54
- end
55
+ def class_names_for(*args)
56
+ class_names(*args).map { |name| class_for(name) }.join(' ')
57
+ end
55
58
 
56
- # Inspired by https://github.com/primer/view_components/blob/v0.1.9/app/lib/primer/class_name_helper.rb#L9
57
- def class_names(*args) # rubocop:disable Metrics/MethodLength
58
- [].tap do |classes|
59
- args.each do |class_name|
60
- case class_name
61
- when String
62
- classes << class_name
63
- when Hash
64
- class_name.each do |key, val|
65
- classes << key if val
59
+ # Inspired by https://github.com/primer/view_components/blob/v0.1.9/app/lib/primer/class_name_helper.rb#L9
60
+ def class_names(*args) # rubocop:disable Metrics/MethodLength
61
+ [].tap do |classes|
62
+ args.each do |class_name|
63
+ case class_name
64
+ when String
65
+ classes << class_name
66
+ when Hash
67
+ class_name.each do |key, val|
68
+ classes << key if val
69
+ end
66
70
  end
67
71
  end
68
- end
69
72
 
70
- classes.compact!
71
- classes.uniq!
73
+ classes.compact!
74
+ classes.uniq!
75
+ end
72
76
  end
73
- end
74
77
 
75
- # Used by Stimulus. E.g. data-controller=identifier => data-controller='dynamic-form--field'
76
- def identifier
77
- @identifier ||= self.class.name.sub('::Component', '').underscore.gsub('_', '-').gsub('/', '--')
78
- end
78
+ # Used by Stimulus. E.g. data-controller=identifier => data-controller='dynamic-form--field'
79
+ def identifier
80
+ @identifier ||= self.class.name.sub('::Component', '').underscore.gsub('_', '-').gsub('/', '--')
81
+ end
79
82
 
80
- # Helper for Stimulus data attributes
81
- def data_for(method:, target:)
82
- data_method(method).merge(data_target(target))
83
- end
83
+ # Helper for Stimulus data attributes
84
+ def data_for(method:, target:)
85
+ data_method(method).merge(data_target(target))
86
+ end
84
87
 
85
- # Helper for Stimulus controller method
86
- def data_method(method, event: 'click')
87
- { action: "#{event}->#{identifier}##{method}" }
88
- end
88
+ # Helper for Stimulus controller method
89
+ def data_method(method, event: 'click')
90
+ { action: "#{event}->#{identifier}##{method}" }
91
+ end
89
92
 
90
- # Helper for Stimulus controller target
91
- def data_target(target)
92
- { "#{identifier}": { target: } }
93
- end
93
+ # Helper for Stimulus controller target
94
+ def data_target(target)
95
+ { "#{identifier}": { target: } }
96
+ end
94
97
 
95
- # Helper for Stimulus controller value
96
- def data_values(values)
97
- values.transform_keys do |key|
98
- "#{identifier}-#{key}-value"
98
+ # Helper for Stimulus controller value
99
+ def data_values(values)
100
+ values.transform_keys do |key|
101
+ "#{identifier}-#{key}-value"
102
+ end
99
103
  end
100
- end
101
104
 
102
- private
105
+ private
103
106
 
104
- def initialize_instance_variables(configured_attributes, attributes)
105
- configured_attributes.each do |key, default|
106
- if attributes.key?(key)
107
- instance_variable_set("@#{key}", attributes[key])
108
- else
109
- yield(key, default)
107
+ def initialize_instance_variables(configured_attributes, attributes)
108
+ configured_attributes.each do |key, default|
109
+ if attributes.key?(key)
110
+ instance_variable_set("@#{key}", attributes[key])
111
+ else
112
+ yield(key, default)
113
+ end
110
114
  end
111
115
  end
112
116
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Optics::ApplicationViewComponentPreview < ViewComponent::Preview
4
- include ApplicationHelper
3
+ module Optics
4
+ class ApplicationViewComponentPreview < ViewComponent::Preview
5
+ include ApplicationHelper
6
+ end
5
7
  end
@@ -19,8 +19,10 @@ module Optics
19
19
 
20
20
  def call
21
21
  build_button do
22
- leading_icon
23
- label
22
+ capture do
23
+ concat leading_icon
24
+ concat label
25
+ end
24
26
  end
25
27
  end
26
28
 
@@ -11,14 +11,14 @@ module Optics
11
11
  # @param variant select {{ ::Button::Component::STYLES }}
12
12
  # @param url text
13
13
  def default( # rubocop:disable Metrics/ParameterLists
14
- border: true,
15
- icon: false,
16
- id: nil,
17
- label: 'Default',
18
- size: 'normal',
19
- variant: 'default',
20
- url: nil
21
- )
14
+ border: true,
15
+ icon: false,
16
+ id: nil,
17
+ label: 'Default',
18
+ size: 'normal',
19
+ variant: 'default',
20
+ url: nil
21
+ )
22
22
  render(Button::Component.new(
23
23
  border:,
24
24
  icon:,
@@ -26,7 +26,7 @@ module Optics
26
26
  label:,
27
27
  size:,
28
28
  variant:,
29
- url:,
29
+ url:
30
30
  ))
31
31
  end
32
32
  end
@@ -1,31 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Icon
4
- class Preview < ViewComponent::Preview
5
- # @param emphasis select {{ ::Icon::Component::EMPHASES }}
6
- # @param filled toggle
7
- # @param name
8
- # @param size select {{ ::Icon::Component::SIZES }}
9
- # @param title
10
- # @param weight select {{ ::Icon::Component::WEIGHTS }}
11
- def default( # rubocop:disable Metrics/ParameterLists
12
- emphasis: 'normal',
13
- filled: false,
14
- name: 'settings',
15
- size: 'normal',
16
- title: nil,
17
- weight: 'normal'
18
- )
19
- render(
20
- Icon::Component.new(
21
- emphasis:,
22
- filled:,
23
- name:,
24
- size:,
25
- title:,
26
- weight:
27
- )
3
+ module Optics
4
+ module Icon
5
+ class Preview < ViewComponent::Preview
6
+ # @param emphasis select {{ ::Icon::Component::EMPHASES }}
7
+ # @param filled toggle
8
+ # @param name
9
+ # @param size select {{ ::Icon::Component::SIZES }}
10
+ # @param title
11
+ # @param weight select {{ ::Icon::Component::WEIGHTS }}
12
+ def default( # rubocop:disable Metrics/ParameterLists
13
+ emphasis: 'normal',
14
+ filled: false,
15
+ name: 'settings',
16
+ size: 'normal',
17
+ title: nil,
18
+ weight: 'normal'
28
19
  )
20
+ render(
21
+ Icon::Component.new(
22
+ emphasis:,
23
+ filled:,
24
+ name:,
25
+ size:,
26
+ title:,
27
+ weight:
28
+ )
29
+ )
30
+ end
29
31
  end
30
32
  end
31
33
  end
data/demo/Gemfile CHANGED
@@ -18,4 +18,3 @@ end
18
18
  group :development do
19
19
  gem 'web-console'
20
20
  end
21
-
data/demo/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- optics_view_components (0.1.0)
4
+ optics_view_components (0.1.1)
5
5
  view_component (> 2.0, < 4.0)
6
6
 
7
7
  GEM
@@ -89,9 +89,6 @@ GEM
89
89
  activesupport (>= 5.0)
90
90
  i18n (1.13.0)
91
91
  concurrent-ruby (~> 1.0)
92
- importmap-rails (1.1.6)
93
- actionpack (>= 6.0.0)
94
- railties (>= 6.0.0)
95
92
  io-console (0.6.0)
96
93
  irb (1.6.4)
97
94
  reline (>= 0.3.0)
@@ -187,7 +184,6 @@ DEPENDENCIES
187
184
  bootsnap
188
185
  cssbundling-rails (~> 1.1)
189
186
  debug
190
- importmap-rails
191
187
  optics_view_components!
192
188
  puma (~> 6.0)
193
189
  rails (~> 7.0.4, >= 7.0.4.3)
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class HomeController < ApplicationController
2
- def index
3
- end
4
+ def index; end
4
5
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Optics
4
4
  module ViewComponents
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optics_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reed Law