grape-rabl 0.1.0 → 0.2.0

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.
data/grape-rabl.gemspec CHANGED
@@ -1,22 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/grape-rabl/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Piotr Niełacny"]
6
- gem.email = ["piotr.nielacny@gmail.com"]
7
- gem.description = %q{Use rabl in grape}
8
- gem.summary = %q{Use rabl in grape}
9
- gem.homepage = "https://github.com/LTe/grape-rabl"
10
-
11
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- gem.files = `git ls-files`.split("\n")
13
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
- gem.name = "grape-rabl"
15
- gem.require_paths = ["lib"]
16
- gem.version = Grape::Rabl::VERSION
17
-
18
- gem.add_dependency "grape", "~> 0.2.3"
19
- gem.add_dependency "rabl"
20
- gem.add_dependency "tilt"
21
- gem.add_dependency "i18n"
22
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/grape-rabl/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Piotr Niełacny"]
6
+ gem.email = ["piotr.nielacny@gmail.com"]
7
+ gem.description = %q{Use rabl in grape}
8
+ gem.summary = %q{Use rabl in grape}
9
+ gem.homepage = "https://github.com/LTe/grape-rabl"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "grape-rabl"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Grape::Rabl::VERSION
17
+
18
+ gem.add_dependency "grape", "~> 0.3"
19
+ gem.add_dependency "rabl"
20
+ gem.add_dependency "tilt"
21
+ gem.add_dependency "i18n"
22
+ end
@@ -13,7 +13,7 @@ module Grape
13
13
 
14
14
  if rablable?
15
15
  rabl do |template|
16
- engine = ::Tilt.new(view_path(template))
16
+ engine = ::Tilt.new(view_path(template), {format: env['api.format'], view_path: env['api.tilt.root']})
17
17
  engine.render endpoint, {}
18
18
  end
19
19
  else
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Rabl
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Grape::Rabl partials" do
4
+ subject do
5
+ Class.new(Grape::API)
6
+ end
7
+
8
+ before do
9
+ subject.format :json
10
+ subject.formatter :json, Grape::Formatter::Rabl
11
+ subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
12
+ end
13
+
14
+ def app
15
+ subject
16
+ end
17
+
18
+ it "proper render partials" do
19
+ subject.get("/home", :rabl => "project") do
20
+ @author = OpenStruct.new(:author => "LTe")
21
+ @type = OpenStruct.new(:type => "paper")
22
+ @project = OpenStruct.new(:name => "First", :type => @type, :author => @author)
23
+ end
24
+
25
+ get("/home")
26
+ last_response.body.should ==
27
+ "{\"project\":{\"name\":\"First\",\"info\":{\"type\":\"paper\"},\"author\":{\"author\":\"LTe\"}}}"
28
+ end
29
+ end
@@ -1,57 +1,61 @@
1
- require 'spec_helper'
2
-
3
- describe Grape::Rabl do
4
- subject do
5
- Class.new(Grape::API)
6
- end
7
-
8
- before do
9
- subject.format :json
10
- subject.formatter :json, Grape::Formatter::Rabl
11
- end
12
-
13
- def app
14
- subject
15
- end
16
-
17
- it 'should work without rabl template' do
18
- subject.get("/home") {"Hello World"}
19
- get "/home"
20
- last_response.body.should == "Hello World"
21
- end
22
-
23
- it "should raise error about root directory" do
24
- subject.get("/home", :rabl => true){}
25
- lambda{ get "/home" }.should raise_error("Use Rack::Config to set 'api.tilt.root' in config.ru")
26
- end
27
-
28
-
29
- context "titl root is setup" do
30
- before do
31
- subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
32
- end
33
-
34
- it "should respond with proper content-type" do
35
- subject.get("/home", :rabl => "user"){}
36
- get("/home")
37
- last_response.headers["Content-Type"].should == "application/json"
38
- end
39
-
40
- it "should not raise error about root directory" do
41
- subject.get("/home", :rabl => true){}
42
- lambda{ get "/home" }.should_not raise_error("Use Rack::Config to set 'api.tilt.root' in config.ru")
43
- end
44
-
45
- ["user", "user.rabl"].each do |rabl_option|
46
- it "should render rabl template (#{rabl_option})" do
47
- subject.get("/home", :rabl => rabl_option) do
48
- @user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
49
- @project = OpenStruct.new(:name => "First")
50
- end
51
-
52
- get "/home"
53
- last_response.body.should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
54
- end
55
- end
56
- end
57
- end
1
+ require 'spec_helper'
2
+
3
+ describe Grape::Rabl do
4
+ subject do
5
+ Class.new(Grape::API)
6
+ end
7
+
8
+ before do
9
+ subject.format :json
10
+ subject.formatter :json, Grape::Formatter::Rabl
11
+ end
12
+
13
+ def app
14
+ subject
15
+ end
16
+
17
+ it 'should work without rabl template' do
18
+ subject.get("/home") {"Hello World"}
19
+ get "/home"
20
+ last_response.body.should == "Hello World"
21
+ end
22
+
23
+ it "should raise error about root directory" do
24
+ subject.get("/home", :rabl => true){}
25
+ get "/home"
26
+ last_response.status.should == 500
27
+ last_response.body.should include "Use Rack::Config to set 'api.tilt.root' in config.ru"
28
+ end
29
+
30
+
31
+ context "titl root is setup" do
32
+ before do
33
+ subject.before { env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views" }
34
+ end
35
+
36
+ it "should respond with proper content-type" do
37
+ subject.get("/home", :rabl => "user"){}
38
+ get("/home")
39
+ last_response.headers["Content-Type"].should == "application/json"
40
+ end
41
+
42
+ it "should not raise error about root directory" do
43
+ subject.get("/home", :rabl => true){}
44
+ get "/home"
45
+ last_response.status.should == 500
46
+ last_response.body.should_not include "Use Rack::Config to set 'api.tilt.root' in config.ru"
47
+ end
48
+
49
+ ["user", "user.rabl"].each do |rabl_option|
50
+ it "should render rabl template (#{rabl_option})" do
51
+ subject.get("/home", :rabl => rabl_option) do
52
+ @user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
53
+ @project = OpenStruct.new(:name => "First")
54
+ end
55
+
56
+ get "/home"
57
+ last_response.body.should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Grape::Rabl do
4
+ subject do
5
+ Class.new(Grape::API)
6
+ end
7
+
8
+ before do
9
+ subject.format :xml
10
+ subject.formatter :xml, Grape::Formatter::Rabl
11
+ end
12
+
13
+ def app
14
+ subject
15
+ end
16
+
17
+ context "with xml format" do
18
+ before do
19
+ subject.before {
20
+ env["api.tilt.root"] = "#{File.dirname(__FILE__)}/views"
21
+ env["api.format"] = :xml
22
+ }
23
+ end
24
+
25
+ it "should respond with proper content-type" do
26
+ subject.get("/home", :rabl => "user"){}
27
+ get("/home")
28
+ last_response.headers["Content-Type"].should == "application/xml"
29
+ end
30
+
31
+ ["user", "user.rabl"].each do |rabl_option|
32
+ it "should render rabl template (#{rabl_option})" do
33
+ subject.get("/home", :rabl => rabl_option) do
34
+ @user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
35
+ @project = OpenStruct.new(:name => "First")
36
+ end
37
+
38
+ get "/home"
39
+
40
+ last_response.body.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<user>\n <name>LTe</name>\n <email>email@example.com</email>\n <project>\n <name>First</name>\n </project>\n</user>\n}
41
+ end
42
+ end
43
+ end
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,18 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- require 'bundler'
5
- Bundler.setup :default, :test
6
-
7
- require 'grape/rabl'
8
- require 'rspec'
9
- require 'rack/test'
10
- require 'ostruct'
11
-
12
- RSpec.configure do |config|
13
- config.include Rack::Test::Methods
14
- end
15
-
16
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
-
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'bundler'
5
+ Bundler.setup :default, :test
6
+
7
+ require 'active_support/core_ext/hash/conversions'
8
+ require 'grape/rabl'
9
+ require 'rspec'
10
+ require 'rack/test'
11
+ require 'ostruct'
12
+
13
+ RSpec.configure do |config|
14
+ config.include Rack::Test::Methods
15
+ end
16
+
17
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
18
+
@@ -0,0 +1 @@
1
+ attributes :type
@@ -0,0 +1 @@
1
+ attributes :author
@@ -0,0 +1,10 @@
1
+ object @project => :project
2
+ attributes :name
3
+
4
+ node :info do
5
+ partial "partial", object: @project.type
6
+ end
7
+
8
+ child @author => :author do
9
+ extends "info"
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.2.3
21
+ version: '0.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.2.3
29
+ version: '0.3'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rabl
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -95,8 +95,13 @@ files:
95
95
  - lib/grape-rabl/tilt.rb
96
96
  - lib/grape-rabl/version.rb
97
97
  - lib/grape/rabl.rb
98
+ - spec/grape_rabl_partials_spec.rb
98
99
  - spec/grape_rabl_spec.rb
100
+ - spec/grape_rabl_xml_spec.rb
99
101
  - spec/spec_helper.rb
102
+ - spec/views/_partial.rabl
103
+ - spec/views/info.rabl
104
+ - spec/views/project.rabl
100
105
  - spec/views/user.rabl
101
106
  homepage: https://github.com/LTe/grape-rabl
102
107
  licenses: []
@@ -123,4 +128,3 @@ signing_key:
123
128
  specification_version: 3
124
129
  summary: Use rabl in grape
125
130
  test_files: []
126
- has_rdoc: