checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA256:
3
- metadata.gz: ddf5bf315652aa562e2539e334b61b97504cc05d37dd8580929dc0427d4ef44a
4
- data.tar.gz: 2c7310fec9eca98c28d6dc1b547959a8f4581026a59afe66f927df4c630b4ded
3
+ metadata.gz: 31181269a68b440c741ff9665ef8cb4df10c7e55bb2b0253423e19ffa96807ab
4
+ data.tar.gz: e851b3a851e95328c969539bad6f02a35311828d5037ea16d21d775651ddf500
5
5
SHA512:
6
- metadata.gz: 38c43b346608924c4ee5977c99760acebbb055392acbb276b8dbe1f0ce92b2c020b6ff2a9c5c63ac9b9025e4d1cc9a24fd86bf428a5ba375f11fa7b12a8fc149
7
- data.tar.gz: 7ed9efc6148a03dcaafcbec7a77467b17690e2c71e5afb133855a4924b91a771c0980cd7e0b4373f9deea8909be74e675a3a579e39eb78391cfbce8ab4db01af
6
+ metadata.gz: eb1cca60238b879c6452688b59ebce47e436493f7b9031871c3099cbcb876f57cd37c020cff59ce09b70ba821d6e1f075c97739753525158acb7d7caa0e5c279
7
+ data.tar.gz: 0341cf5c599e0453ec78ce7f5131411a55dd73253db7b78019a136899d84bbab01d153c0157038d71d484646617bd26e81bf6caae8ab691e1c11f983e533ae99
data/.github/workflows/ruby_on_rails.yml CHANGED
@@ -1,14 +1,23 @@
1
1
name: Ruby on Rails
2
2
3
- on: [push]
3
+ on: [push, pull_request]
4
4
5
5
jobs:
6
6
build:
7
7
runs-on: ubuntu-latest
8
8
strategy:
9
9
matrix:
10
- rails_version: ["5.2.3", "6.0.0", "master"]
11
- ruby_version: ["2.5.x", "2.6.x"]
10
+ rails_version: [5.0.0, 5.2.3, 6.0.0, master]
11
+ ruby_version: [2.3.x, 2.4.x, 2.5.x, 2.6.x]
12
+ exclude:
13
+ - rails_version: master
14
+ ruby_version: 2.4.x
15
+ - rails_version: master
16
+ ruby_version: 2.3.x
17
+ - rails_version: 6.0.0
18
+ ruby_version: 2.4.x
19
+ - rails_version: 6.0.0
20
+ ruby_version: 2.3.x
12
21
steps:
13
22
- uses: actions/checkout@master
14
23
- name: Setup Ruby
@@ -17,7 +26,7 @@ jobs:
17
26
version: ${{ matrix.ruby_version }}
18
27
- name: Build and test with Rake
19
28
run: |
20
- gem install bundler
29
+ gem install bundler:1.14.0
21
30
bundle update
22
31
bundle install --jobs 4 --retry 3
23
32
bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # v1.3.3
2
+
3
+ * Do not raise error when sidecar files that are not templates exist.
4
+
5
+ *Joel Hawksley*
6
+
7
+ # v1.3.2
8
+
9
+ * Support rendering views from inside component templates.
10
+
11
+ *Patrick Sinclair*
12
+
13
+ # v1.3.1
14
+
15
+ * Fix bug where rendering nested content caused an error.
16
+
17
+ *Joel Hawksley, Aaron Patterson*
18
+
19
+ # v1.3.0
20
+
21
+ * Components are rendered with enough controller context to support rendering of partials and forms.
22
+
23
+ *Patrick Sinclair, Joel Hawksley, Aaron Patterson*
24
+
25
+ # v1.2.1
26
+
27
+ * `actionview-component` is now tested against Ruby 2.3/2.4 and Rails 5.0.0.
28
+
29
+ # v1.2.0
30
+
1
31
* The `render_component` test helper has been renamed to `render_inline`. `render_component` has been deprecated and will be removed in v2.0.0.
2
32
3
33
*Joel Hawksley*
data/CONTRIBUTING.md CHANGED
@@ -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
data/Gemfile.lock CHANGED
@@ -1,53 +1,66 @@
1
1
PATH
2
2
remote: .
3
3
specs:
4
- actionview-component (1.2.0)
4
+ actionview-component (1.3.3)
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)
@@ -72,8 +85,8 @@ GEM
72
85
mimemagic (0.3.3)
73
86
mini_mime (1.0.2)
74
87
mini_portile2 (2.4.0)
75
- minitest (5.11.3)
76
- nio4r (2.4.0)
88
+ minitest (5.1.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
@@ -149,12 +165,12 @@ DEPENDENCIES
149
165
actionview-component!
150
166
bundler (>= 1.14)
151
167
haml (~> 5)
152
- minitest (~> 5.0)
153
- rails (= 5.2.3)
168
+ minitest (= 5.1.0)
169
+ rails (= 6.0.0)
154
170
rake (~> 10.0)
155
171
rubocop (~> 0.59)
156
172
rubocop-github (~> 0.13.0)
157
173
slim (~> 4.0)
158
174
159
175
BUNDLED WITH
160
- 2.0.2
176
+ 1.17.3
data/README.md CHANGED
@@ -9,9 +9,13 @@ 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
- `actionview-component` is tested for compatibility with all combinations of Ruby `2.5`/`2.6` and Rails `5.2.3`/`6.0.0`/`6.1.0.alpha`.
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`.
15
19
16
20
## Installation
17
21
Add this line to your application's Gemfile:
data/actionview-component.gemspec CHANGED
@@ -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.0"
9
+ spec.version = "1.3.3"
10
10
spec.authors = ["GitHub Open Source"]
11
11
spec.email = ["opensource+actionview-component@github.com"]
12
12
@@ -31,11 +31,11 @@ Gem::Specification.new do |spec|
31
31
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
spec.require_paths = ["lib"]
33
33
34
- spec.required_ruby_version = ">= 2.5.0"
34
+ spec.required_ruby_version = ">= 2.3.0"
35
35
36
36
spec.add_development_dependency "bundler", ">= 1.14"
37
37
spec.add_development_dependency "rake", "~> 10.0"
38
- spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency "minitest", "= 5.1.0"
39
39
spec.add_development_dependency "haml", "~> 5"
40
40
spec.add_development_dependency "slim", "~> 4.0"
41
41
spec.add_development_dependency "rubocop", "~> 0.59"
data/lib/action_view/component/base.rb CHANGED
@@ -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,12 @@ module ActionView
58
60
#
59
61
def render_in(view_context, *args, &block)
60
62
self.class.compile
63
+ self.controller = view_context.controller
64
+ @view_context = view_context
65
+ @view_renderer ||= view_context.view_renderer
66
+ @lookup_context ||= view_context.lookup_context
67
+ @view_flow ||= view_context.view_flow
68
+
61
69
@content = view_context.capture(&block) if block_given?
62
70
validate!
63
71
call
@@ -65,6 +73,14 @@ module ActionView
65
73
66
74
def initialize(*); end
67
75
76
+ def render(options = {}, args = {}, &block)
77
+ if options.is_a?(String) || (options.is_a?(Hash) && options.has_key?(:partial))
78
+ view_context.render(options, args, &block)
79
+ else
80
+ super
81
+ end
82
+ end
83
+
68
84
class << self
69
85
def inherited(child)
70
86
child.include Rails.application.routes.url_helpers unless child < Rails.application.routes.url_helpers
@@ -101,19 +117,19 @@ module ActionView
101
117
102
118
filename = self.instance_method(:initialize).source_location[0]
103
119
filename_without_extension = filename[0..-(File.extname(filename).length + 1)]
104
- sibling_files = Dir["#{filename_without_extension}.*"] - [filename]
120
+ sibling_template_files = Dir["#{filename_without_extension}.????.{#{ActionView::Template.template_handler_extensions.join(',')}}"] - [filename]
105
121
106
- if sibling_files.length > 1
122
+ if sibling_template_files.length > 1
107
123
raise StandardError.new("More than one template found for #{self}. There can only be one sidecar template file per component.")
108
124
end
109
125
110
- if sibling_files.length == 0
126
+ if sibling_template_files.length == 0
111
127
raise NotImplementedError.new(
112
128
"Could not find a template file for #{self}."
113
129
)
114
130
end
115
131
116
- sibling_files[0]
132
+ sibling_template_files[0]
117
133
end
118
134
end
119
135
@@ -136,7 +152,7 @@ module ActionView
136
152
137
153
private
138
154
139
- attr_reader :content
155
+ attr_reader :content, :view_context
140
156
end
141
157
end
142
158
end
data/lib/action_view/component/test_helpers.rb CHANGED
@@ -4,7 +4,11 @@ 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 = ActionDispatch::TestRequest.create }
8
12
end
9
13
10
14
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.0
4
+ version: 1.3.3
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-02 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
name: minitest
43
43
requirement: !ruby/object:Gem::Requirement
44
44
requirements:
45
- - - "~>"
45
+ - - '='
46
46
- !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: 5.1.0
48
48
type: :development
49
49
prerelease: false
50
50
version_requirements: !ruby/object:Gem::Requirement
51
51
requirements:
52
- - - "~>"
52
+ - - '='
53
53
- !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: 5.1.0
55
55
- !ruby/object:Gem::Dependency
56
56
name: haml
57
57
requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
requirements:
148
148
- - ">="
149
149
- !ruby/object:Gem::Version
150
- version: 2.5.0
150
+ version: 2.3.0
151
151
required_rubygems_version: !ruby/object:Gem::Requirement
152
152
requirements:
153
153
- - ">="