jb 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/gemfiles/rails_60.gemfile +8 -0
- data/jb.gemspec +1 -0
- data/lib/jb/action_view_legacy_monkeys.rb +54 -0
- data/lib/jb/action_view_monkeys.rb +20 -42
- data/lib/jb/railtie.rb +6 -1
- data/lib/jb/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c707621b4d6ba3cbaa4de4b318663845a7b818abf61eb3627b7b00e0528060d
|
4
|
+
data.tar.gz: e5e190db6aef763bacf00c4d172bba4d6e6b12c158e56df7155031dd400d8950
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f038b6e4eaaf94b1a55111943a72a528681326b32e3112c3b010163c806ce146cb19151b319c4677f74873760815db072aba22b9ad53763c0b621289973ce47b
|
7
|
+
data.tar.gz: 3a8318862bc399f9d0e27048b8902ed89f51fe9b9cfa1f832043b089bf5bbee2130672deb965a332631b48142a24140a13c771465db1e57c39dc3cf3fe1ab16b
|
data/.travis.yml
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
|
4
|
-
before_install: gem
|
4
|
+
before_install: "gem uni -x -i /home/travis/.rvm/gems/ruby-2.5.5@global bundler && gem i bundler -v '<2'"
|
5
5
|
|
6
6
|
rvm:
|
7
|
-
- 2.6.
|
8
|
-
- 2.5.
|
7
|
+
- 2.6.2
|
8
|
+
- 2.5.5
|
9
9
|
|
10
10
|
gemfile:
|
11
|
+
- gemfiles/rails_60.gemfile
|
11
12
|
- gemfiles/rails_52.gemfile
|
12
13
|
- gemfiles/rails_51.gemfile
|
13
14
|
- gemfiles/rails_50.gemfile
|
data/jb.gemspec
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Mokey-patches for Action View 4 and 5
|
3
|
+
|
4
|
+
module Jb
|
5
|
+
module PartialRenderer
|
6
|
+
module JbTemplateDetector
|
7
|
+
# A monkey-patch to inject StrongArray module to Jb partial renderer
|
8
|
+
private def find_partial(*)
|
9
|
+
template = super
|
10
|
+
extend RenderCollectionExtension if template && (template.handler == Jb::Handler)
|
11
|
+
template
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# A horrible monkey-patch to prevent rendered collection from being converted to String
|
16
|
+
module StrongArray
|
17
|
+
def join(*)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def html_safe
|
22
|
+
self
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# A monkey-patch strengthening rendered collection
|
27
|
+
module RenderCollectionExtension
|
28
|
+
private def collection_with_template
|
29
|
+
super.extend StrongArray
|
30
|
+
end
|
31
|
+
|
32
|
+
private def collection_without_template
|
33
|
+
super.extend StrongArray
|
34
|
+
end
|
35
|
+
|
36
|
+
private def render_collection
|
37
|
+
return [] if @collection.blank?
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# A monkey-patch that converts non-partial result to a JSON String
|
44
|
+
module TemplateRenderer
|
45
|
+
module JSONizer
|
46
|
+
def render_template(template, *)
|
47
|
+
template.respond_to?(:handler) && (template.handler == Jb::Handler) ? MultiJson.dump(super) : super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
::ActionView::PartialRenderer.prepend ::Jb::PartialRenderer::JbTemplateDetector
|
54
|
+
::ActionView::TemplateRenderer.prepend ::Jb::TemplateRenderer::JSONizer
|
@@ -1,55 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'multi_json'
|
2
|
+
# Mokey-patches for Action View 6+
|
4
3
|
|
5
4
|
module Jb
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# A horrible monkey-patch to prevent rendered collection from being converted to String
|
17
|
-
module StrongArray
|
18
|
-
def join(*)
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
def html_safe
|
23
|
-
self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# A monkey-patch strengthening rendered collection
|
28
|
-
module RenderCollectionExtension
|
29
|
-
private def collection_with_template
|
30
|
-
super.extend StrongArray
|
31
|
-
end
|
32
|
-
|
33
|
-
private def collection_without_template
|
34
|
-
super.extend StrongArray
|
35
|
-
end
|
36
|
-
|
37
|
-
private def render_collection
|
38
|
-
return [] if @collection.blank?
|
39
|
-
super
|
5
|
+
# A monkey-patch that converts non-partial result to a JSON String
|
6
|
+
module TemplateRenderer
|
7
|
+
module JSONizer
|
8
|
+
def render_template(_view, template, *)
|
9
|
+
rendered_template = super
|
10
|
+
rendered_template.instance_variable_set :@body, MultiJson.dump(rendered_template.body) if template.respond_to?(:handler) && (template.handler == Jb::Handler)
|
11
|
+
rendered_template
|
40
12
|
end
|
41
13
|
end
|
42
14
|
end
|
43
15
|
|
44
|
-
# A monkey-patch
|
45
|
-
module
|
46
|
-
|
47
|
-
|
48
|
-
|
16
|
+
# A monkey-patch for jb template collection result's `body` not to return a String but an Array
|
17
|
+
module PartialRendererExtension
|
18
|
+
private def render_collection(_view, template)
|
19
|
+
obj = super
|
20
|
+
if template.respond_to?(:handler) && (template.handler == Jb::Handler)
|
21
|
+
if ActionView::AbstractRenderer::RenderedCollection::EmptyCollection === obj
|
22
|
+
def obj.body; []; end
|
23
|
+
else
|
24
|
+
def obj.body; @rendered_templates.map(&:body); end
|
25
|
+
end
|
49
26
|
end
|
27
|
+
obj
|
50
28
|
end
|
51
29
|
end
|
52
30
|
end
|
53
31
|
|
54
|
-
::ActionView::PartialRenderer.prepend ::Jb::PartialRenderer::JbTemplateDetector
|
55
32
|
::ActionView::TemplateRenderer.prepend ::Jb::TemplateRenderer::JSONizer
|
33
|
+
::ActionView::PartialRenderer.prepend ::Jb::PartialRendererExtension
|
data/lib/jb/railtie.rb
CHANGED
@@ -4,7 +4,12 @@ module Jb
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
initializer 'jb' do
|
6
6
|
ActiveSupport.on_load :action_view do
|
7
|
-
require '
|
7
|
+
require 'multi_json'
|
8
|
+
if Rails::VERSION::MAJOR >= 6
|
9
|
+
require 'jb/action_view_monkeys'
|
10
|
+
else
|
11
|
+
require 'jb/action_view_legacy_monkeys'
|
12
|
+
end
|
8
13
|
require 'jb/handler'
|
9
14
|
::ActionView::Template.register_template_handler :jb, Jb::Handler
|
10
15
|
end
|
data/lib/jb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Faster and simpler JSON renderer for Rails
|
98
112
|
email:
|
99
113
|
- ronnie@dio.jp
|
@@ -115,12 +129,14 @@ files:
|
|
115
129
|
- gemfiles/rails_50.gemfile
|
116
130
|
- gemfiles/rails_51.gemfile
|
117
131
|
- gemfiles/rails_52.gemfile
|
132
|
+
- gemfiles/rails_60.gemfile
|
118
133
|
- jb.gemspec
|
119
134
|
- lib/generators/rails/jb_generator.rb
|
120
135
|
- lib/generators/rails/scaffold_controller_generator.rb
|
121
136
|
- lib/generators/rails/templates/index.json.jb
|
122
137
|
- lib/generators/rails/templates/show.json.jb
|
123
138
|
- lib/jb.rb
|
139
|
+
- lib/jb/action_view_legacy_monkeys.rb
|
124
140
|
- lib/jb/action_view_monkeys.rb
|
125
141
|
- lib/jb/handler.rb
|
126
142
|
- lib/jb/railtie.rb
|
@@ -144,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
160
|
- !ruby/object:Gem::Version
|
145
161
|
version: '0'
|
146
162
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.7.8
|
163
|
+
rubygems_version: 3.0.3
|
149
164
|
signing_key:
|
150
165
|
specification_version: 4
|
151
166
|
summary: Faster and simpler Jbuilder alternative
|