sinatra-mustache 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,21 +9,31 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
+ diff-lcs (1.1.2)
12
13
  mustache (0.11.2)
13
14
  rack (1.2.1)
15
+ rack-test (0.5.6)
16
+ rack (>= 1.0)
17
+ rspec (2.2.0)
18
+ rspec-core (~> 2.2)
19
+ rspec-expectations (~> 2.2)
20
+ rspec-mocks (~> 2.2)
21
+ rspec-core (2.2.1)
22
+ rspec-expectations (2.2.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.2.0)
14
25
  sinatra (1.1.0)
15
26
  rack (~> 1.1)
16
27
  tilt (~> 1.1)
17
28
  tilt (1.1)
18
- unicorn (1.0.0)
19
- rack
20
29
 
21
30
  PLATFORMS
22
31
  ruby
23
32
 
24
33
  DEPENDENCIES
25
34
  mustache (~> 0.11.2)
35
+ rack-test (~> 0.5.6)
36
+ rspec (~> 2.2.0)
26
37
  sinatra (~> 1.1.0)
27
38
  sinatra-mustache!
28
39
  tilt (= 1.1)
29
- unicorn
data/TODO.md CHANGED
@@ -1,3 +1 @@
1
1
  Soon:
2
-
3
- * Tests
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Mustache
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ module Tilt
10
10
  end
11
11
 
12
12
  def prepare
13
- ::Mustache.template_path = file.gsub(File.basename(file), '')
13
+ ::Mustache.template_path = file.gsub(File.basename(file), '') if file
14
14
  @engine = ::Mustache.new
15
15
  @output = nil
16
16
  end
@@ -30,7 +30,11 @@ module Tilt
30
30
  end
31
31
 
32
32
  scope.instance_variables.each do |instance_variable|
33
- locals[instance_variable.to_s.gsub('@','').to_sym] = scope.instance_variable_get(instance_variable)
33
+ symbol = instance_variable.to_s.gsub('@','').to_sym
34
+
35
+ if ! locals[symbol]
36
+ locals[symbol] = scope.instance_variable_get(instance_variable)
37
+ end
34
38
  end
35
39
 
36
40
  locals[:yield] = block.nil? ? '' : yield
@@ -22,4 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'sinatra', '~> 1.1.0'
23
23
  s.add_dependency 'mustache', '~> 0.11.2'
24
24
  s.add_dependency 'tilt', '1.1'
25
+
26
+ s.add_development_dependency 'rspec', '~> 2.2.0'
27
+ s.add_development_dependency 'rack-test', '~> 0.5.6'
25
28
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'sinatra-mustache', :type => :request do
4
+ subject { response }
5
+
6
+ context 'inline mustache strings' do
7
+ context 'without the :locals option' do
8
+ before(:each) { mustache_app { mustache('Hello') } }
9
+
10
+ it { should be_ok }
11
+ its(:body) { should == 'Hello' }
12
+ end
13
+
14
+ context 'with :locals option' do
15
+ before(:each) do
16
+ locals = { :subject => 'World' }
17
+ mustache_app { mustache('Hello {{ subject }}!', :locals => locals) }
18
+ end
19
+
20
+ it { should be_ok }
21
+ its(:body) { should == 'Hello World!' }
22
+ end
23
+
24
+ context 'with an inline layout' do
25
+ before(:each) do
26
+ mock_app {
27
+ layout { 'This is a {{ yield }}!' }
28
+ get('/') { mustache 'layout' }
29
+ }
30
+
31
+ get '/'
32
+ end
33
+
34
+ it { should be_ok }
35
+ its(:body) { should == 'This is a layout!' }
36
+ end
37
+
38
+ context 'with a file layout' do
39
+ before(:each) do
40
+ mustache_app { mustache('Hello World!', :layout => :layout_too) }
41
+ end
42
+
43
+ it { should be_ok }
44
+ its(:body) { should == "From a layout!\nHello World!\n" }
45
+ end
46
+ end
47
+
48
+ context 'rendering .mustache files in the views path' do
49
+ context 'without a layout' do
50
+ before(:each) { mustache_app { mustache :hello } }
51
+
52
+ it { should be_ok }
53
+ its(:body) { should == "Hello \n" }
54
+ end
55
+
56
+ context 'that calls a partial' do
57
+ before(:each) { mustache_app { mustache :needs_partial } }
58
+
59
+ it { should be_ok }
60
+ its(:body) { should == "Hello\nfrom a partial\n" }
61
+ end
62
+
63
+ context 'that has yaml front matter' do
64
+ before(:each) { mustache_app { mustache :yaml } }
65
+
66
+ it { should be_ok }
67
+ its(:body) { should == "Hello\nfrom yaml\n" }
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tilt::MustacheTemplate do
4
+ describe 'registered for mustache files' do
5
+ subject { Tilt::MustacheTemplate }
6
+
7
+ it { should == Tilt['test.mustache'] }
8
+ it { should == Tilt['test.html.mustache'] }
9
+ end
10
+
11
+ describe '#render' do
12
+ let(:template) { Tilt::MustacheTemplate.new { |t| 'Hello {{ name }}!'} }
13
+
14
+ context 'without locals or a scope' do
15
+ subject { template.render }
16
+
17
+ it { should == 'Hello !' }
18
+ end
19
+
20
+ context 'with locals' do
21
+ subject { template.render(Object.new, :name => 'World') }
22
+
23
+ it { should == 'Hello World!' }
24
+ end
25
+
26
+ context 'with an objects scope' do
27
+ let(:scope) do
28
+ scope = Object.new
29
+ scope.instance_variable_set(:@name, 'World')
30
+ scope
31
+ end
32
+
33
+ subject { template.render(scope) }
34
+
35
+ it { should == 'Hello World!' }
36
+ end
37
+
38
+ context 'with both an object and locals' do
39
+ let(:template) do
40
+ Tilt::MustacheTemplate.new {
41
+ 'Beer is {{ beer }} but Whisky is {{ whisky }}.'
42
+ }
43
+ end
44
+
45
+ let(:scope) do
46
+ scope = Object.new
47
+ scope.instance_variable_set(:@beer, 'wet')
48
+ scope.instance_variable_set(:@whisky, 'wetter')
49
+ scope
50
+ end
51
+
52
+ let(:locals) { { :beer => 'great', :whisky => 'greater' } }
53
+
54
+ subject { template.render(scope, locals) }
55
+
56
+ it 'locals should have precedence' do
57
+ subject.should == 'Beer is great but Whisky is greater.'
58
+ end
59
+ end
60
+
61
+ context 'passing a block' do
62
+ let(:template) { Tilt::MustacheTemplate.new { |t| 'Hello {{ yield }}!'} }
63
+ subject { template.render { 'World' } }
64
+
65
+ it { should == 'Hello World!' }
66
+ end
67
+
68
+ context 'with a template that has yaml front matter' do
69
+ let(:template) do
70
+ Tilt::MustacheTemplate.new do
71
+ File.read(File.dirname(__FILE__) + '/views/yaml.mustache')
72
+ end
73
+ end
74
+
75
+ subject { template.render }
76
+
77
+ it { should == "Hello\nfrom yaml\n" }
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module RequestHelper
2
+ include Rack::Test::Methods
3
+
4
+ def mock_app(base=Sinatra::Base, &block)
5
+ @app = Sinatra.new(base, &block)
6
+ end
7
+
8
+ def app
9
+ Rack::Lint.new(@app)
10
+ end
11
+
12
+ def mustache_app(&block)
13
+ mock_app {
14
+ set :environment, :test
15
+ set :views, File.dirname(__FILE__) + '/views'
16
+ get '/', &block
17
+ }
18
+
19
+ get '/'
20
+ end
21
+
22
+ alias_method :response, :last_response
23
+ end
@@ -0,0 +1,10 @@
1
+ require 'sinatra'
2
+ require 'sinatra/mustache'
3
+ require 'rack'
4
+ require 'rack/test'
5
+
6
+ require 'request_helper'
7
+
8
+ RSpec.configure do |config|
9
+ config.include RequestHelper, :type => :request
10
+ end
@@ -0,0 +1 @@
1
+ from a partial
@@ -0,0 +1 @@
1
+ Hello {{ subject }}
@@ -0,0 +1,2 @@
1
+ From a layout!
2
+ {{ yield }}
@@ -0,0 +1,2 @@
1
+ Hello
2
+ {{> box }}
@@ -0,0 +1,6 @@
1
+ ---
2
+ message: from yaml
3
+ ---
4
+
5
+ Hello
6
+ {{ message }}
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-mustache
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 1
10
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jason Campbell
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-01 00:00:00 -08:00
17
+ date: 2010-12-04 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 19
30
28
  segments:
31
29
  - 1
32
30
  - 1
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 55
46
43
  segments:
47
44
  - 0
48
45
  - 11
@@ -58,13 +55,42 @@ dependencies:
58
55
  requirements:
59
56
  - - "="
60
57
  - !ruby/object:Gem::Version
61
- hash: 13
62
58
  segments:
63
59
  - 1
64
60
  - 1
65
61
  version: "1.1"
66
62
  type: :runtime
67
63
  version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: rspec
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 2
74
+ - 2
75
+ - 0
76
+ version: 2.2.0
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rack-test
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ - 5
90
+ - 6
91
+ version: 0.5.6
92
+ type: :development
93
+ version_requirements: *id005
68
94
  description: Use Mustache in your Sinatra app without the extra view classes
69
95
  email:
70
96
  - jason@greatergood.cc
@@ -86,6 +112,15 @@ files:
86
112
  - lib/sinatra/mustache.rb
87
113
  - lib/tilt/mustache_template.rb
88
114
  - sinatra-mustache.gemspec
115
+ - spec/mustache_spec.rb
116
+ - spec/mustache_template_spec.rb
117
+ - spec/request_helper.rb
118
+ - spec/spec_helper.rb
119
+ - spec/views/box.mustache
120
+ - spec/views/hello.mustache
121
+ - spec/views/layout_too.mustache
122
+ - spec/views/needs_partial.mustache
123
+ - spec/views/yaml.mustache
89
124
  has_rdoc: true
90
125
  homepage: http://github.com/jxson/sinatra-mustache
91
126
  licenses: []
@@ -100,7 +135,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
135
  requirements:
101
136
  - - ">="
102
137
  - !ruby/object:Gem::Version
103
- hash: 3
104
138
  segments:
105
139
  - 0
106
140
  version: "0"
@@ -109,7 +143,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
143
  requirements:
110
144
  - - ">="
111
145
  - !ruby/object:Gem::Version
112
- hash: 3
113
146
  segments:
114
147
  - 0
115
148
  version: "0"
@@ -120,5 +153,13 @@ rubygems_version: 1.3.7
120
153
  signing_key:
121
154
  specification_version: 3
122
155
  summary: Use Mustache in your Sinatra app without the extra view classes
123
- test_files: []
124
-
156
+ test_files:
157
+ - spec/mustache_spec.rb
158
+ - spec/mustache_template_spec.rb
159
+ - spec/request_helper.rb
160
+ - spec/spec_helper.rb
161
+ - spec/views/box.mustache
162
+ - spec/views/hello.mustache
163
+ - spec/views/layout_too.mustache
164
+ - spec/views/needs_partial.mustache
165
+ - spec/views/yaml.mustache