jbuilder 2.11.5 → 2.12.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 +4 -4
- data/.github/workflows/ruby.yml +44 -60
- data/.gitignore +1 -0
- data/Appraisals +23 -8
- data/README.md +4 -0
- data/gemfiles/rails_5_0.gemfile +1 -0
- data/gemfiles/rails_5_1.gemfile +1 -0
- data/gemfiles/rails_5_2.gemfile +1 -0
- data/gemfiles/rails_7_0.gemfile +10 -0
- data/gemfiles/rails_7_1.gemfile +10 -0
- data/jbuilder.gemspec +1 -1
- data/lib/generators/rails/jbuilder_generator.rb +4 -0
- data/lib/generators/rails/templates/index.json.jbuilder +1 -1
- data/lib/generators/rails/templates/show.json.jbuilder +1 -1
- data/lib/jbuilder/collection_renderer.rb +7 -0
- data/lib/jbuilder/jbuilder.rb +1 -7
- data/lib/jbuilder/jbuilder_dependency_tracker.rb +73 -0
- data/lib/jbuilder/jbuilder_template.rb +4 -3
- data/lib/jbuilder/railtie.rb +2 -2
- data/lib/jbuilder.rb +9 -6
- data/test/jbuilder_dependency_tracker_test.rb +1 -2
- data/test/jbuilder_generator_test.rb +12 -0
- data/test/jbuilder_template_test.rb +8 -1
- data/test/test_helper.rb +12 -1
- metadata +12 -10
- data/lib/jbuilder/dependency_tracker.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4178787c12de3a44e4d47e347b7eb81da4cbb75222f9726db40b22124998041e
|
4
|
+
data.tar.gz: 967cc31e472ad0e381e9c87f27e29be40aa2c71db6fb9f9131ef53b434bd3e5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ace71a1fc2424b0d9428d66f595f155367763d6d8d28a21e87838418259f8c2d3d370c3a96a7134b5aac729fb5007f053de5a6f0bebcc3d4a4c13f5e9deb0d92
|
7
|
+
data.tar.gz: 4b0b4992c64d2bbbfb83a343800555456a7c201d5f5fc19c5e919fd9ed9a1d448f7b902d841c99666c9794c70e15ad8b1cb94d5de4f61caca95901bbead3f046
|
data/.github/workflows/ruby.yml
CHANGED
@@ -6,7 +6,7 @@ jobs:
|
|
6
6
|
test:
|
7
7
|
name: Ruby ${{ matrix.ruby }} (${{ matrix.gemfile }})
|
8
8
|
runs-on: ubuntu-20.04
|
9
|
-
continue-on-error: ${{ matrix.
|
9
|
+
continue-on-error: ${{ matrix.gemfile == 'rails_head' }}
|
10
10
|
env:
|
11
11
|
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
12
12
|
BUNDLE_JOBS: 4
|
@@ -14,90 +14,74 @@ jobs:
|
|
14
14
|
strategy:
|
15
15
|
fail-fast: false
|
16
16
|
matrix:
|
17
|
-
ruby:
|
18
|
-
- "2.2"
|
19
|
-
- "2.3"
|
20
|
-
- "2.4"
|
21
|
-
- "2.5"
|
22
|
-
- "2.6"
|
17
|
+
ruby:
|
23
18
|
- "2.7"
|
24
19
|
- "3.0"
|
20
|
+
- "3.1"
|
21
|
+
- "3.2"
|
22
|
+
- "3.3"
|
25
23
|
|
26
24
|
gemfile:
|
27
|
-
- "rails_5_0"
|
28
|
-
- "rails_5_1"
|
29
|
-
- "rails_5_2"
|
30
|
-
- "rails_6_0"
|
31
25
|
- "rails_6_1"
|
26
|
+
- "rails_7_0"
|
27
|
+
- "rails_7_1"
|
32
28
|
- "rails_head"
|
33
|
-
|
34
|
-
experimental: [false]
|
29
|
+
|
35
30
|
exclude:
|
36
31
|
- ruby: 2.7
|
37
|
-
gemfile:
|
32
|
+
gemfile: rails_head
|
38
33
|
- ruby: '3.0'
|
34
|
+
gemfile: rails_head
|
35
|
+
|
36
|
+
include:
|
37
|
+
- ruby: 2.2
|
39
38
|
gemfile: rails_5_0
|
40
|
-
- ruby:
|
41
|
-
gemfile: rails_5_0
|
42
|
-
- ruby: 2.7
|
43
|
-
gemfile: rails_5_1
|
44
|
-
- ruby: '3.0'
|
39
|
+
- ruby: 2.2
|
45
40
|
gemfile: rails_5_1
|
46
|
-
- ruby:
|
41
|
+
- ruby: 2.3
|
42
|
+
gemfile: rails_5_0
|
43
|
+
- ruby: 2.3
|
47
44
|
gemfile: rails_5_1
|
48
|
-
- ruby: 2.2
|
49
|
-
gemfile: rails_5_2
|
50
|
-
- ruby: 2.7
|
51
|
-
gemfile: rails_5_2
|
52
|
-
- ruby: '3.0'
|
53
|
-
gemfile: rails_5_2
|
54
|
-
- ruby: head
|
55
|
-
gemfile: rails_5_2
|
56
|
-
- ruby: 2.2
|
57
|
-
gemfile: rails_6_0
|
58
45
|
- ruby: 2.3
|
59
|
-
gemfile:
|
46
|
+
gemfile: rails_5_2
|
60
47
|
- ruby: 2.4
|
61
|
-
gemfile:
|
62
|
-
- ruby: '3.0'
|
63
|
-
gemfile: rails_6_0
|
64
|
-
- ruby: head
|
65
|
-
gemfile: rails_6_0
|
66
|
-
- ruby: 2.2
|
67
|
-
gemfile: rails_6_1
|
68
|
-
- ruby: 2.3
|
69
|
-
gemfile: rails_6_1
|
48
|
+
gemfile: rails_5_0
|
70
49
|
- ruby: 2.4
|
71
|
-
gemfile:
|
72
|
-
- ruby: 2.2
|
73
|
-
gemfile: rails_head
|
74
|
-
- ruby: 2.3
|
75
|
-
gemfile: rails_head
|
50
|
+
gemfile: rails_5_1
|
76
51
|
- ruby: 2.4
|
77
|
-
gemfile:
|
52
|
+
gemfile: rails_5_2
|
78
53
|
- ruby: 2.5
|
79
|
-
gemfile:
|
54
|
+
gemfile: rails_5_0
|
55
|
+
- ruby: 2.5
|
56
|
+
gemfile: rails_5_1
|
57
|
+
- ruby: 2.5
|
58
|
+
gemfile: rails_5_2
|
59
|
+
- ruby: 2.5
|
60
|
+
gemfile: rails_6_0
|
61
|
+
- ruby: 2.5
|
62
|
+
gemfile: rails_6_1
|
80
63
|
- ruby: 2.6
|
81
|
-
gemfile:
|
82
|
-
- ruby: 2.
|
83
|
-
gemfile:
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
64
|
+
gemfile: rails_5_0
|
65
|
+
- ruby: 2.6
|
66
|
+
gemfile: rails_5_1
|
67
|
+
- ruby: 2.6
|
68
|
+
gemfile: rails_5_2
|
69
|
+
- ruby: 2.6
|
70
|
+
gemfile: rails_6_0
|
71
|
+
- ruby: 2.6
|
72
|
+
gemfile: rails_6_1
|
89
73
|
- ruby: 2.7
|
74
|
+
gemfile: rails_6_0
|
75
|
+
|
76
|
+
- ruby: '3.1'
|
90
77
|
gemfile: rails_head
|
91
|
-
|
92
|
-
- ruby: '3.0'
|
78
|
+
- ruby: '3.2'
|
93
79
|
gemfile: rails_head
|
94
|
-
experimental: true
|
95
80
|
- ruby: head
|
96
81
|
gemfile: rails_head
|
97
|
-
experimental: true
|
98
82
|
|
99
83
|
steps:
|
100
|
-
- uses: actions/checkout@
|
84
|
+
- uses: actions/checkout@v4
|
101
85
|
|
102
86
|
- uses: ruby/setup-ruby@v1
|
103
87
|
with:
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
if RUBY_VERSION < "2.7.0"
|
2
|
+
appraise "rails-5-0" do
|
3
|
+
gem "rails", "~> 5.0.0"
|
4
|
+
gem "loofah", "< 2.21.0"
|
5
|
+
end
|
4
6
|
|
5
|
-
appraise "rails-5-1" do
|
6
|
-
|
7
|
-
|
7
|
+
appraise "rails-5-1" do
|
8
|
+
gem "rails", "~> 5.1.0"
|
9
|
+
gem "loofah", "< 2.21.0"
|
10
|
+
end
|
8
11
|
|
9
|
-
appraise "rails-5-2" do
|
10
|
-
|
12
|
+
appraise "rails-5-2" do
|
13
|
+
gem "rails", "~> 5.2.0"
|
14
|
+
gem "loofah", "< 2.21.0"
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
if RUBY_VERSION >= "2.5.0"
|
@@ -18,6 +23,16 @@ if RUBY_VERSION >= "2.5.0"
|
|
18
23
|
appraise "rails-6-1" do
|
19
24
|
gem "rails", "~> 6.1.0"
|
20
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if RUBY_VERSION >= "2.7.0"
|
29
|
+
appraise "rails-7-0" do
|
30
|
+
gem "rails", "~> 7.0.0"
|
31
|
+
end
|
32
|
+
|
33
|
+
appraise "rails-7-1" do
|
34
|
+
gem "rails", "~> 7.1.0"
|
35
|
+
end
|
21
36
|
|
22
37
|
appraise "rails-head" do
|
23
38
|
gem "rails", github: "rails/rails", branch: "main"
|
data/README.md
CHANGED
@@ -338,6 +338,10 @@ environment.rb for example):
|
|
338
338
|
Jbuilder.deep_format_keys true
|
339
339
|
```
|
340
340
|
|
341
|
+
## Testing JBuilder Response body with RSpec
|
342
|
+
|
343
|
+
To test the response body of your controller spec, enable `render_views` in your RSpec context. This [configuration](https://rspec.info/features/6-0/rspec-rails/controller-specs/render-views) renders the views in a controller test.
|
344
|
+
|
341
345
|
## Contributing to Jbuilder
|
342
346
|
|
343
347
|
Jbuilder is the work of many contributors. You're encouraged to submit pull requests, propose
|
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
data/gemfiles/rails_5_2.gemfile
CHANGED
data/jbuilder.gemspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
json.array! @<%= plural_table_name %>, partial: "<%=
|
1
|
+
json.array! @<%= plural_table_name %>, partial: "<%= partial_path_name %>", as: :<%= singular_table_name %>
|
@@ -1 +1 @@
|
|
1
|
-
json.partial! "<%=
|
1
|
+
json.partial! "<%= partial_path_name %>", <%= singular_table_name %>: @<%= singular_table_name %>
|
data/lib/jbuilder/jbuilder.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
class Jbuilder::DependencyTracker
|
2
|
+
EXPLICIT_DEPENDENCY = /# Template Dependency: (\S+)/
|
3
|
+
|
4
|
+
# Matches:
|
5
|
+
# json.partial! "messages/message"
|
6
|
+
# json.partial!('messages/message')
|
7
|
+
#
|
8
|
+
DIRECT_RENDERS = /
|
9
|
+
\w+\.partial! # json.partial!
|
10
|
+
\(?\s* # optional parenthesis
|
11
|
+
(['"])([^'"]+)\1 # quoted value
|
12
|
+
/x
|
13
|
+
|
14
|
+
# Matches:
|
15
|
+
# json.partial! partial: "comments/comment"
|
16
|
+
# json.comments @post.comments, partial: "comments/comment", as: :comment
|
17
|
+
# json.array! @posts, partial: "posts/post", as: :post
|
18
|
+
# = render partial: "account"
|
19
|
+
#
|
20
|
+
INDIRECT_RENDERS = /
|
21
|
+
(?::partial\s*=>|partial:) # partial: or :partial =>
|
22
|
+
\s* # optional whitespace
|
23
|
+
(['"])([^'"]+)\1 # quoted value
|
24
|
+
/x
|
25
|
+
|
26
|
+
def self.call(name, template, view_paths = nil)
|
27
|
+
new(name, template, view_paths).dependencies
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(name, template, view_paths = nil)
|
31
|
+
@name, @template, @view_paths = name, template, view_paths
|
32
|
+
end
|
33
|
+
|
34
|
+
def dependencies
|
35
|
+
direct_dependencies + indirect_dependencies + explicit_dependencies
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :name, :template
|
41
|
+
|
42
|
+
def direct_dependencies
|
43
|
+
source.scan(DIRECT_RENDERS).map(&:second)
|
44
|
+
end
|
45
|
+
|
46
|
+
def indirect_dependencies
|
47
|
+
source.scan(INDIRECT_RENDERS).map(&:second)
|
48
|
+
end
|
49
|
+
|
50
|
+
def explicit_dependencies
|
51
|
+
dependencies = source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
|
52
|
+
|
53
|
+
wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") }
|
54
|
+
|
55
|
+
(explicits + resolve_directories(wildcards)).uniq
|
56
|
+
end
|
57
|
+
|
58
|
+
def resolve_directories(wildcard_dependencies)
|
59
|
+
return [] unless @view_paths
|
60
|
+
return [] if wildcard_dependencies.empty?
|
61
|
+
|
62
|
+
# Remove trailing "/*"
|
63
|
+
prefixes = wildcard_dependencies.map { |query| query[0..-3] }
|
64
|
+
|
65
|
+
@view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
|
66
|
+
path.to_s if prefixes.include?(path.prefix)
|
67
|
+
}.sort
|
68
|
+
end
|
69
|
+
|
70
|
+
def source
|
71
|
+
template.source
|
72
|
+
end
|
73
|
+
end
|
@@ -89,7 +89,7 @@ class JbuilderTemplate < Jbuilder
|
|
89
89
|
# # json.extra 'This will not work either, the root must be exclusive'
|
90
90
|
def cache_root!(key=nil, options={})
|
91
91
|
if @context.controller.perform_caching
|
92
|
-
raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present?
|
92
|
+
::Kernel.raise "cache_root! can't be used after JSON structures have been defined" if @attributes.present?
|
93
93
|
|
94
94
|
@cached_root = _cache_fragment_for([ :root, key ], options) { yield; target! }
|
95
95
|
else
|
@@ -145,13 +145,14 @@ class JbuilderTemplate < Jbuilder
|
|
145
145
|
collection = options.delete(:collection) || []
|
146
146
|
partial = options.delete(:partial)
|
147
147
|
options[:locals].merge!(json: self)
|
148
|
+
collection = EnumerableCompat.new(collection) if collection.respond_to?(:count) && !collection.respond_to?(:size)
|
148
149
|
|
149
150
|
if options.has_key?(:layout)
|
150
|
-
raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering."
|
151
|
+
::Kernel.raise ::NotImplementedError, "The `:layout' option is not supported in collection rendering."
|
151
152
|
end
|
152
153
|
|
153
154
|
if options.has_key?(:spacer_template)
|
154
|
-
raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering."
|
155
|
+
::Kernel.raise ::NotImplementedError, "The `:spacer_template' option is not supported in collection rendering."
|
155
156
|
end
|
156
157
|
|
157
158
|
results = CollectionRenderer
|
data/lib/jbuilder/railtie.rb
CHANGED
@@ -6,7 +6,7 @@ class Jbuilder
|
|
6
6
|
initializer :jbuilder do
|
7
7
|
ActiveSupport.on_load :action_view do
|
8
8
|
ActionView::Template.register_template_handler :jbuilder, JbuilderHandler
|
9
|
-
require 'jbuilder/
|
9
|
+
require 'jbuilder/jbuilder_dependency_tracker'
|
10
10
|
end
|
11
11
|
|
12
12
|
if Rails::VERSION::MAJOR >= 5
|
@@ -17,7 +17,7 @@ class Jbuilder
|
|
17
17
|
end
|
18
18
|
|
19
19
|
ActiveSupport.on_load :action_controller do
|
20
|
-
if
|
20
|
+
if name == 'ActionController::API'
|
21
21
|
include ActionController::Helpers
|
22
22
|
include ActionController::ImplicitRender
|
23
23
|
end
|
data/lib/jbuilder.rb
CHANGED
@@ -4,8 +4,11 @@ require 'jbuilder/blank'
|
|
4
4
|
require 'jbuilder/key_formatter'
|
5
5
|
require 'jbuilder/errors'
|
6
6
|
require 'json'
|
7
|
-
require 'ostruct'
|
8
7
|
require 'active_support/core_ext/hash/deep_merge'
|
8
|
+
begin
|
9
|
+
require 'ostruct'
|
10
|
+
rescue LoadError
|
11
|
+
end
|
9
12
|
|
10
13
|
class Jbuilder
|
11
14
|
@@key_formatter = nil
|
@@ -28,7 +31,7 @@ class Jbuilder
|
|
28
31
|
end
|
29
32
|
|
30
33
|
BLANK = Blank.new
|
31
|
-
NON_ENUMERABLES = [
|
34
|
+
NON_ENUMERABLES = defined?(::OpenStruct) ? [::Struct, ::OpenStruct].to_set : [::Struct].to_set
|
32
35
|
|
33
36
|
def set!(key, value = BLANK, *args, &block)
|
34
37
|
result = if ::Kernel.block_given?
|
@@ -292,7 +295,7 @@ class Jbuilder
|
|
292
295
|
|
293
296
|
def _merge_block(key)
|
294
297
|
current_value = _blank? ? BLANK : @attributes.fetch(_key(key), BLANK)
|
295
|
-
raise NullError.build(key) if current_value.nil?
|
298
|
+
::Kernel.raise NullError.build(key) if current_value.nil?
|
296
299
|
new_value = _scope{ yield self }
|
297
300
|
_merge_values(current_value, new_value)
|
298
301
|
end
|
@@ -307,7 +310,7 @@ class Jbuilder
|
|
307
310
|
elsif ::Hash === current_value && ::Hash === updates
|
308
311
|
current_value.deep_merge(updates)
|
309
312
|
else
|
310
|
-
raise MergeError.build(current_value, updates)
|
313
|
+
::Kernel.raise MergeError.build(current_value, updates)
|
311
314
|
end
|
312
315
|
end
|
313
316
|
|
@@ -328,8 +331,8 @@ class Jbuilder
|
|
328
331
|
end
|
329
332
|
|
330
333
|
def _set_value(key, value)
|
331
|
-
raise NullError.build(key) if @attributes.nil?
|
332
|
-
raise ArrayError.build(key) if ::Array === @attributes
|
334
|
+
::Kernel.raise NullError.build(key) if @attributes.nil?
|
335
|
+
::Kernel.raise ArrayError.build(key) if ::Array === @attributes
|
333
336
|
return if @ignore_nil && value.nil? or _blank?(value)
|
334
337
|
@attributes = {} if _blank?
|
335
338
|
@attributes[_key(key)] = value
|
@@ -44,6 +44,18 @@ class JbuilderGeneratorTest < Rails::Generators::TestCase
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
test 'namespaced views are generated correctly for index' do
|
48
|
+
run_generator %w(Admin::Post --model-name=Post)
|
49
|
+
|
50
|
+
assert_file 'app/views/admin/posts/index.json.jbuilder' do |content|
|
51
|
+
assert_match %r{json\.array! @posts, partial: "admin/posts/post", as: :post}, content
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_file 'app/views/admin/posts/show.json.jbuilder' do |content|
|
55
|
+
assert_match %r{json\.partial! "admin/posts/post", post: @post}, content
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
47
59
|
if Rails::VERSION::MAJOR >= 6
|
48
60
|
test 'handles virtual attributes' do
|
49
61
|
run_generator %w(Message content:rich_text video:attachment photos:attachments)
|
@@ -73,6 +73,14 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
|
|
73
73
|
assert_equal "Pavel", result[5]["author"]["first_name"]
|
74
74
|
end
|
75
75
|
|
76
|
+
test "partial collection by name with caching" do
|
77
|
+
result = render('json.partial! "post", collection: @posts, cached: true, as: :post', posts: POSTS)
|
78
|
+
assert_equal 10, result.count
|
79
|
+
assert_equal "Post #5", result[4]["body"]
|
80
|
+
assert_equal "Heinemeier Hansson", result[2]["author"]["last_name"]
|
81
|
+
assert_equal "Pavel", result[5]["author"]["first_name"]
|
82
|
+
end
|
83
|
+
|
76
84
|
test "partial collection by name with string local" do
|
77
85
|
result = render('json.partial! "post", collection: @posts, as: "post"', posts: POSTS)
|
78
86
|
assert_equal 10, result.count
|
@@ -294,7 +302,6 @@ class JbuilderTemplateTest < ActiveSupport::TestCase
|
|
294
302
|
test "works with an enumerable object" do
|
295
303
|
enumerable_class = Class.new do
|
296
304
|
include Enumerable
|
297
|
-
alias length count # Rails 6.1 requires this.
|
298
305
|
|
299
306
|
def each(&block)
|
300
307
|
[].each(&block)
|
data/test/test_helper.rb
CHANGED
@@ -8,12 +8,16 @@ require "active_support/core_ext/array/access"
|
|
8
8
|
require "active_support/cache/memory_store"
|
9
9
|
require "active_support/json"
|
10
10
|
require "active_model"
|
11
|
+
require 'action_controller/railtie'
|
12
|
+
require 'action_view/railtie'
|
11
13
|
|
12
14
|
require "active_support/testing/autorun"
|
13
15
|
require "mocha/minitest"
|
14
16
|
|
15
17
|
ActiveSupport.test_order = :random
|
16
18
|
|
19
|
+
ENV["RAILS_ENV"] ||= "test"
|
20
|
+
|
17
21
|
class << Rails
|
18
22
|
def cache
|
19
23
|
@cache ||= ActiveSupport::Cache::MemoryStore.new
|
@@ -33,4 +37,11 @@ class Racer < Struct.new(:id, :name)
|
|
33
37
|
include ActiveModel::Conversion
|
34
38
|
end
|
35
39
|
|
36
|
-
|
40
|
+
# Instantiate an Application in order to trigger the initializers
|
41
|
+
Class.new(Rails::Application) do
|
42
|
+
config.secret_key_base = 'secret'
|
43
|
+
config.eager_load = false
|
44
|
+
end.initialize!
|
45
|
+
|
46
|
+
# Touch AV::Base in order to trigger :action_view on_load hook before running the tests
|
47
|
+
ActionView::Base.inspect
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.0
|
41
|
-
description:
|
41
|
+
description:
|
42
42
|
email: david@basecamp.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- gemfiles/rails_5_2.gemfile
|
58
58
|
- gemfiles/rails_6_0.gemfile
|
59
59
|
- gemfiles/rails_6_1.gemfile
|
60
|
+
- gemfiles/rails_7_0.gemfile
|
61
|
+
- gemfiles/rails_7_1.gemfile
|
60
62
|
- gemfiles/rails_head.gemfile
|
61
63
|
- jbuilder.gemspec
|
62
64
|
- lib/generators/rails/jbuilder_generator.rb
|
@@ -69,9 +71,9 @@ files:
|
|
69
71
|
- lib/jbuilder.rb
|
70
72
|
- lib/jbuilder/blank.rb
|
71
73
|
- lib/jbuilder/collection_renderer.rb
|
72
|
-
- lib/jbuilder/dependency_tracker.rb
|
73
74
|
- lib/jbuilder/errors.rb
|
74
75
|
- lib/jbuilder/jbuilder.rb
|
76
|
+
- lib/jbuilder/jbuilder_dependency_tracker.rb
|
75
77
|
- lib/jbuilder/jbuilder_template.rb
|
76
78
|
- lib/jbuilder/key_formatter.rb
|
77
79
|
- lib/jbuilder/railtie.rb
|
@@ -87,11 +89,11 @@ licenses:
|
|
87
89
|
- MIT
|
88
90
|
metadata:
|
89
91
|
bug_tracker_uri: https://github.com/rails/jbuilder/issues
|
90
|
-
changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.
|
92
|
+
changelog_uri: https://github.com/rails/jbuilder/releases/tag/v2.12.0
|
91
93
|
mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
|
92
|
-
source_code_uri: https://github.com/rails/jbuilder/tree/v2.
|
94
|
+
source_code_uri: https://github.com/rails/jbuilder/tree/v2.12.0
|
93
95
|
rubygems_mfa_required: 'true'
|
94
|
-
post_install_message:
|
96
|
+
post_install_message:
|
95
97
|
rdoc_options: []
|
96
98
|
require_paths:
|
97
99
|
- lib
|
@@ -106,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
- !ruby/object:Gem::Version
|
107
109
|
version: '0'
|
108
110
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
110
|
-
signing_key:
|
111
|
+
rubygems_version: 3.5.9
|
112
|
+
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Create JSON structures via a Builder-style DSL
|
113
115
|
test_files:
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'jbuilder/jbuilder'
|
2
|
-
|
3
|
-
dependency_tracker = false
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'action_view'
|
7
|
-
require 'action_view/dependency_tracker'
|
8
|
-
dependency_tracker = ::ActionView::DependencyTracker
|
9
|
-
rescue LoadError
|
10
|
-
begin
|
11
|
-
require 'cache_digests'
|
12
|
-
dependency_tracker = ::CacheDigests::DependencyTracker
|
13
|
-
rescue LoadError
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
if dependency_tracker
|
18
|
-
class Jbuilder
|
19
|
-
module DependencyTrackerMethods
|
20
|
-
# Matches:
|
21
|
-
# json.partial! "messages/message"
|
22
|
-
# json.partial!('messages/message')
|
23
|
-
#
|
24
|
-
DIRECT_RENDERS = /
|
25
|
-
\w+\.partial! # json.partial!
|
26
|
-
\(?\s* # optional parenthesis
|
27
|
-
(['"])([^'"]+)\1 # quoted value
|
28
|
-
/x
|
29
|
-
|
30
|
-
# Matches:
|
31
|
-
# json.partial! partial: "comments/comment"
|
32
|
-
# json.comments @post.comments, partial: "comments/comment", as: :comment
|
33
|
-
# json.array! @posts, partial: "posts/post", as: :post
|
34
|
-
# = render partial: "account"
|
35
|
-
#
|
36
|
-
INDIRECT_RENDERS = /
|
37
|
-
(?::partial\s*=>|partial:) # partial: or :partial =>
|
38
|
-
\s* # optional whitespace
|
39
|
-
(['"])([^'"]+)\1 # quoted value
|
40
|
-
/x
|
41
|
-
|
42
|
-
def dependencies
|
43
|
-
direct_dependencies + indirect_dependencies + explicit_dependencies
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def direct_dependencies
|
49
|
-
source.scan(DIRECT_RENDERS).map(&:second)
|
50
|
-
end
|
51
|
-
|
52
|
-
def indirect_dependencies
|
53
|
-
source.scan(INDIRECT_RENDERS).map(&:second)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
::Jbuilder::DependencyTracker = Class.new(dependency_tracker::ERBTracker)
|
59
|
-
::Jbuilder::DependencyTracker.send :include, ::Jbuilder::DependencyTrackerMethods
|
60
|
-
dependency_tracker.register_tracker :jbuilder, ::Jbuilder::DependencyTracker
|
61
|
-
end
|