rabl-rails 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/CHANGELOG.md +3 -0
- data/lib/rabl-rails/compiler.rb +9 -3
- data/lib/rabl-rails/nodes.rb +1 -0
- data/lib/rabl-rails/nodes/polymorphic.rb +11 -0
- data/lib/rabl-rails/version.rb +1 -1
- data/lib/rabl-rails/visitors/to_hash.rb +6 -0
- data/test/test_compiler.rb +7 -0
- data/test/test_hash_visitor.rb +14 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dedc8586508a3810863c0064ec79ed16bae0912c
|
4
|
+
data.tar.gz: c025be318058b389563a9103f5855b1085b3ffaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046f7ded9881826bbbe283f160c9136b905dbadaa0eff728479f790b380747d5d4a7c6d6f379ba5d50bf8d4de440a8b7d2922d6bdef0adb10b02d576c1bd4e47
|
7
|
+
data.tar.gz: d0ce45379a3281561a768bc605f153a3b46b64b82bbb37a1300ed67273ea8ac09e7ea08b0687becd22eab7c73668e5eda454a3d0490487f47d3b70a2e054d81e
|
data/.travis.yml
CHANGED
@@ -3,19 +3,15 @@ cache: bundler
|
|
3
3
|
dist: trusty
|
4
4
|
env:
|
5
5
|
- "RAILS_VERSION=4.2.6"
|
6
|
-
- "RAILS_VERSION=
|
6
|
+
- "RAILS_VERSION=5.2.0"
|
7
7
|
rvm:
|
8
8
|
- 2.2.7
|
9
|
-
- 2.3.4
|
10
9
|
- 2.4.1
|
11
|
-
- jruby
|
12
|
-
- rbx-3
|
10
|
+
- jruby
|
11
|
+
- rbx-3
|
13
12
|
before_install:
|
14
13
|
- gem update bundler
|
15
14
|
matrix:
|
16
15
|
fast_finish: true
|
17
16
|
allow_failures:
|
18
17
|
- env: RAILS_VERSION=master
|
19
|
-
exclude:
|
20
|
-
- rvm: 2.1.8
|
21
|
-
env: "RAILS_VERSION=master"
|
data/CHANGELOG.md
CHANGED
data/lib/rabl-rails/compiler.rb
CHANGED
@@ -62,7 +62,7 @@ module RablRails
|
|
62
62
|
# Creates a child node to be included in the output.
|
63
63
|
# name_or data can be an object or collection or a method to call on the data. It
|
64
64
|
# accepts :root and :partial options.
|
65
|
-
#
|
65
|
+
# Note that partial and blocks are not compatible
|
66
66
|
# Example:
|
67
67
|
# child(:@posts, :root => :posts) { attribute :id }
|
68
68
|
# child(:posts, :partial => 'posts/base')
|
@@ -122,10 +122,16 @@ module RablRails
|
|
122
122
|
# Extends an existing rabl template
|
123
123
|
# Example:
|
124
124
|
# extends 'users/base'
|
125
|
+
# extends ->(item) { "v1/#{item.class}/_core" }
|
125
126
|
# extends 'posts/base', locals: { hide_comments: true }
|
126
127
|
#
|
127
|
-
def extends(
|
128
|
-
|
128
|
+
def extends(path_or_lambda, options = nil)
|
129
|
+
if path_or_lambda.is_a?(Proc)
|
130
|
+
@template.add_node Nodes::Polymorphic.new(path_or_lambda)
|
131
|
+
return
|
132
|
+
end
|
133
|
+
|
134
|
+
other = Library.instance.compile_template_from_path(path_or_lambda, @view)
|
129
135
|
|
130
136
|
if options && options.is_a?(Hash)
|
131
137
|
@template.add_node Nodes::Extend.new(other.nodes, options[:locals])
|
data/lib/rabl-rails/nodes.rb
CHANGED
data/lib/rabl-rails/version.rb
CHANGED
@@ -67,6 +67,12 @@ module Visitors
|
|
67
67
|
@_locals = {}
|
68
68
|
end
|
69
69
|
|
70
|
+
def visit_Polymorphic n
|
71
|
+
template_path = n.template_lambda.call(_resource)
|
72
|
+
template = RablRails::Library.instance.compile_template_from_path(template_path, @_context)
|
73
|
+
@_result.merge!(sub_visit(_resource, template.nodes))
|
74
|
+
end
|
75
|
+
|
70
76
|
def result
|
71
77
|
case RablRails.configuration.result_flags
|
72
78
|
when 0
|
data/test/test_compiler.rb
CHANGED
@@ -232,6 +232,13 @@ class TestCompiler < Minitest::Test
|
|
232
232
|
assert_equal([{ :id => :id }], extract_attributes(t.nodes))
|
233
233
|
end
|
234
234
|
|
235
|
+
it "extends with a lambda" do
|
236
|
+
t = @compiler.compile_source(%{ extends -> { 'user' } })
|
237
|
+
node = t.nodes.first
|
238
|
+
assert_instance_of(RablRails::Nodes::Polymorphic, node)
|
239
|
+
assert_equal('user', node.template_lambda.call)
|
240
|
+
end
|
241
|
+
|
235
242
|
it "compiles extend without overwriting nodes previously defined" do
|
236
243
|
File.open(@@tmp_path + 'xtnd.rabl', 'w') do |f|
|
237
244
|
f.puts %q{
|
data/test/test_hash_visitor.rb
CHANGED
@@ -185,6 +185,20 @@ class TestHashVisitor < Minitest::Test
|
|
185
185
|
library.verify
|
186
186
|
end
|
187
187
|
|
188
|
+
it 'renders partial defined in node' do
|
189
|
+
template = RablRails::CompiledTemplate.new
|
190
|
+
template.add_node(RablRails::Nodes::Attribute.new(name: :name))
|
191
|
+
library = MiniTest::Mock.new
|
192
|
+
library.expect :compile_template_from_path, template, ['users/base', @context]
|
193
|
+
|
194
|
+
@nodes << RablRails::Nodes::Polymorphic.new(->(_) { 'users/base' })
|
195
|
+
RablRails::Library.stub :instance, library do
|
196
|
+
assert_equal({ name: 'Marty' }, visitor_result)
|
197
|
+
end
|
198
|
+
|
199
|
+
library.verify
|
200
|
+
end
|
201
|
+
|
188
202
|
it 'allows uses of locals variables with partials' do
|
189
203
|
template = RablRails::CompiledTemplate.new
|
190
204
|
template.add_node(RablRails::Nodes::Code.new(:hide_comments, ->(u) { locals[:hide_comments] }, ->(u) { locals.key?(:hide_comments) }))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Cocchi-Perrier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- lib/rabl-rails/nodes/const.rb
|
110
110
|
- lib/rabl-rails/nodes/extend.rb
|
111
111
|
- lib/rabl-rails/nodes/glue.rb
|
112
|
+
- lib/rabl-rails/nodes/polymorphic.rb
|
112
113
|
- lib/rabl-rails/railtie.rb
|
113
114
|
- lib/rabl-rails/renderers/hash.rb
|
114
115
|
- lib/rabl-rails/renderers/json.rb
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.6.13
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: Fast Rails 4+ templating system with JSON, XML and PList support
|