sanford-rabl 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gemspec
4
4
 
5
5
  gem 'rake'
6
6
  gem 'pry'
7
+ gem 'bson_ext'
7
8
 
8
9
  platform :rbx do
9
10
  gem 'rubysl'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SanfordRabl
1
+ # Sanford::Rabl
2
2
 
3
3
  Sanford [template engine](https://github.com/redding/sanford) for rendering Rabl templates
4
4
 
@@ -13,7 +13,7 @@ require 'sanford-rabl'
13
13
 
14
14
  Sanford.configure do |c|
15
15
 
16
- c.template_source "/path/to/templates") do |s|
16
+ c.template_source "/path/to/templates" do |s|
17
17
  s.engine 'rabl', Sanford::Rabl::TemplateEngine
18
18
  end
19
19
 
@@ -22,6 +22,10 @@ end
22
22
 
23
23
  Add `.rabl` to any template files in your template source path. Sanford will render their content using Rabl when they are rendered.
24
24
 
25
+ ### Notes
26
+
27
+ Rabl allows you to specify the template scope. Templates will be rendered in the scope of the service handler. Therefore, you can access any service handler attributes directly in the template file.
28
+
25
29
  ## Installation
26
30
 
27
31
  Add this line to your application's Gemfile:
@@ -1,4 +1,19 @@
1
- require "sanford-rabl/version"
1
+ require 'rabl'
2
+ require 'sanford/template_engine'
3
+ require 'sanford-rabl/version'
2
4
 
3
5
  module Sanford::Rabl
6
+
7
+ class TemplateEngine < Sanford::TemplateEngine
8
+
9
+ def render(path, service_handler, locals)
10
+ Rabl::Renderer.new(path, nil, {
11
+ :view_path => self.source_path,
12
+ :format => 'hash',
13
+ :locals => locals
14
+ }).render(service_handler)
15
+ end
16
+
17
+ end
18
+
4
19
  end
@@ -1,4 +1,4 @@
1
1
  module Sanford; end
2
2
  module Sanford::Rabl
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0 "
4
4
  end
@@ -20,4 +20,7 @@ Gem::Specification.new do |gem|
20
20
 
21
21
  gem.add_development_dependency("assert", ["~> 2.10"])
22
22
 
23
+ gem.add_dependency("sanford", ["~> 0.10"])
24
+ gem.add_dependency("rabl")
25
+
23
26
  end
@@ -7,4 +7,7 @@ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
7
7
  # require pry for debugging (`binding.pry`)
8
8
  require 'pry'
9
9
 
10
+ require 'pathname'
11
+ TEST_SUPPORT_PATH = Pathname.new(File.expand_path('../support', __FILE__))
12
+
10
13
  require 'test/support/factory'
@@ -3,4 +3,13 @@ require 'assert/factory'
3
3
  module Factory
4
4
  extend Assert::Factory
5
5
 
6
+ def self.template_json_rendered(handler, locals)
7
+ { :thing => {
8
+ :id => handler.identifier,
9
+ :name => handler.name,
10
+ :local1 => locals[:local1]
11
+ }
12
+ }
13
+ end
14
+
6
15
  end
@@ -0,0 +1,5 @@
1
+ child(:thing) {
2
+ node(:id){ identifier }
3
+ node(:name){ name }
4
+ node(:local1){ locals[:local1] }
5
+ }
@@ -0,0 +1,35 @@
1
+ require 'assert'
2
+ require 'sanford-rabl'
3
+
4
+ require 'sanford/template_engine'
5
+
6
+ class Sanford::Rabl::TemplateEngine
7
+
8
+ class UnitTests < Assert::Context
9
+ desc "Sanford::Rabl::TemplateEngine"
10
+ setup do
11
+ @engine = Sanford::Rabl::TemplateEngine.new({
12
+ 'source_path' => TEST_SUPPORT_PATH
13
+ })
14
+ end
15
+ subject{ @engine }
16
+
17
+ should "be a Sanford template engine" do
18
+ assert_kind_of Sanford::TemplateEngine, subject
19
+ assert_respond_to 'render', subject
20
+ end
21
+
22
+ should "render rabl template files as raw data output" do
23
+ service_handler = OpenStruct.new({
24
+ :identifier => Factory.integer,
25
+ :name => Factory.string
26
+ })
27
+ locals = { :local1 => Factory.string }
28
+ exp = Factory.template_json_rendered(service_handler, locals)
29
+
30
+ assert_equal exp, subject.render('template.json', service_handler, locals)
31
+ end
32
+
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanford-rabl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Kelly Redding
@@ -10,17 +16,51 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2014-06-08 00:00:00 Z
19
+ date: 2014-06-11 00:00:00 Z
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
17
24
  requirements:
18
25
  - - ~>
19
26
  - !ruby/object:Gem::Version
27
+ hash: 23
28
+ segments:
29
+ - 2
30
+ - 10
20
31
  version: "2.10"
21
32
  type: :development
22
- version_requirements: *id001
23
33
  name: assert
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 31
43
+ segments:
44
+ - 0
45
+ - 10
46
+ version: "0.10"
47
+ type: :runtime
48
+ name: sanford
49
+ version_requirements: *id002
50
+ prerelease: false
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ name: rabl
63
+ version_requirements: *id003
24
64
  prerelease: false
25
65
  description: Sanford template engine for Rabl templates
26
66
  email:
@@ -44,32 +84,43 @@ files:
44
84
  - sanford-rabl.gemspec
45
85
  - test/helper.rb
46
86
  - test/support/factory.rb
87
+ - test/support/template.json.rabl
88
+ - test/unit/template_engine_tests.rb
47
89
  homepage: http://github.com/redding/sanford-rabl
48
90
  licenses:
49
91
  - MIT
50
- metadata: {}
51
-
52
92
  post_install_message:
53
93
  rdoc_options: []
54
94
 
55
95
  require_paths:
56
96
  - lib
57
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
58
99
  requirements:
59
- - &id002
60
- - ">="
100
+ - - ">="
61
101
  - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
62
105
  version: "0"
63
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
64
108
  requirements:
65
- - *id002
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
66
115
  requirements: []
67
116
 
68
117
  rubyforge_project:
69
- rubygems_version: 2.2.2
118
+ rubygems_version: 1.8.25
70
119
  signing_key:
71
- specification_version: 4
120
+ specification_version: 3
72
121
  summary: Sanford template engine for Rabl templates
73
122
  test_files:
74
123
  - test/helper.rb
75
124
  - test/support/factory.rb
125
+ - test/support/template.json.rabl
126
+ - test/unit/template_engine_tests.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA512:
3
- metadata.gz: 3b22656cc602d020076334abcd06a5ad62218420e288ba53b612c0ecb594b5a920c52d99d1236d65660005ed049489141c2aeee792a4494fd08a7ce71fa9ba36
4
- data.tar.gz: a4fa8f1c450b4bd5083e1be4fb3c17de46987db40cadc5c2ab23815c9d0bdd8ee7ecd793fc604e3465e470a05a5c60c09c8782b40ba01713ab48791800baf8ca
5
- SHA1:
6
- metadata.gz: d86f08b5cf8e4e07277e854fc27e17eff4ddcaf9
7
- data.tar.gz: 133b0d5e68cf261974d218ffc4b0773d97d1e06e