breezy_template 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/breezy_template/active_support.rb +10 -18
- data/lib/breezy_template/cache_extension.rb +1 -19
- data/lib/breezy_template/configuration.rb +3 -2
- data/lib/breezy_template/deferment_extension.rb +1 -19
- data/lib/breezy_template/dependency_tracker.rb +29 -40
- data/lib/breezy_template/handler.rb +14 -7
- data/lib/breezy_template/partial_extension.rb +0 -36
- data/lib/breezy_template/var.rb +19 -0
- data/lib/breezy_template.rb +1 -0
- data/test/extensions_test.rb +28 -13
- data/test/template_test.rb +2 -2
- metadata +26 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcc3ba9f23a74e82348d910f9416e89261fbe158
|
4
|
+
data.tar.gz: 915a033140bc98f1a30767d349c511fe4bd4decf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acd0a3eef49b95f992b091e264d464f1de67c7691b50a6aadf04932703d166bbe7de0b2f08e05ea724e2c778ce3fff88c2f8ec6baae5c4d972e0dd8d2722754d
|
7
|
+
data.tar.gz: f309c6efe2251650ae1648bc6cf3959a4ab537ef4df1dcce0b65b013598c3fb00c20d203e4a0dd016a3aacac3e99cef4700fc56aefc0664817a409396b6b8b40
|
@@ -1,23 +1,15 @@
|
|
1
1
|
# https://github.com/rails/jbuilder/issues/204
|
2
|
-
|
3
|
-
module
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
alias_method :original_jsonify, :jsonify
|
2
|
+
module ActiveSupport
|
3
|
+
module JSON
|
4
|
+
module Encoding
|
5
|
+
class JSONGemEncoder
|
6
|
+
alias_method :original_jsonify, :jsonify
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
elsif ::BreezyTemplate::DeferVar === value
|
15
|
-
value
|
16
|
-
elsif ::BreezyTemplate::Undefined === value
|
17
|
-
value
|
18
|
-
else
|
19
|
-
original_jsonify(value)
|
20
|
-
end
|
8
|
+
def jsonify(value)
|
9
|
+
if ::BreezyTemplate::Var === value
|
10
|
+
value
|
11
|
+
else
|
12
|
+
original_jsonify(value)
|
21
13
|
end
|
22
14
|
end
|
23
15
|
end
|
@@ -2,24 +2,6 @@ require 'breezy_template/breezy_template'
|
|
2
2
|
|
3
3
|
class BreezyTemplate
|
4
4
|
module CacheExtension
|
5
|
-
class Digest
|
6
|
-
def initialize(digest)
|
7
|
-
@digest = "cache[\"#{digest}\"]"
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_json(*)
|
11
|
-
@digest
|
12
|
-
end
|
13
|
-
|
14
|
-
def as_json(*)
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def encode_json(*)
|
19
|
-
@digest
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
5
|
def _result(value, *args)
|
24
6
|
options = _cache_options(args[0])
|
25
7
|
if options
|
@@ -154,7 +136,7 @@ class BreezyTemplate
|
|
154
136
|
else
|
155
137
|
v = blank_or_value
|
156
138
|
@js.push(v)
|
157
|
-
|
139
|
+
::BreezyTemplate::Var.new("cache[\"#{key}\"]")
|
158
140
|
end
|
159
141
|
end
|
160
142
|
|
@@ -2,10 +2,11 @@ require 'breezy_template/breezy_template'
|
|
2
2
|
|
3
3
|
class BreezyTemplate
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :track_sprockets_assets, :track_pack_assets
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@track_sprockets_assets = ['application.js', 'application.css']
|
9
|
+
@track_pack_assets = ['application.js']
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -1,24 +1,6 @@
|
|
1
1
|
require 'breezy_template/breezy_template'
|
2
2
|
|
3
3
|
class BreezyTemplate
|
4
|
-
class Undefined
|
5
|
-
def initialize
|
6
|
-
@value = "undefined"
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_json(*)
|
10
|
-
@value
|
11
|
-
end
|
12
|
-
|
13
|
-
def as_json(*)
|
14
|
-
self
|
15
|
-
end
|
16
|
-
|
17
|
-
def encode_json(*)
|
18
|
-
@value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
4
|
module DefermentExtension
|
23
5
|
ACTIVE_MODES = [:auto, :manual].freeze
|
24
6
|
|
@@ -28,7 +10,7 @@ class BreezyTemplate
|
|
28
10
|
if _deferment_auto?(options)
|
29
11
|
@js.push(_breezy_visit_current(@path))
|
30
12
|
end
|
31
|
-
return _set_value key,
|
13
|
+
return _set_value key, ::BreezyTemplate::Var.new('undefined')
|
32
14
|
else
|
33
15
|
super
|
34
16
|
end
|
@@ -1,50 +1,39 @@
|
|
1
1
|
# This was taken from jbuilder
|
2
2
|
require 'breezy_template/breezy_template'
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_view/dependency_tracker'
|
3
5
|
|
4
|
-
dependency_tracker =
|
6
|
+
dependency_tracker = ::ActionView::DependencyTracker
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
class BreezyTemplate
|
9
|
+
module DependencyTrackerMethods
|
10
|
+
# Matches:
|
11
|
+
# json.partial! partial: "comments/comment"
|
12
|
+
# json.comments @post.comments, partial: "comments/comment", as: :comment
|
13
|
+
# json.array! @posts, partial: "posts/post", as: :post
|
14
|
+
# = render partial: "account"
|
15
|
+
#
|
16
|
+
INDIRECT_RENDERS = /
|
17
|
+
(?::partial\s*=>|partial:) # partial: or :partial =>
|
18
|
+
\s* # optional whitespace
|
19
|
+
\[* # optional Bracket
|
20
|
+
\s* # optional whitespace
|
21
|
+
(['"])([^'"]+)\1 # quoted value
|
22
|
+
/x
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
# Matches:
|
22
|
-
# json.partial! partial: "comments/comment"
|
23
|
-
# json.comments @post.comments, partial: "comments/comment", as: :comment
|
24
|
-
# json.array! @posts, partial: "posts/post", as: :post
|
25
|
-
# = render partial: "account"
|
26
|
-
#
|
27
|
-
INDIRECT_RENDERS = /
|
28
|
-
(?::partial\s*=>|partial:) # partial: or :partial =>
|
29
|
-
\s* # optional whitespace
|
30
|
-
\[* # optional Bracket
|
31
|
-
\s* # optional whitespace
|
32
|
-
(['"])([^'"]+)\1 # quoted value
|
33
|
-
/x
|
34
|
-
|
35
|
-
def dependencies
|
36
|
-
indirect_dependencies + explicit_dependencies
|
37
|
-
end
|
24
|
+
def dependencies
|
25
|
+
indirect_dependencies + explicit_dependencies
|
26
|
+
end
|
38
27
|
|
39
|
-
|
28
|
+
private
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
30
|
+
def indirect_dependencies
|
31
|
+
source.scan(INDIRECT_RENDERS).map(&:second)
|
44
32
|
end
|
45
33
|
end
|
46
|
-
|
47
|
-
::BreezyTemplate::DependencyTracker = Class.new(dependency_tracker::ERBTracker)
|
48
|
-
::BreezyTemplate::DependencyTracker.send :include, ::BreezyTemplate::DependencyTrackerMethods
|
49
|
-
dependency_tracker.register_tracker :breezy, ::BreezyTemplate::DependencyTracker
|
50
34
|
end
|
35
|
+
|
36
|
+
::BreezyTemplate::DependencyTracker = Class.new(dependency_tracker::ERBTracker)
|
37
|
+
::BreezyTemplate::DependencyTracker.send :include, ::BreezyTemplate::DependencyTrackerMethods
|
38
|
+
|
39
|
+
::ActionView::DependencyTracker.register_tracker :breezy, ::BreezyTemplate::DependencyTracker
|
@@ -21,14 +21,21 @@ class BreezyTemplate
|
|
21
21
|
json.csrf_token form_authenticity_token
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
__sprockets_assets = (::BreezyTemplate.configuration.track_sprockets_assets || []).map do |asset|
|
25
|
+
asset_path(asset)
|
26
|
+
end
|
27
|
+
|
28
|
+
__pack_assets = []
|
29
|
+
if defined?(asset_pack_path)
|
30
|
+
__pack_assets = (::BreezyTemplate.configuration.track_pack_assets || []).map do |asset|
|
31
|
+
asset_pack_path(asset)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
35
|
+
if __sprockets_assets.any? || __pack_assets.any?
|
36
|
+
json.assets (__sprockets_assets + __pack_assets)
|
37
|
+
end
|
38
|
+
|
32
39
|
if defined?(breezy_filter) && !!breezy_filter
|
33
40
|
json.action 'graft'
|
34
41
|
json.path breezy_filter
|
@@ -38,8 +45,8 @@ class BreezyTemplate
|
|
38
45
|
session.delete(:breezy_filter)
|
39
46
|
end
|
40
47
|
|
41
|
-
json.joints ::BreezyTemplate::
|
42
|
-
json.defers ::BreezyTemplate::
|
48
|
+
json.joints ::BreezyTemplate::Var.new('joints')
|
49
|
+
json.defers ::BreezyTemplate::Var.new('defers')
|
43
50
|
|
44
51
|
json.target!
|
45
52
|
end
|
@@ -2,42 +2,6 @@ require 'breezy_template/breezy_template'
|
|
2
2
|
|
3
3
|
class BreezyTemplate
|
4
4
|
module PartialExtension
|
5
|
-
class DeferVar
|
6
|
-
def initialize
|
7
|
-
@digest = "defers"
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_json(*)
|
11
|
-
@digest
|
12
|
-
end
|
13
|
-
|
14
|
-
def as_json(*)
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def encode_json(*)
|
19
|
-
@digest
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class JointVar
|
24
|
-
def initialize
|
25
|
-
@digest = "joints"
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_json(*)
|
29
|
-
@digest
|
30
|
-
end
|
31
|
-
|
32
|
-
def as_json(*)
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def encode_json(*)
|
37
|
-
@digest
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
5
|
def set!(key, value = BLANK, *args)
|
42
6
|
options = args.last || {}
|
43
7
|
|
data/lib/breezy_template.rb
CHANGED
data/test/extensions_test.rb
CHANGED
@@ -51,7 +51,8 @@ end
|
|
51
51
|
class BreezyTemplateTest < ActionView::TestCase
|
52
52
|
setup do
|
53
53
|
self.request_forgery = false
|
54
|
-
BreezyTemplate.configuration.
|
54
|
+
BreezyTemplate.configuration.track_sprockets_assets = []
|
55
|
+
BreezyTemplate.configuration.track_pack_assets = []
|
55
56
|
|
56
57
|
# this is a stub. Normally this would be set by the
|
57
58
|
# controller locals
|
@@ -73,6 +74,10 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
73
74
|
@breezy_filter
|
74
75
|
end
|
75
76
|
|
77
|
+
def asset_pack_path(asset)
|
78
|
+
return asset
|
79
|
+
end
|
80
|
+
|
76
81
|
def request
|
77
82
|
@request
|
78
83
|
end
|
@@ -96,7 +101,9 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
96
101
|
end
|
97
102
|
|
98
103
|
def action_controller_test_request
|
99
|
-
if ::Rails.version.start_with?('5')
|
104
|
+
if ::Rails.version.start_with?('5.1')
|
105
|
+
::ActionController::TestRequest.create({})
|
106
|
+
elsif ::Rails.version.start_with?('5')
|
100
107
|
::ActionController::TestRequest.create
|
101
108
|
else
|
102
109
|
::ActionController::TestRequest.new
|
@@ -188,9 +195,10 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
188
195
|
|
189
196
|
assert_equal expected, result
|
190
197
|
end
|
191
|
-
|
198
|
+
|
192
199
|
test "render with asset tracking" do
|
193
|
-
BreezyTemplate.configuration.
|
200
|
+
BreezyTemplate.configuration.track_sprockets_assets = ['test.js', 'test.css']
|
201
|
+
BreezyTemplate.configuration.track_pack_assets = ['test_pack.js', 'test_pack.css']
|
194
202
|
|
195
203
|
result = jbuild(<<-TEMPLATE)
|
196
204
|
json.content "hello"
|
@@ -201,7 +209,7 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
201
209
|
var joints={};
|
202
210
|
var cache={};
|
203
211
|
var defers=[];
|
204
|
-
return ({"data":{"content":"hello"},"assets":["/test.js","/test.css"],"joints":joints,"defers":defers});
|
212
|
+
return ({"data":{"content":"hello"},"assets":["/test.js","/test.css","test_pack.js","test_pack.css"],"joints":joints,"defers":defers});
|
205
213
|
})()
|
206
214
|
JS
|
207
215
|
|
@@ -231,7 +239,7 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
231
239
|
end
|
232
240
|
|
233
241
|
test "wrapping jbuilder contents inside Breezy with additional options" do
|
234
|
-
BreezyTemplate.configuration.
|
242
|
+
BreezyTemplate.configuration.track_sprockets_assets = ['test.js', 'test.css']
|
235
243
|
self.breezy = { title: 'this is fun' }
|
236
244
|
|
237
245
|
result = jbuild(<<-TEMPLATE)
|
@@ -1013,12 +1021,17 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
1013
1021
|
end
|
1014
1022
|
|
1015
1023
|
test "filtering for a node of a AR relation in a tree by id via an appended where clause" do
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1024
|
+
Post.delete_all
|
1025
|
+
Note.delete_all
|
1026
|
+
|
1027
|
+
post = Post.create
|
1028
|
+
first_note = post.notes.create(title: 'first')
|
1029
|
+
post.notes.create(title: 'second')
|
1020
1030
|
|
1021
|
-
|
1031
|
+
result = jbuild(<<-JBUILDER, breezy_filter: "hit.hit2.id=#{first_note.id}")
|
1032
|
+
post = Post.first
|
1033
|
+
first_note = Note.where(title: 'first').first
|
1034
|
+
post.notes.expects(:where).once().with('id'=>first_note.id).returns([{id: first_note.id, title: 'first'}])
|
1022
1035
|
|
1023
1036
|
json.hit do
|
1024
1037
|
json.hit2 do
|
@@ -1031,14 +1044,14 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
1031
1044
|
JBUILDER
|
1032
1045
|
|
1033
1046
|
Rails.cache.clear
|
1034
|
-
|
1047
|
+
id = Note.where(title: 'first').first.id
|
1035
1048
|
expected = strip_format(<<-JS)
|
1036
1049
|
(function(){
|
1037
1050
|
var joints={};
|
1038
1051
|
var cache={};
|
1039
1052
|
var defers=[];
|
1040
1053
|
return (
|
1041
|
-
{"data":{"title":"first"},"action":"graft","path":"hit.hit2.id
|
1054
|
+
{"data":{"title":"first"},"action":"graft","path":"hit.hit2.id=#{id}","joints":joints,"defers":defers}
|
1042
1055
|
);
|
1043
1056
|
})()
|
1044
1057
|
JS
|
@@ -1290,3 +1303,5 @@ class BreezyTemplateTest < ActionView::TestCase
|
|
1290
1303
|
assert_equal expected, result
|
1291
1304
|
end
|
1292
1305
|
end
|
1306
|
+
|
1307
|
+
|
data/test/template_test.rb
CHANGED
@@ -76,7 +76,7 @@ class TemplateTest < ActiveSupport::TestCase
|
|
76
76
|
end
|
77
77
|
|
78
78
|
assert result.has_key?('content')
|
79
|
-
|
79
|
+
assert_nil result['content']
|
80
80
|
end
|
81
81
|
|
82
82
|
test 'multiple keys' do
|
@@ -156,7 +156,7 @@ class TemplateTest < ActiveSupport::TestCase
|
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
|
-
|
159
|
+
assert_nil result['author']['name']
|
160
160
|
assert_equal 32, result['author']['age']
|
161
161
|
end
|
162
162
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breezy_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johny Ho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: multi_json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,30 @@ dependencies:
|
|
56
56
|
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
82
|
+
version: '12.0'
|
69
83
|
description: Breezy Templates for React props
|
70
84
|
email: jho406@gmail.com
|
71
85
|
executables: []
|
@@ -86,6 +100,7 @@ files:
|
|
86
100
|
- lib/breezy_template/key_formatter.rb
|
87
101
|
- lib/breezy_template/partial_extension.rb
|
88
102
|
- lib/breezy_template/search_extension.rb
|
103
|
+
- lib/breezy_template/var.rb
|
89
104
|
- test/dependency_tracker_test.rb
|
90
105
|
- test/extensions_test.rb
|
91
106
|
- test/template_test.rb
|
@@ -102,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
117
|
requirements:
|
103
118
|
- - ">="
|
104
119
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
120
|
+
version: 2.2.2
|
106
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
122
|
requirements:
|
108
123
|
- - ">="
|