actionview-component 1.2.1 → 1.3.4

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: 88f41dda27814dde34bc2c802388e04ff4e96d02cd107b455406583d19fe93ee
4
- data.tar.gz: 4f968af602146f71ec2749455090c80db72099e0668f2961520cdf9918924ecd
3
+ metadata.gz: 03a3c04aa78f3fcc16c350b49955870f60e712ad0383eb924e7053d7208431d0
4
+ data.tar.gz: 299741730bcfe4eb6640e5899e3973d4fd303dc28aadc79103eb72bdcd2382ec
5
5
  SHA512:
6
- metadata.gz: 5076c4abed4915eb568eb423918ce9a8c66af85f1290a7a1c6ec7858d82db515e6731f66b0135ad8208ae6cf7da5ca554b45faa12cad09487b1516cc25a09709
7
- data.tar.gz: a4d4040ae40657644b51971393b9ba0de2e4df7bfb47fbeb685f49fc1526d92bd15a2aa542be952b04aeb7b986d2b74a4568fc2cda9a3a82470cef6f1c05c947
6
+ metadata.gz: '01091f9da0436fcbfcbdfd602bcf7595c9c061738f49b9fb70305474218b6b928382daed58c4a3ebc1d08991815ecc965cc6a19b8c4384c35338d672ee5b456e'
7
+ data.tar.gz: 32fae5a27cb1f1f939ce5b59947b3785f1b4ee73a8e9b3b1a95eb1351800aa005518b61b6f24d8570790c1e45d128bf87ab28e4f14cecac1479d33a4ed30a524
@@ -1,6 +1,6 @@
1
1
  name: Ruby on Rails
2
2
 
3
- on: [push]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
@@ -1,3 +1,37 @@
1
+ # v1.3.4
2
+
3
+ * Template errors surface correct file and line number.
4
+
5
+ *Justin Coyne*
6
+
7
+ * Allow access to `request` inside components.
8
+
9
+ *Joel Hawksley*
10
+
11
+ # v1.3.3
12
+
13
+ * Do not raise error when sidecar files that are not templates exist.
14
+
15
+ *Joel Hawksley*
16
+
17
+ # v1.3.2
18
+
19
+ * Support rendering views from inside component templates.
20
+
21
+ *Patrick Sinclair*
22
+
23
+ # v1.3.1
24
+
25
+ * Fix bug where rendering nested content caused an error.
26
+
27
+ *Joel Hawksley, Aaron Patterson*
28
+
29
+ # v1.3.0
30
+
31
+ * Components are rendered with enough controller context to support rendering of partials and forms.
32
+
33
+ *Patrick Sinclair, Joel Hawksley, Aaron Patterson*
34
+
1
35
  # v1.2.1
2
36
 
3
37
  * `actionview-component` is now tested against Ruby 2.3/2.4 and Rails 5.0.0.
@@ -32,6 +32,7 @@ Here are a few things you can do that will increase the likelihood of your pull
32
32
  If you are the current maintainer of this gem:
33
33
 
34
34
  1. Create a branch for the release: `git checkout -b release-vxx.xx.xx`
35
+ 1. Bump gem version in `actionview-component.gemspec`.
35
36
  1. Make sure your local dependencies are up to date: `bundle`
36
37
  1. Ensure that tests are green: `bundle exec rake`
37
38
  1. Build a test gem `GEM_VERSION=$(git describe --tags 2>/dev/null | sed 's/-/./g' | sed 's/v//') gem build actionview-component.gemspec`
@@ -39,7 +40,6 @@ If you are the current maintainer of this gem:
39
40
  1. Bump the Gemfile and Gemfile.lock versions for an app which relies on this gem
40
41
  1. Install the new gem locally
41
42
  1. Test behavior locally, branch deploy, whatever needs to happen
42
- 1. Bump gem version in `actionview-component.gemspec`.
43
43
  1. Make a PR to github/actionview-component.
44
44
  1. Build a local gem: `gem build actionview-component.gemspec`
45
45
  1. Merge github/actionview-component PR
data/Gemfile CHANGED
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
- rails_version = "#{ENV['RAILS_VERSION'] || '5.2.3'}"
6
+ rails_version = "#{ENV['RAILS_VERSION'] || '6.0.0'}"
7
7
 
8
8
  gem "rails", rails_version == "master" ? { github: "rails/rails" } : rails_version
@@ -1,53 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-component (1.2.1)
4
+ actionview-component (1.3.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actioncable (5.2.3)
10
- actionpack (= 5.2.3)
9
+ actioncable (6.0.0)
10
+ actionpack (= 6.0.0)
11
11
  nio4r (~> 2.0)
12
12
  websocket-driver (>= 0.6.1)
13
- actionmailer (5.2.3)
14
- actionpack (= 5.2.3)
15
- actionview (= 5.2.3)
16
- activejob (= 5.2.3)
13
+ actionmailbox (6.0.0)
14
+ actionpack (= 6.0.0)
15
+ activejob (= 6.0.0)
16
+ activerecord (= 6.0.0)
17
+ activestorage (= 6.0.0)
18
+ activesupport (= 6.0.0)
19
+ mail (>= 2.7.1)
20
+ actionmailer (6.0.0)
21
+ actionpack (= 6.0.0)
22
+ actionview (= 6.0.0)
23
+ activejob (= 6.0.0)
17
24
  mail (~> 2.5, >= 2.5.4)
18
25
  rails-dom-testing (~> 2.0)
19
- actionpack (5.2.3)
20
- actionview (= 5.2.3)
21
- activesupport (= 5.2.3)
26
+ actionpack (6.0.0)
27
+ actionview (= 6.0.0)
28
+ activesupport (= 6.0.0)
22
29
  rack (~> 2.0)
23
30
  rack-test (>= 0.6.3)
24
31
  rails-dom-testing (~> 2.0)
25
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
26
- actionview (5.2.3)
27
- activesupport (= 5.2.3)
32
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
33
+ actiontext (6.0.0)
34
+ actionpack (= 6.0.0)
35
+ activerecord (= 6.0.0)
36
+ activestorage (= 6.0.0)
37
+ activesupport (= 6.0.0)
38
+ nokogiri (>= 1.8.5)
39
+ actionview (6.0.0)
40
+ activesupport (= 6.0.0)
28
41
  builder (~> 3.1)
29
42
  erubi (~> 1.4)
30
43
  rails-dom-testing (~> 2.0)
31
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
32
- activejob (5.2.3)
33
- activesupport (= 5.2.3)
44
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
45
+ activejob (6.0.0)
46
+ activesupport (= 6.0.0)
34
47
  globalid (>= 0.3.6)
35
- activemodel (5.2.3)
36
- activesupport (= 5.2.3)
37
- activerecord (5.2.3)
38
- activemodel (= 5.2.3)
39
- activesupport (= 5.2.3)
40
- arel (>= 9.0)
41
- activestorage (5.2.3)
42
- actionpack (= 5.2.3)
43
- activerecord (= 5.2.3)
48
+ activemodel (6.0.0)
49
+ activesupport (= 6.0.0)
50
+ activerecord (6.0.0)
51
+ activemodel (= 6.0.0)
52
+ activesupport (= 6.0.0)
53
+ activestorage (6.0.0)
54
+ actionpack (= 6.0.0)
55
+ activejob (= 6.0.0)
56
+ activerecord (= 6.0.0)
44
57
  marcel (~> 0.3.1)
45
- activesupport (5.2.3)
58
+ activesupport (6.0.0)
46
59
  concurrent-ruby (~> 1.0, >= 1.0.2)
47
60
  i18n (>= 0.7, < 2)
48
61
  minitest (~> 5.1)
49
62
  tzinfo (~> 1.1)
50
- arel (9.0.0)
63
+ zeitwerk (~> 2.1, >= 2.1.8)
51
64
  ast (2.4.0)
52
65
  builder (3.2.3)
53
66
  concurrent-ruby (1.1.5)
@@ -73,7 +86,7 @@ GEM
73
86
  mini_mime (1.0.2)
74
87
  mini_portile2 (2.4.0)
75
88
  minitest (5.1.0)
76
- nio4r (2.4.0)
89
+ nio4r (2.5.2)
77
90
  nokogiri (1.10.4)
78
91
  mini_portile2 (~> 2.4.0)
79
92
  parallel (1.17.0)
@@ -82,30 +95,32 @@ GEM
82
95
  rack (2.0.7)
83
96
  rack-test (1.1.0)
84
97
  rack (>= 1.0, < 3)
85
- rails (5.2.3)
86
- actioncable (= 5.2.3)
87
- actionmailer (= 5.2.3)
88
- actionpack (= 5.2.3)
89
- actionview (= 5.2.3)
90
- activejob (= 5.2.3)
91
- activemodel (= 5.2.3)
92
- activerecord (= 5.2.3)
93
- activestorage (= 5.2.3)
94
- activesupport (= 5.2.3)
98
+ rails (6.0.0)
99
+ actioncable (= 6.0.0)
100
+ actionmailbox (= 6.0.0)
101
+ actionmailer (= 6.0.0)
102
+ actionpack (= 6.0.0)
103
+ actiontext (= 6.0.0)
104
+ actionview (= 6.0.0)
105
+ activejob (= 6.0.0)
106
+ activemodel (= 6.0.0)
107
+ activerecord (= 6.0.0)
108
+ activestorage (= 6.0.0)
109
+ activesupport (= 6.0.0)
95
110
  bundler (>= 1.3.0)
96
- railties (= 5.2.3)
111
+ railties (= 6.0.0)
97
112
  sprockets-rails (>= 2.0.0)
98
113
  rails-dom-testing (2.0.3)
99
114
  activesupport (>= 4.2.0)
100
115
  nokogiri (>= 1.6)
101
116
  rails-html-sanitizer (1.2.0)
102
117
  loofah (~> 2.2, >= 2.2.2)
103
- railties (5.2.3)
104
- actionpack (= 5.2.3)
105
- activesupport (= 5.2.3)
118
+ railties (6.0.0)
119
+ actionpack (= 6.0.0)
120
+ activesupport (= 6.0.0)
106
121
  method_source
107
122
  rake (>= 0.8.7)
108
- thor (>= 0.19.0, < 2.0)
123
+ thor (>= 0.20.3, < 2.0)
109
124
  rainbow (3.0.0)
110
125
  rake (10.5.0)
111
126
  rubocop (0.74.0)
@@ -141,6 +156,7 @@ GEM
141
156
  websocket-driver (0.7.1)
142
157
  websocket-extensions (>= 0.1.0)
143
158
  websocket-extensions (0.1.4)
159
+ zeitwerk (2.1.10)
144
160
 
145
161
  PLATFORMS
146
162
  ruby
@@ -150,7 +166,7 @@ DEPENDENCIES
150
166
  bundler (>= 1.14)
151
167
  haml (~> 5)
152
168
  minitest (= 5.1.0)
153
- rails (= 5.2.3)
169
+ rails (= 6.0.0)
154
170
  rake (~> 10.0)
155
171
  rubocop (~> 0.59)
156
172
  rubocop-github (~> 0.13.0)
data/README.md CHANGED
@@ -9,6 +9,10 @@ This gem is meant to serve as a precursor to upstreaming the `ActionView::Compon
9
9
 
10
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.
11
11
 
12
+ ## Design philosophy
13
+
14
+ As the goal of this gem is to be upstreamed into Rails, it is designed to integrate as seamlessly as possible, with the [least surprise](https://www.artima.com/intv/ruby4.html).
15
+
12
16
  ## Compatibility
13
17
 
14
18
  `actionview-component` is tested for compatibility with combinations of Ruby `2.3`/`2.4`/`2.5`/`2.6` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`6.1.0.alpha`.
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "actionview-component"
9
- spec.version = "1.2.1"
9
+ spec.version = "1.3.4"
10
10
  spec.authors = ["GitHub Open Source"]
11
11
  spec.email = ["opensource+actionview-component@github.com"]
12
12
 
@@ -30,6 +30,8 @@ module ActionView
30
30
  module Component
31
31
  class Base < ActionView::Base
32
32
  include ActiveModel::Validations
33
+ include ActiveSupport::Configurable
34
+ include ActionController::RequestForgeryProtection
33
35
 
34
36
  # Entrypoint for rendering components. Called by ActionView::Base#render.
35
37
  #
@@ -58,6 +60,11 @@ module ActionView
58
60
  #
59
61
  def render_in(view_context, *args, &block)
60
62
  self.class.compile
63
+ @view_context = view_context
64
+ @view_renderer ||= view_context.view_renderer
65
+ @lookup_context ||= view_context.lookup_context
66
+ @view_flow ||= view_context.view_flow
67
+
61
68
  @content = view_context.capture(&block) if block_given?
62
69
  validate!
63
70
  call
@@ -65,6 +72,14 @@ module ActionView
65
72
 
66
73
  def initialize(*); end
67
74
 
75
+ def render(options = {}, args = {}, &block)
76
+ if options.is_a?(String) || (options.is_a?(Hash) && options.has_key?(:partial))
77
+ view_context.render(options, args, &block)
78
+ else
79
+ super
80
+ end
81
+ end
82
+
68
83
  class << self
69
84
  def inherited(child)
70
85
  child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
@@ -78,7 +93,12 @@ module ActionView
78
93
  def compile
79
94
  return if @compiled && ActionView::Base.cache_template_loading
80
95
 
81
- class_eval("def call; @output_buffer = ActionView::OutputBuffer.new; #{compiled_template}; end")
96
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
97
+ def call
98
+ @output_buffer = ActionView::OutputBuffer.new
99
+ #{compiled_template}
100
+ end
101
+ RUBY
82
102
 
83
103
  @compiled = true
84
104
  end
@@ -101,19 +121,19 @@ module ActionView
101
121
 
102
122
  filename = self.instance_method(:initialize).source_location[0]
103
123
  filename_without_extension = filename[0..-(File.extname(filename).length + 1)]
104
- sibling_files = Dir["#{filename_without_extension}.*"] - [filename]
124
+ sibling_template_files = Dir["#{filename_without_extension}.????.{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [filename]
105
125
 
106
- if sibling_files.length > 1
126
+ if sibling_template_files.length > 1
107
127
  raise StandardError.new("More than one template found for #{self}. There can only be one sidecar template file per component.")
108
128
  end
109
129
 
110
- if sibling_files.length == 0
130
+ if sibling_template_files.length == 0
111
131
  raise NotImplementedError.new(
112
132
  "Could not find a template file for #{self}."
113
133
  )
114
134
  end
115
135
 
116
- sibling_files[0]
136
+ sibling_template_files[0]
117
137
  end
118
138
  end
119
139
 
@@ -136,7 +156,15 @@ module ActionView
136
156
 
137
157
  private
138
158
 
139
- attr_reader :content
159
+ def controller
160
+ @controller ||= view_context.controller
161
+ end
162
+
163
+ def request
164
+ @request ||= controller.request
165
+ end
166
+
167
+ attr_reader :content, :view_context
140
168
  end
141
169
  end
142
170
  end
@@ -4,7 +4,15 @@ module ActionView
4
4
  module Component
5
5
  module TestHelpers
6
6
  def render_inline(component, **args, &block)
7
- Nokogiri::HTML(ApplicationController.new.view_context.render(component, args, &block))
7
+ Nokogiri::HTML(controller.view_context.render(component, args, &block))
8
+ end
9
+
10
+ def controller
11
+ @controller ||= ApplicationController.new.tap { |c| c.request = request }
12
+ end
13
+
14
+ def request
15
+ @request ||= ActionDispatch::TestRequest.create
8
16
  end
9
17
 
10
18
  def render_component(component, **args, &block)
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.2.1
4
+ version: 1.3.4
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-08-28 00:00:00.000000000 Z
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler