grape-rabl 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/grape-rabl/formatter.rb +64 -62
- data/lib/grape-rabl/render.rb +8 -6
- data/lib/grape-rabl/version.rb +1 -1
- data/lib/grape/rabl.rb +12 -0
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4a8470660f6399543eefa3e7f27972b76b8f0cc
|
4
|
+
data.tar.gz: 3493ecbd9a3b87e659ae004a312a2d473f5cdd26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c22e0830abc4a6a8793109f432123b1897a35d4c94c0c863446497ef8cc769373f032f2c32272a73b062c6897960f5fc7b28172cbf2b1da62c8893fa7bbedd9
|
7
|
+
data.tar.gz: 9cfd783255db7b1288f30133052c78130d62d8101bff90c15f763ed88d99dd31ee55400551acc141930daa5b53e58fad93b4832a15c019f1a6628eb8af61e711
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
#### v0.4.0
|
2
|
+
|
3
|
+
* Make grape-rabl thread-safe. [#37](https://github.com/LTe/grape-rabl/issues/37) [@kushkella](https://github.com/kushkella)
|
4
|
+
|
1
5
|
#### v0.3.1
|
2
6
|
|
3
7
|
* The `render` method will no longer modify endpoint options at runtime. [#35](https://github.com/LTe/grape-rabl/issues/35) [@yesmeck](https://github.com/yesmeck)
|
data/lib/grape-rabl/formatter.rb
CHANGED
@@ -1,86 +1,88 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
module Grape
|
4
|
-
module
|
5
|
-
|
4
|
+
module Rabl
|
5
|
+
class Formatter
|
6
6
|
class << self
|
7
|
-
|
8
|
-
|
7
|
+
def tilt_cache
|
8
|
+
@tilt_cache ||= ::Tilt::Cache.new
|
9
|
+
end
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
@env = env
|
12
|
-
@endpoint = env['api.endpoint']
|
12
|
+
attr_reader :env, :endpoint, :object
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
def initialize(object, env)
|
15
|
+
@env = env
|
16
|
+
@endpoint = env['api.endpoint']
|
17
|
+
@object = object
|
18
|
+
end
|
19
|
+
|
20
|
+
def render
|
21
|
+
if rablable?
|
22
|
+
rabl do |template|
|
23
|
+
engine = tilt_template(template)
|
24
|
+
output = engine.render endpoint, locals
|
25
|
+
if layout_template
|
26
|
+
layout_template.render(endpoint) { output }
|
27
|
+
else
|
28
|
+
output
|
23
29
|
end
|
24
|
-
else
|
25
|
-
Grape::Formatter::Json.call object, env
|
26
30
|
end
|
31
|
+
else
|
32
|
+
Grape::Formatter::Json.call object, env
|
27
33
|
end
|
34
|
+
end
|
28
35
|
|
29
|
-
|
30
|
-
|
31
|
-
def view_path(template)
|
32
|
-
if template.split('.')[-1] == 'rabl'
|
33
|
-
File.join(env['api.tilt.root'], template)
|
34
|
-
else
|
35
|
-
File.join(env['api.tilt.root'], (template + '.rabl'))
|
36
|
-
end
|
37
|
-
end
|
36
|
+
private
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
def view_path(template)
|
39
|
+
if template.split('.')[-1] == 'rabl'
|
40
|
+
File.join(env['api.tilt.root'], template)
|
41
|
+
else
|
42
|
+
File.join(env['api.tilt.root'], (template + '.rabl'))
|
41
43
|
end
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
yield rabl_template
|
47
|
-
end
|
46
|
+
def rablable?
|
47
|
+
!!rabl_template
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def rabl
|
51
|
+
fail 'missing rabl template' unless rabl_template
|
52
|
+
set_view_root unless env['api.tilt.root']
|
53
|
+
yield rabl_template
|
54
|
+
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
def locals
|
57
|
+
env['api.tilt.rabl_locals'] || endpoint.options[:route_options][:rabl_locals] || {}
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def rabl_template
|
61
|
+
env['api.tilt.rabl'] || endpoint.options[:route_options][:rabl]
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
::Tilt.new(view_path(template), tilt_options)
|
66
|
-
end
|
67
|
-
end
|
64
|
+
def set_view_root
|
65
|
+
fail "Use Rack::Config to set 'api.tilt.root' in config.ru"
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
68
|
+
def tilt_template(template)
|
69
|
+
if Grape::Rabl.configuration.cache_template_loading
|
70
|
+
Grape::Rabl::Formatter.tilt_cache.fetch(template) { ::Tilt.new(view_path(template), tilt_options) }
|
71
|
+
else
|
72
|
+
::Tilt.new(view_path(template), tilt_options)
|
71
73
|
end
|
74
|
+
end
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
def tilt_options
|
77
|
+
{ format: env['api.format'], view_path: env['api.tilt.root'] }
|
78
|
+
end
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
80
|
+
def layout_template
|
81
|
+
layout_path = view_path(env['api.tilt.layout'] || 'layouts/application')
|
82
|
+
if Grape::Rabl.configuration.cache_template_loading
|
83
|
+
Grape::Rabl::Formatter.tilt_cache.fetch(layout_path) { ::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path) }
|
84
|
+
else
|
85
|
+
::Tilt.new(layout_path, tilt_options) if File.exist?(layout_path)
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
data/lib/grape-rabl/render.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module Grape
|
2
|
+
module Rabl
|
3
|
+
module Render
|
4
|
+
def render(options = {})
|
5
|
+
env['api.tilt.rabl'] = options[:rabl]
|
6
|
+
env['api.tilt.rabl_locals'] = options[:locals]
|
7
|
+
end
|
6
8
|
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
|
-
Grape::Endpoint.send(:include,
|
12
|
+
Grape::Endpoint.send(:include, Grape::Rabl::Render)
|
data/lib/grape-rabl/version.rb
CHANGED
data/lib/grape/rabl.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Niełacny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: tilt
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: i18n
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Use rabl in grape
|
@@ -73,11 +73,11 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .coveralls.yml
|
77
|
-
- .gitignore
|
78
|
-
- .rspec
|
79
|
-
- .rubocop.yml
|
80
|
-
- .travis.yml
|
76
|
+
- ".coveralls.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".travis.yml"
|
81
81
|
- CHANGELOG.md
|
82
82
|
- Gemfile
|
83
83
|
- LICENSE
|
@@ -116,17 +116,17 @@ require_paths:
|
|
116
116
|
- lib
|
117
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- -
|
119
|
+
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: 1.9.3
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.2.2
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Use rabl in grape
|