actionview-component 1.5.3 → 1.6.0

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: 00a684cf9aea1c6f1a94dd0c980fd7d1889e2b17fb165006817063de69b6f721
4
- data.tar.gz: 30766fd4333fb8d708369e48192b000ba4a5136898bd82e98273d5fc9445fb67
3
+ metadata.gz: e0d1497b59c35721a9d9c48906ca5b1a64eb30f72e9bfd17d0da2437820e7e87
4
+ data.tar.gz: e703a27db8cac4a589f6d8f78e3ffc2bb7783af16d7c49c8986d06db7155bcd4
5
5
  SHA512:
6
- metadata.gz: aeaf7ae830c1b2e099a974228c0c072c41481c9ddd0f000c488727066df837f872b9616f064962bc3e8adee2fd20d86e0894d97cbc1a6c049faa5b6eea4636b1
7
- data.tar.gz: ef32ebd537e7d36ae192b29b7aa756a8bf2efca96ef19d87e751e0dea11369616e0fc6e8a5848c2ea45230eb7eb46fac18e6e6eb6778ee58749193f22d3f2a44
6
+ metadata.gz: 481e35fdf095d48a1c3a33795d8e1d8b0be6a6b6944b149e5a6320add88f8748f4ea8e19282cd90bb62f9858291cd07084e9b1221051fcfb89f70b7dd6471281
7
+ data.tar.gz: 45fd087cc394799a8f21044c58de91a3aeee93dc29c8fbd8ff8c4a1979977bb86bc47d38341f51a37bbe93038c81b77908ec8d634d4d41b064a11585a684ae44
@@ -1,3 +1,33 @@
1
+ # v1.6.0
2
+
3
+ * Avoid dropping elements in the render_inline test helper.
4
+
5
+ *@dark-panda*
6
+
7
+ * Add test for helpers.asset_url.
8
+
9
+ *Christopher Coleman*
10
+
11
+ * Add rudimentary compatibility with better_html.
12
+
13
+ *Joel Hawksley*
14
+
15
+ * Template-less variants fall back to default template.
16
+
17
+ *Asger Behncke Jacobsen*, *Cesario Uy*
18
+
19
+ * Generated tests use new naming convention.
20
+
21
+ *Simon Træls Ravn*
22
+
23
+ * Eliminate sqlite dependency.
24
+
25
+ *Simon Dawson*
26
+
27
+ * Add support for rendering components via #to_component_class
28
+
29
+ *Vinicius Stock*
30
+
1
31
  # v1.5.3
2
32
 
3
33
  * Add support for RSpec to generators.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.5.3)
4
+ actionview-component (1.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -62,6 +62,14 @@ GEM
62
62
  tzinfo (~> 1.1)
63
63
  zeitwerk (~> 2.1, >= 2.1.8)
64
64
  ast (2.4.0)
65
+ better_html (1.0.14)
66
+ actionview (>= 4.0)
67
+ activesupport (>= 4.0)
68
+ ast (~> 2.0)
69
+ erubi (~> 1.4)
70
+ html_tokenizer (~> 0.0.6)
71
+ parser (>= 2.4)
72
+ smart_properties
65
73
  builder (3.2.3)
66
74
  concurrent-ruby (1.1.5)
67
75
  crass (1.0.5)
@@ -71,6 +79,7 @@ GEM
71
79
  haml (5.1.2)
72
80
  temple (>= 0.8.0)
73
81
  tilt
82
+ html_tokenizer (0.0.7)
74
83
  i18n (1.6.0)
75
84
  concurrent-ruby (~> 1.0)
76
85
  jaro_winkler (1.5.3)
@@ -139,6 +148,7 @@ GEM
139
148
  slim (4.0.1)
140
149
  temple (>= 0.7.6, < 0.9)
141
150
  tilt (>= 2.0.6, < 2.1)
151
+ smart_properties (1.15.0)
142
152
  sprockets (3.7.2)
143
153
  concurrent-ruby (~> 1.0)
144
154
  rack (> 1, < 3)
@@ -163,6 +173,7 @@ PLATFORMS
163
173
 
164
174
  DEPENDENCIES
165
175
  actionview-component!
176
+ better_html (~> 1)
166
177
  bundler (>= 1.14)
167
178
  haml (~> 5)
168
179
  minitest (= 5.1.0)
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  This gem is meant to serve as a precursor to upstreaming the `ActionView::Component` class into Rails. It also serves to enable the usage of `ActionView::Component` in older versions of Rails.
9
9
 
10
- Preliminary support for rendering components was merged into Rails `6.1.0.alpha` in https://github.com/rails/rails/pull/36388. Assuming `ActionView::Component` makes it into Rails `6.1`, this gem will then exist to serve as a backport.
10
+ Preliminary support for rendering components was merged into Rails `6.1.0.alpha` in https://github.com/rails/rails/pull/36388. Assuming `ActionView::Component` makes it into Rails, this gem will then exist to serve as a backport.
11
11
 
12
12
  ## Design philosophy
13
13
 
@@ -163,6 +163,24 @@ Components can be rendered via:
163
163
 
164
164
  `render(component: TestComponent, locals: { foo: :bar })`
165
165
 
166
+ **Rendering components through models**
167
+
168
+ Passing model instances will cause `render` to look for its respective component class.
169
+
170
+ The component is instantiated with the rendered model instance.
171
+
172
+ Example for a `Post` model:
173
+
174
+ `render(@post)`
175
+
176
+ ```ruby
177
+ class PostComponent < ActionView::Component
178
+ def initialize(post)
179
+ @post = post
180
+ end
181
+ end
182
+ ```
183
+
166
184
  The following syntax has been deprecated and will be removed in v2.0.0:
167
185
 
168
186
  `render(TestComponent.new(foo: :bar))`
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency "minitest", "= 5.1.0"
40
40
  spec.add_development_dependency "haml", "~> 5"
41
41
  spec.add_development_dependency "slim", "~> 4.0"
42
+ spec.add_development_dependency "better_html", "~> 1"
42
43
  spec.add_development_dependency "rubocop", "= 0.74"
43
44
  spec.add_development_dependency "rubocop-github", "~> 0.13.0"
44
45
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "action_view/component/monkey_patch"
4
+ require "action_view/component/active_model_conversion_monkey_patch"
4
5
  require "action_view/component/base"
5
6
  require "action_view/component/railtie"
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveModel
4
+ module Conversion
5
+ def to_component_class
6
+ "#{self.class.name}Component".safe_constantize
7
+ end
8
+ end
9
+ end
@@ -14,8 +14,6 @@ module ActionView
14
14
 
15
15
  delegate :form_authenticity_token, :protect_against_forgery?, to: :helpers
16
16
 
17
- validate :variant_exists
18
-
19
17
  # Entrypoint for rendering components. Called by ActionView::Base#render.
20
18
  #
21
19
  # view_context: ActionView context from calling view
@@ -94,12 +92,6 @@ module ActionView
94
92
 
95
93
  private
96
94
 
97
- def variant_exists
98
- return if self.class.variants.include?(@variant) || @variant.nil?
99
-
100
- errors.add(:variant, "'#{@variant}' has no template defined")
101
- end
102
-
103
95
  def request
104
96
  @request ||= controller.request
105
97
  end
@@ -114,7 +106,7 @@ module ActionView
114
106
  end
115
107
 
116
108
  def call_method_name(variant)
117
- if variant.present?
109
+ if variant.present? && variants.include?(variant)
118
110
  "call_#{variant}"
119
111
  else
120
112
  "call"
@@ -164,7 +156,7 @@ module ActionView
164
156
  end
165
157
 
166
158
  def identifier
167
- ""
159
+ source_location
168
160
  end
169
161
 
170
162
  private
@@ -17,6 +17,8 @@ class ActionView::Base
17
17
  options.new(args).render_in(self, &block)
18
18
  elsif options.is_a?(Hash) && options.has_key?(:component)
19
19
  options[:component].new(options[:locals]).render_in(self, &block)
20
+ elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil?
21
+ options.to_component_class.new(options).render_in(self, &block)
20
22
  else
21
23
  super
22
24
  end
@@ -4,7 +4,7 @@ module ActionView
4
4
  module Component
5
5
  module TestHelpers
6
6
  def render_inline(component, **args, &block)
7
- Nokogiri::HTML(controller.view_context.render(component, args, &block)).css("body > *")
7
+ Nokogiri::HTML.fragment(controller.view_context.render(component, args, &block))
8
8
  end
9
9
 
10
10
  def controller
@@ -4,8 +4,8 @@ module ActionView
4
4
  module Component
5
5
  module VERSION
6
6
  MAJOR = 1
7
- MINOR = 5
8
- PATCH = 3
7
+ MINOR = 6
8
+ PATCH = 0
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH].join(".")
11
11
  end
@@ -6,7 +6,7 @@ class <%= class_name %>ComponentTest < ActiveSupport::TestCase
6
6
  test "component renders something useful" do
7
7
  # assert_equal(
8
8
  # %(<span title="my title">Hello, components!</span>),
9
- # render_inline(<%= class_name %>, attr: "value") { "Hello, components!" }.css("span").to_html
9
+ # render_inline(<%= class_name %>Component, attr: "value") { "Hello, components!" }.css("span").to_html
10
10
  # )
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: better_html
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +142,7 @@ files:
128
142
  - Rakefile
129
143
  - actionview-component.gemspec
130
144
  - lib/action_view/component.rb
145
+ - lib/action_view/component/active_model_conversion_monkey_patch.rb
131
146
  - lib/action_view/component/base.rb
132
147
  - lib/action_view/component/monkey_patch.rb
133
148
  - lib/action_view/component/preview.rb