rabl-rails 0.5.1 → 0.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ecb1329a32490a735d1554c309c4d22b7a4eecf
4
- data.tar.gz: 19958bd42ebd7ef7ff2e3f6d961c034c9409f17d
3
+ metadata.gz: 4807b83a2eb921feedfb2b1a183c8cc2a8f27ef6
4
+ data.tar.gz: 511aa8bd4d1c5c9b034b695545e083dd761e31b6
5
5
  SHA512:
6
- metadata.gz: 981a64007d589ba27a1b2ce4f85cd63763dc6335fc9d96ddd5df71178002c3648a44f6cbff7a0d7ad4fc1639b478278263898829f940ee002a645099c45ef3c3
7
- data.tar.gz: ab7d0fd23fe2fcce56ac0ad149629e89d2125e3ee55f8fa0e97e0fda435012f728a73c63cdf0c156913eefa1d8a82fbe3cd0b030c83238d04cf4ca9a5ee9ee0d
6
+ metadata.gz: d17c495e276a6344ad8e9bbf2162aebf7e056f575367bcfde60399f683fceb90a5216a3b76155e42386b017411197b80afe7eeff96e8bdb31fc55c47f83ab1fe
7
+ data.tar.gz: 2cc491b7e1298cb12e25bb4e365d0c86ca87fff0b73f125a1abc11caa80f575ac5d0ac1cb27ebdf42eb4fe1e3fd101a46fe23e0e4a307a3f06982fd7f355585b
@@ -1,7 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.2
4
+ * Add `const` node
5
+
3
6
  ## 0.5.1
4
- * Fix bug when trying to compile partials with caching enabled
7
+ * Fix bug when trying to compile partials with caching enabled
5
8
 
6
9
  ## 0.5.0
7
10
  * Add requirement ruby >= 2.2
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 the given block.
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
@@ -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.
@@ -1,4 +1,5 @@
1
1
  require 'rabl-rails/nodes/attribute'
2
+ require 'rabl-rails/nodes/const'
2
3
  require 'rabl-rails/nodes/glue'
3
4
  require 'rabl-rails/nodes/child'
4
5
  require 'rabl-rails/nodes/code'
@@ -0,0 +1,12 @@
1
+ module RablRails
2
+ module Nodes
3
+ class Const
4
+ attr_reader :name, :value
5
+
6
+ def initialize(name, value)
7
+ @name = name
8
+ @value = value
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -52,6 +52,10 @@ module Visitors
52
52
  end
53
53
  end
54
54
 
55
+ def visit_Const n
56
+ @_result[n.name] = n.value
57
+ end
58
+
55
59
  def visit_Condition n
56
60
  @_result.merge!(sub_visit(_resource, n.nodes)) if instance_exec _resource, &(n.condition)
57
61
  end
@@ -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))
@@ -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.1
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-14 00:00:00.000000000 Z
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.6.11
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