grape-rabl 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,12 +41,12 @@ end
41
41
  To *get post put delete options* add **:rabl** options with template name.
42
42
 
43
43
  ```ruby
44
- get "/path", :rabl => "template_name.rabl" do
44
+ get "/path", :rabl => "template_name" do
45
45
  # stuff
46
46
  @var = "hello"
47
47
  end
48
48
 
49
- post "/path", :rabl => "template_name_diff.rabl" do
49
+ post "/path", :rabl => "template_name_diff" do
50
50
  # stuff
51
51
  @user = User.find_user("email@example.com")
52
52
  end
@@ -54,6 +54,15 @@ end
54
54
 
55
55
  **You can use instance variables in templates!**
56
56
 
57
+ ## Template name
58
+
59
+ You can use "**view.rabl**" or just "**view**"
60
+
61
+ ```ruby
62
+ get "/home", :rabl => "view"
63
+ get "/home", :rabl => "view.rabl"
64
+ ```
65
+
57
66
  ### Example
58
67
 
59
68
  ```ruby
@@ -66,7 +75,7 @@ end
66
75
 
67
76
  class UserAPI < Grape::API
68
77
  # use rabl with 'hello.rabl' template
69
- get '/user', :rabl => 'hello.rabl' do
78
+ get '/user', :rabl => 'hello' do
70
79
  @user = User.first
71
80
  end
72
81
 
@@ -84,6 +93,7 @@ object @user => :user
84
93
  attributes :name
85
94
  ```
86
95
 
96
+
87
97
  Enjoy :)
88
98
 
89
99
  ## Contributing
@@ -11,12 +11,22 @@ module Grape
11
11
  current_endpoint = env['api.endpoint']
12
12
 
13
13
  rabl(current_endpoint) do |template|
14
- engine = ::Tilt.new(File.join(env['api.tilt.root'], template))
14
+ engine = ::Tilt.new(view_path(template))
15
15
  rendered = engine.render(current_endpoint, {})
16
16
  Rack::Response.new(rendered, status, headers).to_a
17
17
  end
18
18
  end
19
19
 
20
+ private
21
+
22
+ def view_path(template)
23
+ if template.split(".")[-1] == "rabl"
24
+ File.join(env['api.tilt.root'], template)
25
+ else
26
+ File.join(env['api.tilt.root'], (template + ".rabl"))
27
+ end
28
+ end
29
+
20
30
  def rabl(endpoint)
21
31
  if template = rablable?(endpoint)
22
32
  yield template
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Rabl
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -26,14 +26,16 @@ describe Grape::Rabl do
26
26
  lambda{ get "/home" }.should_not raise_error("Use Rack::Config to set 'api.tilt.root' in config.ru")
27
27
  end
28
28
 
29
- it "should render rabl template" do
30
- subject.get("/home", :rabl => "user.rabl") do
31
- @user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
32
- @project = OpenStruct.new(:name => "First")
33
- end
29
+ ["user", "user.rabl"].each do |rabl_option|
30
+ it "should render rabl template (#{rabl_option})" do
31
+ subject.get("/home", :rabl => rabl_option) do
32
+ @user = OpenStruct.new(:name => "LTe", :email => "email@example.com")
33
+ @project = OpenStruct.new(:name => "First")
34
+ end
34
35
 
35
- get "/home"
36
- last_response.body.should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
36
+ get "/home"
37
+ last_response.body.should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
38
+ end
37
39
  end
38
40
  end
39
41
  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.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-10 00:00:00.000000000 Z
12
+ date: 2012-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rabl
16
- requirement: &15019600 !ruby/object:Gem::Requirement
16
+ requirement: &4299880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15019600
24
+ version_requirements: *4299880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tilt
27
- requirement: &15016400 !ruby/object:Gem::Requirement
27
+ requirement: &4298300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15016400
35
+ version_requirements: *4298300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &15027960 !ruby/object:Gem::Requirement
38
+ requirement: &4294300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *15027960
46
+ version_requirements: *4294300
47
47
  description: Use rabl in grape
48
48
  email:
49
49
  - piotr.nielacny@gmail.com