rabl-rails 0.4.2 → 0.4.3

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: 2874d3a8bc282b5f68501b4b20a238a764a7a50e
4
- data.tar.gz: 84d6d590864951016038bee486096ef7637efc5f
3
+ metadata.gz: dfd78996e96f1bf4dc99f2ffe80c69b57e1d7c72
4
+ data.tar.gz: e7c0c4bcf0d10beba1a814962ac15fd5c55434e7
5
5
  SHA512:
6
- metadata.gz: 6022f49acacdc484fc278c2e770db3f418f89602c17821d83e06339c824228fe4990e37aa9e197cf402155caad62fd35474ac522d2b13aff71e537e13708ed8e
7
- data.tar.gz: cfbc8c2ae6a2f39a1202ec502c6a4fa1d7d0a39952633ac6f27375865ef764f974cfa438168c49d623833816ca71b33dcfe583b482542a0e4d6679f5c71380d8
6
+ metadata.gz: b75c2a1b05cd16037797aa5a2eedb63041be6e0670cef0e0658cadd709e514e96d718d52f6d4e7b616873e91e280439eb08f7a09c4409eebc65ebe5c95f8a704
7
+ data.tar.gz: 87a2345a2b7b02dda10ceadfedbe6e231f3af9fd365fd4ab4d35019184ce7318420d5c92cb02b0013b2a591d0f6765c24cc75b50ea5cf4258d161665fd28bd76
data/.gitignore CHANGED
@@ -8,3 +8,5 @@ rdoc
8
8
  pkg
9
9
  Gemfile.lock
10
10
 
11
+ .ruby-version
12
+ .byebug_history
data/.travis.yml CHANGED
@@ -9,4 +9,6 @@ rvm:
9
9
  - jruby-19mode
10
10
  - rbx-2
11
11
  - 2.0.0
12
- - 2.1.0
12
+ - 2.1.8
13
+ before_install:
14
+ - gem update bundler
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.3
4
+ * Fix custom responder compatibility with responders 2.1 (itkin)
5
+ * Fix bug when template was already loaded by ActionView and causing a nil
6
+ error
7
+
3
8
  ## 0.4.2
4
9
  * Allow to pass locals to partials
5
10
  * Add condition to `attributes`
@@ -78,7 +83,6 @@
78
83
  * Warning message printed on logger when JSON engine fail to load
79
84
 
80
85
  ## 0.1.1
81
-
82
86
  * Add CHANGELOG
83
87
  * Remove unused test in loop
84
88
  * Speed up rendering by not double copying variable from context
data/Gemfile CHANGED
@@ -20,6 +20,11 @@ gem 'railties', rails
20
20
 
21
21
  group :test do
22
22
  gem 'minitest', minitest_version
23
+ gem 'actionpack', rails
24
+
25
+ if rails_version > '4.0.0'
26
+ gem 'actionview', rails
27
+ end
23
28
  end
24
29
 
25
30
  gem 'plist'
data/README.md CHANGED
@@ -279,7 +279,7 @@ end
279
279
 
280
280
  # user.json.rabl
281
281
  merge { |u| partial('users/base', object: u, locals: { display_credit_card: true }) }
282
-
282
+ ```
283
283
 
284
284
  ### Nesting
285
285
 
@@ -50,4 +50,4 @@ module RablRails
50
50
  end
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -68,7 +68,9 @@ module RablRails
68
68
  end
69
69
 
70
70
  def fetch_source(path, view)
71
- view.lookup_context.find_template(path, [], false).source
71
+ t = view.lookup_context.find_template(path, [], false)
72
+ t = t.refresh(view) unless t.source
73
+ t.source
72
74
  end
73
75
  end
74
- end
76
+ end
@@ -5,5 +5,9 @@ module RablRails
5
5
  ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl
6
6
  end
7
7
  end
8
+
9
+ config.after_initialize do
10
+ ActionController::Base.responder = RablRails::Responder if RablRails.configuration.use_custom_responder
11
+ end
8
12
  end
9
- end
13
+ end
@@ -27,7 +27,7 @@ module RablRails
27
27
  #
28
28
  def find_template(name, opt, partial = false)
29
29
  paths = Dir["#@view_path/#{name}{.#@format,}.rabl"]
30
- file_path = paths.find { |path| File.exists?(path) }
30
+ file_path = paths.find { |path| File.exist?(path) }
31
31
 
32
32
  if file_path
33
33
  T.new(File.read(file_path))
@@ -94,4 +94,4 @@ module RablRails
94
94
  Library.instance.get_rendered_template(t.source, c, resource: object)
95
95
  end
96
96
  end
97
- end
97
+ end
@@ -20,13 +20,13 @@ module RablRails
20
20
  elsif has_errors?
21
21
  display_errors
22
22
  else
23
- api_behavior(nil)
23
+ api_behavior
24
24
  end
25
25
  end
26
26
 
27
27
  protected
28
28
 
29
- def api_behavior(error)
29
+ def api_behavior
30
30
  if post?
31
31
  template = if controller.respond_to?(:responder_default_template, true)
32
32
  controller.send(:responder_default_template)
@@ -41,7 +41,7 @@ module RablRails
41
41
  head :no_content
42
42
  end
43
43
  rescue ActionView::MissingTemplate => e
44
- super(e)
44
+ super
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module RablRails
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
data/rabl-rails.gemspec CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/ccocchi/rabl-rails"
11
11
  s.summary = "Fast Rails 3+ templating system with JSON, XML and PList support"
12
12
  s.description = "Fast Rails 3+ templating system with JSON, XML and PList support"
13
+ s.license = 'MIT'
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -18,4 +19,6 @@ Gem::Specification.new do |s|
18
19
  s.add_dependency 'activesupport', '>= 3.1'
19
20
  s.add_dependency 'railties', '>= 3.1'
20
21
  s.add_dependency 'thread_safe', '~> 0.3.1'
22
+
23
+ s.add_development_dependency 'actionpack', '>= 3.1'
21
24
  end
data/test/helper.rb CHANGED
@@ -7,6 +7,9 @@ require 'minitest/autorun'
7
7
 
8
8
  require 'rabl-rails'
9
9
  require 'plist'
10
+ require 'action_dispatch/http/mime_type'
11
+ require 'action_view'
12
+ require 'active_support/core_ext/string/starts_ends_with'
10
13
 
11
14
  if RUBY_ENGINE == 'jruby'
12
15
  require 'nokogiri'
@@ -20,6 +23,8 @@ else
20
23
  Minitest::Unit::TestCase
21
24
  end
22
25
 
26
+ ActionView::Template.register_template_handler :rabl, RablRails::Handlers::Rabl
27
+
23
28
  module Configurable
24
29
  def with_configuration(key, value)
25
30
  accessor = "#{key}="
@@ -84,4 +89,4 @@ class User
84
89
  @id = id
85
90
  @name = name
86
91
  end
87
- end
92
+ end
@@ -1,13 +1,17 @@
1
1
  require 'helper'
2
+ require 'pathname'
3
+ require 'tmpdir'
2
4
 
3
5
  class TestCompiler < MINITEST_TEST_CLASS
6
+ @@tmp_path = Pathname.new(Dir.mktmpdir)
7
+
4
8
  describe 'compiler' do
5
9
  def extract_attributes(nodes)
6
10
  nodes.map(&:hash)
7
11
  end
8
12
 
9
13
  before do
10
- @view = Context.new
14
+ @view = ActionView::Base.new(@@tmp_path, {})
11
15
  @compiler = RablRails::Compiler.new(@view)
12
16
  end
13
17
 
@@ -155,13 +159,13 @@ class TestCompiler < MINITEST_TEST_CLASS
155
159
  end
156
160
 
157
161
  it "compiles child with inline partial notation" do
158
- mock_template = RablRails::CompiledTemplate.new
159
- mock_template.add_node(RablRails::Nodes::Attribute.new(id: :id))
160
-
161
- t = RablRails::Library.instance.stub :compile_template_from_path, mock_template do
162
- @compiler.compile_source(%{child(:user, :partial => 'users/base') })
162
+ File.open(@@tmp_path + 'user.rabl', 'w') do |f|
163
+ f.puts %q{
164
+ attributes :id
165
+ }
163
166
  end
164
167
 
168
+ t = @compiler.compile_source(%{child(:user, :partial => 'user') })
165
169
  child_node = t.nodes.first
166
170
 
167
171
  assert_equal(:user, child_node.name)
@@ -202,32 +206,40 @@ class TestCompiler < MINITEST_TEST_CLASS
202
206
  end
203
207
 
204
208
  it "extends other template" do
205
- template = RablRails::CompiledTemplate.new
206
- template.add_node RablRails::Nodes::Attribute.new(id: :id)
207
-
208
- library = MiniTest::Mock.new
209
- library.expect :compile_template_from_path, template, ['users/base', @view]
210
-
211
- t = RablRails::Library.stub :instance, library do
212
- @compiler.compile_source(%{ extends 'users/base' })
209
+ File.open(@@tmp_path + 'user.rabl', 'w') do |f|
210
+ f.puts %q{
211
+ attributes :id
212
+ }
213
213
  end
214
+ t = @compiler.compile_source(%{ extends 'user' })
214
215
  assert_equal([{ :id => :id }], extract_attributes(t.nodes))
215
- library.verify
216
216
  end
217
217
 
218
218
  it "compiles extend without overwriting nodes previously defined" do
219
- template = RablRails::CompiledTemplate.new
220
- template.add_node(RablRails::Nodes::Condition.new(->{ true }, ->{ 'foo' }))
221
-
222
- t = RablRails::Library.instance.stub :compile_template_from_path, template do
223
- @compiler.compile_source(%{
224
- condition(-> { false }) { 'bar' }
225
- extends('users/xtnd')
226
- })
219
+ File.open(@@tmp_path + 'xtnd.rabl', 'w') do |f|
220
+ f.puts %q{
221
+ condition(-> { true }) { 'foo' }
222
+ }
227
223
  end
224
+ t = @compiler.compile_source(%{
225
+ condition(-> { false }) { 'bar' }
226
+ extends 'xtnd'
227
+ })
228
228
  assert_equal(2, t.nodes.size)
229
229
  end
230
230
 
231
+ it "extends template that has been compiled previously by ActionView" do
232
+ File.open(@@tmp_path + 'user.rabl', 'w') do |f|
233
+ f.puts %q{
234
+ attributes :id
235
+ }
236
+ end
237
+ t = @view.lookup_context.find_template('user')
238
+ t.send(:compile!, @view)
239
+ t = @compiler.compile_source(%{ extends 'user' })
240
+ assert_equal([{ :id => :id }], extract_attributes(t.nodes))
241
+ end
242
+
231
243
  it "compiles node" do
232
244
  t = @compiler.compile_source(%{ node(:foo) { bar } })
233
245
 
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.4.2
4
+ version: 0.4.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: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.3.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionpack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
55
69
  description: Fast Rails 3+ templating system with JSON, XML and PList support
56
70
  email:
57
71
  - cocchi.c@gmail.com
@@ -105,7 +119,8 @@ files:
105
119
  - test/test_library.rb
106
120
  - test/test_render.rb
107
121
  homepage: https://github.com/ccocchi/rabl-rails
108
- licenses: []
122
+ licenses:
123
+ - MIT
109
124
  metadata: {}
110
125
  post_install_message:
111
126
  rdoc_options: []
@@ -123,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
138
  version: '0'
124
139
  requirements: []
125
140
  rubyforge_project:
126
- rubygems_version: 2.4.5
141
+ rubygems_version: 2.5.1
127
142
  signing_key:
128
143
  specification_version: 4
129
144
  summary: Fast Rails 3+ templating system with JSON, XML and PList support
@@ -139,4 +154,3 @@ test_files:
139
154
  - test/test_helpers.rb
140
155
  - test/test_library.rb
141
156
  - test/test_render.rb
142
- has_rdoc: