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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4807b83a2eb921feedfb2b1a183c8cc2a8f27ef6
4
- data.tar.gz: 511aa8bd4d1c5c9b034b695545e083dd761e31b6
3
+ metadata.gz: dedc8586508a3810863c0064ec79ed16bae0912c
4
+ data.tar.gz: c025be318058b389563a9103f5855b1085b3ffaf
5
5
  SHA512:
6
- metadata.gz: d17c495e276a6344ad8e9bbf2162aebf7e056f575367bcfde60399f683fceb90a5216a3b76155e42386b017411197b80afe7eeff96e8bdb31fc55c47f83ab1fe
7
- data.tar.gz: 2cc491b7e1298cb12e25bb4e365d0c86ca87fff0b73f125a1abc11caa80f575ac5d0ac1cb27ebdf42eb4fe1e3fd101a46fe23e0e4a307a3f06982fd7f355585b
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=master"
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-9.1.12.0
12
- - rbx-3.71
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
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.3
4
+ * Allow `extends` to accept lambdas
5
+
3
6
  ## 0.5.2
4
7
  * Add `const` node
5
8
 
@@ -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
- # Notes that partial and blocks are not compatible
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(path, options = nil)
128
- other = Library.instance.compile_template_from_path(path, @view)
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])
@@ -5,3 +5,4 @@ require 'rabl-rails/nodes/child'
5
5
  require 'rabl-rails/nodes/code'
6
6
  require 'rabl-rails/nodes/condition'
7
7
  require 'rabl-rails/nodes/extend'
8
+ require 'rabl-rails/nodes/polymorphic'
@@ -0,0 +1,11 @@
1
+ module RablRails
2
+ module Nodes
3
+ class Polymorphic
4
+ attr_reader :template_lambda
5
+
6
+ def initialize(template_lambda)
7
+ @template_lambda = template_lambda
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -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
@@ -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{
@@ -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.2
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: 2017-08-25 00:00:00.000000000 Z
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.4.5.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