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 +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +5 -0
- data/README.md +1 -1
- data/lib/rabl-rails/configuration.rb +1 -1
- data/lib/rabl-rails/library.rb +4 -2
- data/lib/rabl-rails/railtie.rb +5 -1
- data/lib/rabl-rails/renderer.rb +2 -2
- data/lib/rabl-rails/responder.rb +4 -4
- data/lib/rabl-rails/version.rb +1 -1
- data/rabl-rails.gemspec +3 -0
- data/test/helper.rb +6 -1
- data/test/test_compiler.rb +35 -23
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfd78996e96f1bf4dc99f2ffe80c69b57e1d7c72
|
4
|
+
data.tar.gz: e7c0c4bcf0d10beba1a814962ac15fd5c55434e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b75c2a1b05cd16037797aa5a2eedb63041be6e0670cef0e0658cadd709e514e96d718d52f6d4e7b616873e91e280439eb08f7a09c4409eebc65ebe5c95f8a704
|
7
|
+
data.tar.gz: 87a2345a2b7b02dda10ceadfedbe6e231f3af9fd365fd4ab4d35019184ce7318420d5c92cb02b0013b2a591d0f6765c24cc75b50ea5cf4258d161665fd28bd76
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
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
data/README.md
CHANGED
data/lib/rabl-rails/library.rb
CHANGED
@@ -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)
|
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
|
data/lib/rabl-rails/railtie.rb
CHANGED
@@ -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
|
data/lib/rabl-rails/renderer.rb
CHANGED
@@ -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.
|
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
|
data/lib/rabl-rails/responder.rb
CHANGED
@@ -20,13 +20,13 @@ module RablRails
|
|
20
20
|
elsif has_errors?
|
21
21
|
display_errors
|
22
22
|
else
|
23
|
-
api_behavior
|
23
|
+
api_behavior
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
protected
|
28
28
|
|
29
|
-
def api_behavior
|
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
|
44
|
+
super
|
45
45
|
end
|
46
46
|
end
|
47
|
-
end
|
47
|
+
end
|
data/lib/rabl-rails/version.rb
CHANGED
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
|
data/test/test_compiler.rb
CHANGED
@@ -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
|
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
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
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.
|
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-
|
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.
|
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:
|