rabl-rails 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +24 -3
- data/README.md +2 -1
- data/lib/rabl-rails.rb +6 -0
- data/lib/rabl-rails/renderer.rb +3 -3
- data/lib/rabl-rails/renderers/xml.rb +1 -3
- data/lib/rabl-rails/version.rb +1 -1
- data/rabl-rails.gemspec +3 -3
- data/test/base_renderer_test.rb +1 -1
- data/test/compiler_test.rb +1 -1
- data/test/deep_nesting_test.rb +1 -1
- data/test/render_test.rb +16 -0
- data/test/renderers/json_renderer_test.rb +2 -2
- data/test/renderers/plist_renderer_test.rb +1 -1
- data/test/renderers/xml_renderer_test.rb +6 -0
- metadata +82 -80
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 0.3.4
|
4
|
+
* Add `xml_options` option to root_level (brettallred)
|
5
|
+
|
6
|
+
* Format can be omitted in template filename
|
7
|
+
|
8
|
+
RablRails.allow_empty_format_in_template = true
|
9
|
+
RablRails.render(user, 'show') # => app/view/user.rabl
|
10
|
+
|
11
|
+
* Rails 4 support
|
12
|
+
* Update travis configuration and remove warning in tests (petergoldstein)
|
13
|
+
|
3
14
|
## 0.3.3
|
4
15
|
* Add response caching
|
5
16
|
|
data/Gemfile
CHANGED
@@ -1,7 +1,25 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
rails_version = ENV['RAILS_VERSION'] || 'default'
|
6
|
+
|
7
|
+
rails = case rails_version
|
8
|
+
when 'master'
|
9
|
+
{github: 'rails/rails'}
|
10
|
+
when "default"
|
11
|
+
'~> 3.2.0'
|
12
|
+
else
|
13
|
+
"~> #{rails_version}"
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'activesupport', rails
|
17
|
+
gem 'railties', rails
|
18
|
+
|
19
|
+
group :development, :test do
|
20
|
+
gem 'actionpack', rails
|
21
|
+
end
|
22
|
+
|
5
23
|
gem 'plist'
|
6
24
|
|
7
25
|
platforms :ruby do
|
@@ -16,6 +34,9 @@ platforms :jruby do
|
|
16
34
|
gem 'nokogiri'
|
17
35
|
end
|
18
36
|
|
19
|
-
|
20
|
-
gem '
|
37
|
+
platforms :rbx do
|
38
|
+
gem 'rubysl', '~> 2.0'
|
39
|
+
gem 'minitest'
|
40
|
+
gem 'rubysl-test-unit'
|
21
41
|
end
|
42
|
+
|
data/README.md
CHANGED
@@ -93,6 +93,7 @@ RablRails.configure do |config|
|
|
93
93
|
# config.include_json_root = true
|
94
94
|
# config.json_engine = :oj
|
95
95
|
# config.xml_engine = 'LibXML'
|
96
|
+
# config.xml_options = { :dasherize => true, :skip_types => false }
|
96
97
|
# config.use_custom_responder = false
|
97
98
|
# config.default_responder_template = 'show'
|
98
99
|
# config.enable_jsonp_callbacks = false
|
@@ -278,7 +279,7 @@ end
|
|
278
279
|
There are cases when you want to render object outside Rails view context. For instance to render objects in the console or to create message queue payloads. For these situations, you can use `RablRails.render` as show below:
|
279
280
|
|
280
281
|
```ruby
|
281
|
-
|
282
|
+
RablRails.render(object, template, :view_path => 'app/views', :format => :json) #=> "{...}"
|
282
283
|
```
|
283
284
|
|
284
285
|
You can find more informations about how to use this method in the [wiki](http://github.com/ccocchi/rabl-rails/wiki/Render-object-directly)
|
data/lib/rabl-rails.rb
CHANGED
@@ -42,6 +42,12 @@ module RablRails
|
|
42
42
|
mattr_accessor :enable_jsonp_callbacks
|
43
43
|
@@enable_jsonp_callbacks = false
|
44
44
|
|
45
|
+
mattr_accessor :allow_empty_format_in_template
|
46
|
+
@@allow_empty_format_in_template = false
|
47
|
+
|
48
|
+
mattr_accessor :xml_options
|
49
|
+
@@xml_options = { dasherize: true, skip_types: false }
|
50
|
+
|
45
51
|
def self.configure
|
46
52
|
yield self
|
47
53
|
|
data/lib/rabl-rails/renderer.rb
CHANGED
@@ -15,7 +15,7 @@ module RablRails
|
|
15
15
|
|
16
16
|
def initialize(view_path, format)
|
17
17
|
@view_path = view_path || RablRails::Renderer.view_path
|
18
|
-
@
|
18
|
+
@extension = format ? ".#{format.to_s.downcase}.rabl" : ".rabl"
|
19
19
|
end
|
20
20
|
|
21
21
|
#
|
@@ -24,7 +24,7 @@ module RablRails
|
|
24
24
|
# path is used
|
25
25
|
#
|
26
26
|
def find_template(name, opt, partial = false)
|
27
|
-
path = File.join(@view_path, "#{name}
|
27
|
+
path = File.join(@view_path, "#{name}#{@extension}")
|
28
28
|
File.exists?(path) ? T.new(File.read(path)) : nil
|
29
29
|
end
|
30
30
|
end
|
@@ -38,7 +38,7 @@ module RablRails
|
|
38
38
|
|
39
39
|
def initialize(path, options)
|
40
40
|
@virtual_path = path
|
41
|
-
@format = options.delete(:format) || 'json'
|
41
|
+
@format = options.delete(:format) || (RablRails.allow_empty_format_in_template ? nil : 'json')
|
42
42
|
@_assigns = {}
|
43
43
|
@options = options
|
44
44
|
|
@@ -3,10 +3,8 @@ require 'active_support/core_ext/hash/conversions'
|
|
3
3
|
module RablRails
|
4
4
|
module Renderers
|
5
5
|
class XML < Base
|
6
|
-
DEFAULT_OPTIONS = { dasherize: true, skip_types: false }
|
7
|
-
|
8
6
|
def format_output(hash)
|
9
|
-
xml_options = { root: _options[:root_name] }.merge!(
|
7
|
+
xml_options = { root: _options[:root_name] }.merge!(RablRails.xml_options)
|
10
8
|
hash.to_xml(xml_options)
|
11
9
|
end
|
12
10
|
|
data/lib/rabl-rails/version.rb
CHANGED
data/rabl-rails.gemspec
CHANGED
@@ -15,9 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
-
s.add_dependency "activesupport", "
|
19
|
-
s.add_dependency "railties", "
|
18
|
+
s.add_dependency "activesupport", ">= 3.1"
|
19
|
+
s.add_dependency "railties", ">= 3.1"
|
20
20
|
|
21
|
-
s.add_development_dependency "actionpack", "
|
21
|
+
s.add_development_dependency "actionpack", ">= 3.1"
|
22
22
|
s.add_development_dependency "rspec-mocks"
|
23
23
|
end
|
data/test/base_renderer_test.rb
CHANGED
data/test/compiler_test.rb
CHANGED
@@ -160,7 +160,7 @@ class CompilerTest < ActiveSupport::TestCase
|
|
160
160
|
end
|
161
161
|
|
162
162
|
test "extends use other template source as itself" do
|
163
|
-
template =
|
163
|
+
template = double('template', :source => { :id => :id })
|
164
164
|
RablRails::Library.reset_instance
|
165
165
|
RablRails::Library.instance.stub(:compile_template_from_path).with('users/base').and_return(template)
|
166
166
|
t = @compiler.compile_source(%{ extends 'users/base' })
|
data/test/deep_nesting_test.rb
CHANGED
@@ -23,7 +23,7 @@ class DeepNestingTest < ActiveSupport::TestCase
|
|
23
23
|
@context = Context.new
|
24
24
|
@context.assigns['user'] = @user
|
25
25
|
@context.virtual_path = 'users/show'
|
26
|
-
@context.stub(:lookup_context).and_return(
|
26
|
+
@context.stub(:lookup_context).and_return(double(:find_template => double(:source => %{ object :@comment\n attribute :content })))
|
27
27
|
end
|
28
28
|
|
29
29
|
test "compile and render deep nesting template" do
|
data/test/render_test.rb
CHANGED
@@ -73,4 +73,20 @@ class RenderTest < ActiveSupport::TestCase
|
|
73
73
|
assert_equal %q({"user":{"id":1,"name":"Marty"}}), RablRails.render(@user, 'show', view_path: @tmp_path, format: 'JSON')
|
74
74
|
end
|
75
75
|
|
76
|
+
test "format can be omitted if option is set" do
|
77
|
+
begin
|
78
|
+
RablRails.allow_empty_format_in_template = true
|
79
|
+
File.open(@tmp_path + "show.rabl", "w") do |f|
|
80
|
+
f.puts %q{
|
81
|
+
object :@user
|
82
|
+
attributes :id, :name
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal %q({"user":{"id":1,"name":"Marty"}}), RablRails.render(@user, 'show', view_path: @tmp_path)
|
87
|
+
ensure
|
88
|
+
RablRails.allow_empty_format_in_template = false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
76
92
|
end
|
@@ -40,7 +40,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
test "render child with object association" do
|
43
|
-
@data.stub(:address).and_return(
|
43
|
+
@data.stub(:address).and_return(double(:city => 'Paris'))
|
44
44
|
@template.source = { :address => { :_data => :address, :city => :city } }
|
45
45
|
assert_equal %q({"address":{"city":"Paris"}}), render_json_output
|
46
46
|
end
|
@@ -180,7 +180,7 @@ class TestJsonRenderer < ActiveSupport::TestCase
|
|
180
180
|
@data.stub(:cache_key).and_return('data_cache_key')
|
181
181
|
@template.cache_key = nil
|
182
182
|
|
183
|
-
@cache =
|
183
|
+
@cache = double
|
184
184
|
@cache.should_receive(:fetch).with('data_cache_key.json').and_return(%("some":"json"))
|
185
185
|
Rails.stub(:cache).and_return(@cache)
|
186
186
|
|
@@ -48,7 +48,7 @@ class TestPlistRenderer < ActiveSupport::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
test "render child with object association" do
|
51
|
-
@data.stub(:address).and_return(
|
51
|
+
@data.stub(:address).and_return(double(:city => 'Paris'))
|
52
52
|
@template.source = { :address => { :_data => :address, :city => :city } }
|
53
53
|
assert_equal %q(<key>address</key><dict><key>city</key><string>Paris</string></dict>), render_plist_output
|
54
54
|
end
|
@@ -128,4 +128,10 @@ class TestXmlRenderer < ActiveSupport::TestCase
|
|
128
128
|
|
129
129
|
assert_equal %q(<list><users type="array"/></list>), render_xml_output
|
130
130
|
end
|
131
|
+
|
132
|
+
test "render underscorized xml" do
|
133
|
+
RablRails.xml_options = { :dasherize => false, :skip_types => false }
|
134
|
+
@template.source = { :first_name => :name }
|
135
|
+
assert_equal %q(<user><first_name>foobar</first_name></user>), render_xml_output
|
136
|
+
end
|
131
137
|
end
|
metadata
CHANGED
@@ -1,87 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 4
|
9
|
+
version: 0.3.4
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Christopher Cocchi-Perrier
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2014-04-02 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: activesupport
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.0'
|
22
|
-
type: :runtime
|
23
22
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '3.0'
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 1
|
30
|
+
version: "3.1"
|
38
31
|
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: railties
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
-
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 3
|
42
|
+
- 1
|
43
|
+
version: "3.1"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
47
|
name: actionpack
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.0'
|
54
|
-
type: :development
|
55
48
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
-
|
63
|
-
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 3
|
55
|
+
- 1
|
56
|
+
version: "3.1"
|
70
57
|
type: :development
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec-mocks
|
71
61
|
prerelease: false
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id004
|
78
71
|
description: Fast Rails 3+ templating system with JSON, XML and PList support
|
79
|
-
email:
|
72
|
+
email:
|
80
73
|
- cocchi.c@gmail.com
|
81
74
|
executables: []
|
75
|
+
|
82
76
|
extensions: []
|
77
|
+
|
83
78
|
extra_rdoc_files: []
|
84
|
-
|
79
|
+
|
80
|
+
files:
|
85
81
|
- .gitignore
|
86
82
|
- .travis.yml
|
87
83
|
- CHANGELOG.md
|
@@ -116,31 +112,37 @@ files:
|
|
116
112
|
- test/renderers/plist_renderer_test.rb
|
117
113
|
- test/renderers/xml_renderer_test.rb
|
118
114
|
- test/test_helper.rb
|
115
|
+
has_rdoc: true
|
119
116
|
homepage: https://github.com/ccocchi/rabl-rails
|
120
117
|
licenses: []
|
118
|
+
|
121
119
|
post_install_message:
|
122
120
|
rdoc_options: []
|
123
|
-
|
121
|
+
|
122
|
+
require_paths:
|
124
123
|
- lib
|
125
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
requirements:
|
134
|
-
- -
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
137
138
|
requirements: []
|
139
|
+
|
138
140
|
rubyforge_project:
|
139
|
-
rubygems_version: 1.
|
141
|
+
rubygems_version: 1.3.6
|
140
142
|
signing_key:
|
141
143
|
specification_version: 3
|
142
144
|
summary: Fast Rails 3+ templating system with JSON, XML and PList support
|
143
|
-
test_files:
|
145
|
+
test_files:
|
144
146
|
- test/base_renderer_test.rb
|
145
147
|
- test/cache_templates_test.rb
|
146
148
|
- test/compiler_test.rb
|