rabl-rails 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +8 -1
- data/lib/rabl-rails/compiler.rb +9 -0
- data/lib/rabl-rails/nodes.rb +1 -0
- data/lib/rabl-rails/nodes/const.rb +12 -0
- data/lib/rabl-rails/version.rb +1 -1
- data/lib/rabl-rails/visitors/to_hash.rb +4 -0
- data/test/test_compiler.rb +10 -0
- data/test/test_hash_visitor.rb +5 -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: 4807b83a2eb921feedfb2b1a183c8cc2a8f27ef6
|
4
|
+
data.tar.gz: 511aa8bd4d1c5c9b034b695545e083dd761e31b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d17c495e276a6344ad8e9bbf2162aebf7e056f575367bcfde60399f683fceb90a5216a3b76155e42386b017411197b80afe7eeff96e8bdb31fc55c47f83ab1fe
|
7
|
+
data.tar.gz: 2cc491b7e1298cb12e25bb4e365d0c86ca87fff0b73f125a1abc11caa80f575ac5d0ac1cb27ebdf42eb4fe1e3fd101a46fe23e0e4a307a3f06982fd7f355585b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -204,7 +204,7 @@ end
|
|
204
204
|
|
205
205
|
### Custom nodes
|
206
206
|
|
207
|
-
You can create custom node in your response, based on the result of
|
207
|
+
You can create custom node in your response, based on the result of a given block
|
208
208
|
|
209
209
|
```ruby
|
210
210
|
object :@user
|
@@ -212,6 +212,13 @@ node(:full_name) { |u| u.first_name + " " + u.last_name }
|
|
212
212
|
# => { "user" : { "full_name" : "John Doe" } }
|
213
213
|
```
|
214
214
|
|
215
|
+
or with an assigned constant
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
const(:api_version, API::VERSION)
|
219
|
+
const(:locale, 'fr_FR')
|
220
|
+
```
|
221
|
+
|
215
222
|
You can add condition on your custom nodes (if the condition is evaluated to false, the node will not be included).
|
216
223
|
|
217
224
|
```ruby
|
data/lib/rabl-rails/compiler.rb
CHANGED
@@ -98,6 +98,15 @@ module RablRails
|
|
98
98
|
end
|
99
99
|
alias_method :code, :node
|
100
100
|
|
101
|
+
#
|
102
|
+
# Creates a constant node in the json output.
|
103
|
+
# Example:
|
104
|
+
# const(:locale, 'fr_FR')
|
105
|
+
#
|
106
|
+
def const(name, value)
|
107
|
+
@template.add_node Nodes::Const.new(name, value)
|
108
|
+
end
|
109
|
+
|
101
110
|
#
|
102
111
|
# Merge arbitrary data into json output. Given block should
|
103
112
|
# return a hash.
|
data/lib/rabl-rails/nodes.rb
CHANGED
data/lib/rabl-rails/version.rb
CHANGED
data/test/test_compiler.rb
CHANGED
@@ -217,6 +217,16 @@ class TestCompiler < Minitest::Test
|
|
217
217
|
assert_equal([{ :id => :id }], extract_attributes(glue_node.nodes))
|
218
218
|
end
|
219
219
|
|
220
|
+
it "compiles constant node" do
|
221
|
+
t = @compiler.compile_source(%{
|
222
|
+
const(:locale, 'fr_FR')
|
223
|
+
})
|
224
|
+
|
225
|
+
const_node = t.nodes.first
|
226
|
+
assert_equal :locale, const_node.name
|
227
|
+
assert_equal 'fr_FR', const_node.value
|
228
|
+
end
|
229
|
+
|
220
230
|
it "extends other template" do
|
221
231
|
t = @compiler.compile_source(%{ extends 'user' })
|
222
232
|
assert_equal([{ :id => :id }], extract_attributes(t.nodes))
|
data/test/test_hash_visitor.rb
CHANGED
@@ -136,6 +136,11 @@ class TestHashVisitor < Minitest::Test
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
+
it 'renders a const node' do
|
140
|
+
@nodes << RablRails::Nodes::Const.new(:locale, 'fr_FR')
|
141
|
+
assert_equal({ locale: 'fr_FR' }, visitor_result)
|
142
|
+
end
|
143
|
+
|
139
144
|
describe 'with a condition node' do
|
140
145
|
before do
|
141
146
|
@ns = [RablRails::Nodes::Attribute.new(name: :name)]
|
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.2
|
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: 2017-08-
|
11
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/rabl-rails/nodes/child.rb
|
107
107
|
- lib/rabl-rails/nodes/code.rb
|
108
108
|
- lib/rabl-rails/nodes/condition.rb
|
109
|
+
- lib/rabl-rails/nodes/const.rb
|
109
110
|
- lib/rabl-rails/nodes/extend.rb
|
110
111
|
- lib/rabl-rails/nodes/glue.rb
|
111
112
|
- lib/rabl-rails/railtie.rb
|
@@ -150,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
151
|
version: '0'
|
151
152
|
requirements: []
|
152
153
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
154
|
+
rubygems_version: 2.4.5.2
|
154
155
|
signing_key:
|
155
156
|
specification_version: 4
|
156
157
|
summary: Fast Rails 4+ templating system with JSON, XML and PList support
|