elemental_components 1.0.0.rc2 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 188ba4f31148a5b63a6bedc1d45471216563c5b50137c575e1846a8a319807fc
4
- data.tar.gz: 04a1af8dfe65532e07bdef3cbeb62c1e94faf6c7f9fabb4e940504215e80e3b1
3
+ metadata.gz: 140e8e6085779745ad5a7bfc3b61aab1f3b0754bd05b90f5c5890176f1fd9934
4
+ data.tar.gz: 6aeb44e4f571905edff448524738b73b39682907900dc0576dedb114931aa52e
5
5
  SHA512:
6
- metadata.gz: abd7a702a6030f480b384100a684c8e7cf841c5fcda44314c3d55e75236991c5a20d5c0042721bf446a6fdb3244253322f12aa1a4cd8b52bdc99a0b1dee8bbb4
7
- data.tar.gz: f30734ef9349f9baaa9f86b35dc6d865e0bbb64a4a380616db9ca5e9d47a7ace0ccf1aaee3c0943f4f9466be5524a7c48c98508c2680310a3a25937e58d73b6b
6
+ metadata.gz: 252b44e941c1b6bd10e38c1ef5b4fd217674819ccc818e071b7f32965a74a64aebe36b299997706fa60ed70c0198aa1626c813611133c89b5845dcf40299b4c6
7
+ data.tar.gz: 1f11fed00fae502454922d217dd9d5c4eff4f5f439744ea745ec855283d6bb1c0aca5b06892227285c1744989a06c53f4464035be4c080a7f5f24efe12f966fb
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Elemental Components
2
2
 
3
- Simple view components for Rails 5.1+, designed to go well with [elemental_styleguide](https://github.com/jensljungblad/elemental_styleguide). The two together are inspired by the works of [Brad Frost](http://bradfrost.com) and by the [thoughts behind](http://engineering.lonelyplanet.com/2014/05/18/a-maintainable-styleguide.html) Lonely Planet's style guide [Rizzo](http://rizzo.lonelyplanet.com).
3
+ Simple view components for Rails 7.2+, designed to go well with [elemental_styleguide](https://github.com/jensljungblad/elemental_styleguide). The two together are inspired by the works of [Brad Frost](http://bradfrost.com) and by the [thoughts behind](http://engineering.lonelyplanet.com/2014/05/18/a-maintainable-styleguide.html) Lonely Planet's style guide [Rizzo](http://rizzo.lonelyplanet.com).
4
4
 
5
5
  ## Installation
6
6
 
@@ -34,11 +34,10 @@ app/
34
34
  alert/
35
35
  _alert.html.erb
36
36
  alert.css
37
- alert.js
38
37
  alert_component.rb
39
38
  ```
40
39
 
41
- The generator also takes `--skip-css` and `--skip-js` options.
40
+ The generator also takes `--skip-css` and `--skip-erb` options.
42
41
 
43
42
  Let's add some markup and CSS:
44
43
 
@@ -78,7 +77,9 @@ This component can now be rendered using the `component` helper:
78
77
 
79
78
  ### Assets
80
79
 
81
- In order to require assets such as CSS, either require them manually in the manifest, e.g. `application.css`:
80
+ The `app/components` directory is automatically added to `Rails.application.config.assets.paths` which means CSS assets can be referenced, regardless if you are using sprockets or propshaft.
81
+
82
+ If using sprockets, require in i.e. `application.css`:
82
83
 
83
84
  ```css
84
85
  /*
@@ -86,12 +87,10 @@ In order to require assets such as CSS, either require them manually in the mani
86
87
  */
87
88
  ```
88
89
 
89
- Or require `components`, which will in turn require the assets for all components:
90
+ If using propshaft, import in i.e. `application.css`:
90
91
 
91
92
  ```css
92
- /*
93
- *= require elemental_components
94
- */
93
+ @import url("alert/alert");
95
94
  ```
96
95
 
97
96
  ### Attributes and content blocks
@@ -316,7 +315,7 @@ Another good use case is a navigation component:
316
315
  # app/components/navigation_component.rb %>
317
316
 
318
317
  class NavigationComponent < ElementalComponents::Component
319
- element :items, multiple: true do
318
+ element :item, multiple: true do
320
319
  attribute :label
321
320
  attribute :url
322
321
  attribute :active, default: false
@@ -331,12 +330,6 @@ end
331
330
  <% end %>
332
331
  ```
333
332
 
334
- An alternative here is to pass a data structure to the component as an attribute, if no HTML needs to be injected when rendering the component:
335
-
336
- ```erb
337
- <%= component "navigation", items: items %>
338
- ```
339
-
340
333
  Elements can have validations, too:
341
334
 
342
335
  ```ruby
@@ -2,8 +2,8 @@
2
2
 
3
3
  module ElementalComponents
4
4
  module ComponentHelper
5
- def component(name, attrs = nil, &block)
6
- "#{name}_component".classify.constantize.new(self, attrs, &block).render
5
+ def component(name, attrs = nil, &)
6
+ "#{name}_component".classify.constantize.new(self, attrs, &).render
7
7
  end
8
8
  end
9
9
  end
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  ElementalComponents::Engine.routes.draw do
4
+ # No routes defined
4
5
  end
@@ -58,20 +58,20 @@ module ElementalComponents
58
58
  # rubocop:enable Metrics/MethodLength
59
59
  # rubocop:enable Metrics/PerceivedComplexity
60
60
 
61
- def self.define_method_or_raise(method_name, &block)
61
+ def self.define_method_or_raise(method_name, &)
62
62
  if method_defined?(method_name.to_sym)
63
63
  raise(ElementalComponents::Error, "Method '#{method_name}' already exists.")
64
64
  end
65
65
 
66
- define_method(method_name, &block)
66
+ define_method(method_name, &)
67
67
  end
68
68
  private_class_method :define_method_or_raise
69
69
 
70
- def initialize(view, attributes = nil, &block)
70
+ def initialize(view, attributes = nil, &)
71
71
  @view = view
72
72
  initialize_attributes(attributes || {})
73
73
  initialize_elements
74
- @yield = block_given? ? @view.capture(self, &block) : nil
74
+ @yield = block_given? ? @view.capture(self, &) : nil
75
75
  validate!
76
76
  end
77
77
 
@@ -87,10 +87,16 @@ module ElementalComponents
87
87
 
88
88
  def initialize_attributes(attributes)
89
89
  self.class.attributes.each do |name, options|
90
- set_instance_variable(name, attributes[name] || (options[:default] && options[:default].dup))
90
+ set_instance_variable(name, attribute_value(attributes, name, options[:default]))
91
91
  end
92
92
  end
93
93
 
94
+ def attribute_value(attributes, name, default)
95
+ return attributes[name] if attributes.key?(name)
96
+
97
+ default.dup
98
+ end
99
+
94
100
  def initialize_elements
95
101
  self.class.elements.each do |name, options|
96
102
  if (plural_name = options[:multiple])
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElementalComponents
4
- VERSION = "1.0.0.rc2"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -5,7 +5,6 @@ module ElementalComponents
5
5
  desc "Generate a component"
6
6
  class_option :skip_erb, type: :boolean, default: false
7
7
  class_option :skip_css, type: :boolean, default: false
8
- class_option :skip_js, type: :boolean, default: false
9
8
 
10
9
  source_root File.expand_path("templates", __dir__)
11
10
 
@@ -25,12 +24,6 @@ module ElementalComponents
25
24
  create_file "app/components/#{name}/#{filename}.css"
26
25
  end
27
26
 
28
- def create_js_file
29
- return if options["skip_js"]
30
-
31
- create_file "app/components/#{name}/#{filename}.js"
32
- end
33
-
34
27
  private
35
28
 
36
29
  def filename
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elemental_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Ljungblad
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rails
@@ -16,57 +15,15 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 5.1.0
18
+ version: 7.2.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 5.1.0
27
- - !ruby/object:Gem::Dependency
28
- name: appraisal
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.74.0
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.74.0
55
- - !ruby/object:Gem::Dependency
56
- name: sqlite3
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.4.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 1.4.0
69
- description: Simple view components for Rails 5.1+
25
+ version: 7.2.0
26
+ description: Simple view components for Rails 7.2+
70
27
  email:
71
28
  - jens.ljungblad@gmail.com
72
29
  executables: []
@@ -76,9 +33,6 @@ files:
76
33
  - MIT-LICENSE
77
34
  - README.md
78
35
  - Rakefile
79
- - app/assets/config/elemental_components_manifest.js
80
- - app/assets/javascripts/elemental_components.js.erb
81
- - app/assets/stylesheets/elemental_components.css.erb
82
36
  - app/helpers/elemental_components/component_helper.rb
83
37
  - config/routes.rb
84
38
  - lib/elemental_components.rb
@@ -93,8 +47,8 @@ files:
93
47
  homepage: https://www.github.com/jensljungblad/elemental_components
94
48
  licenses:
95
49
  - MIT
96
- metadata: {}
97
- post_install_message:
50
+ metadata:
51
+ rubygems_mfa_required: 'true'
98
52
  rdoc_options: []
99
53
  require_paths:
100
54
  - lib
@@ -102,16 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
56
  requirements:
103
57
  - - ">="
104
58
  - !ruby/object:Gem::Version
105
- version: '0'
59
+ version: 3.1.0
106
60
  required_rubygems_version: !ruby/object:Gem::Requirement
107
61
  requirements:
108
- - - ">"
62
+ - - ">="
109
63
  - !ruby/object:Gem::Version
110
- version: 1.3.1
64
+ version: '0'
111
65
  requirements: []
112
- rubyforge_project:
113
- rubygems_version: 2.7.6
114
- signing_key:
66
+ rubygems_version: 3.7.2
115
67
  specification_version: 4
116
- summary: Simple view components for Rails 5.1+
68
+ summary: Simple view components for Rails 7.2+
117
69
  test_files: []
@@ -1,2 +0,0 @@
1
- //= link_directory ../javascripts/elemental_components .js
2
- //= link_directory ../stylesheets/elemental_components .css
@@ -1,7 +0,0 @@
1
- <% ElementalComponents.component_names.each do |name| %>
2
- <% begin %>
3
- <% require_asset "#{name}/#{name.split('/')[-1]}" %>
4
- <% rescue Sprockets::FileNotFound %>
5
- <% Rails.logger.debug "ElementalComponents: JS not found for #{name}" %>
6
- <% end %>
7
- <% end %>
@@ -1,7 +0,0 @@
1
- <% ElementalComponents.component_names.each do |name| %>
2
- <% begin %>
3
- <% require_asset "#{name}/#{name.split('/')[-1]}" %>
4
- <% rescue Sprockets::FileNotFound %>
5
- <% Rails.logger.debug "ElementalComponents: CSS not found for #{name}" %>
6
- <% end %>
7
- <% end %>