sinatra-mustache 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ree
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - jruby
10
+
11
+ script: bundle exec rspec
12
+
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby
@@ -0,0 +1,5 @@
1
+ 0.0.5
2
+ =====
3
+
4
+ - Fixed rendering output being the same when templates are cached
5
+ - Fixed locals being modified through rendering
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-mustache (0.0.3)
4
+ sinatra-mustache (0.0.5)
5
5
  mustache (~> 0.99)
6
6
  sinatra (~> 1.3, ~> 1.2)
7
7
  tilt (~> 1.3, ~> 1.2)
@@ -12,19 +12,19 @@ GEM
12
12
  diff-lcs (1.1.3)
13
13
  mustache (0.99.4)
14
14
  rack (1.4.1)
15
- rack-protection (1.2.0)
15
+ rack-protection (1.3.2)
16
16
  rack
17
- rack-test (0.6.1)
17
+ rack-test (0.6.2)
18
18
  rack (>= 1.0)
19
- rspec (2.8.0)
20
- rspec-core (~> 2.8.0)
21
- rspec-expectations (~> 2.8.0)
22
- rspec-mocks (~> 2.8.0)
23
- rspec-core (2.8.0)
24
- rspec-expectations (2.8.0)
25
- diff-lcs (~> 1.1.2)
26
- rspec-mocks (2.8.0)
27
- sinatra (1.3.2)
19
+ rspec (2.12.0)
20
+ rspec-core (~> 2.12.0)
21
+ rspec-expectations (~> 2.12.0)
22
+ rspec-mocks (~> 2.12.0)
23
+ rspec-core (2.12.2)
24
+ rspec-expectations (2.12.1)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.12.0)
27
+ sinatra (1.3.3)
28
28
  rack (~> 1.3, >= 1.3.6)
29
29
  rack-protection (~> 1.2)
30
30
  tilt (~> 1.3, >= 1.3.3)
@@ -34,6 +34,6 @@ PLATFORMS
34
34
  ruby
35
35
 
36
36
  DEPENDENCIES
37
- rack-test (~> 0.6)
38
- rspec (~> 2.8)
37
+ rack-test (~> 0)
38
+ rspec (~> 2)
39
39
  sinatra-mustache!
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- sinatra-mustache
1
+ sinatra-mustache [![Build Status](https://travis-ci.org/beatrichartz/sinatra-mustache.png?branch=master)](https://travis-ci.org/beatrichartz/sinatra-mustache)
2
2
  ================
3
3
 
4
4
  To simplify setting up [Sinatra][1] to use [Mustache][2] for it's templates
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module Mustache
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require 'yaml'
4
4
 
5
5
  module Tilt
6
6
  class MustacheTemplate < Template
7
+
7
8
  def initialize_engine
8
9
  return if defined? ::Mustache
9
10
  require_template_library 'mustache'
@@ -16,14 +17,16 @@ module Tilt
16
17
  end
17
18
 
18
19
  def evaluate(scope, locals, &block)
20
+ mustache_locals = locals.dup
21
+
19
22
  if data =~ /^(\s*---(.+)---\s*)/m
20
23
  yaml = $2.strip
21
24
  template = data.sub($1, '')
22
25
 
23
26
  YAML.load_documents(yaml) do |front_matter|
24
27
  # allows partials to override locals defined higher up
25
- front_matter.delete_if { |key,value| locals.has_key?(key)}
26
- locals.merge!(front_matter)
28
+ front_matter.delete_if { |key,value| mustache_locals.has_key?(key)}
29
+ mustache_locals.merge!(front_matter)
27
30
  end
28
31
  else
29
32
  template = data
@@ -32,16 +35,17 @@ module Tilt
32
35
  scope.instance_variables.each do |instance_variable|
33
36
  symbol = instance_variable.to_s.gsub('@','').to_sym
34
37
 
35
- if ! locals[symbol]
36
- locals[symbol] = scope.instance_variable_get(instance_variable)
38
+ unless mustache_locals.member?(symbol)
39
+ mustache_locals[symbol] = scope.instance_variable_get(instance_variable)
37
40
  end
38
41
  end
39
42
 
40
- locals[:yield] = block.nil? ? '' : yield
41
- locals[:content] = locals[:yield]
43
+ mustache_locals[:yield] = block.nil? ? '' : yield
44
+ mustache_locals[:content] = mustache_locals[:yield]
42
45
 
43
- @output ||= ::Mustache.render(template, locals)
46
+ @output = ::Mustache.render(template, mustache_locals)
44
47
  end
45
48
  end
49
+
46
50
  register 'mustache', MustacheTemplate
47
51
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'mustache', '~> 0.99'
24
24
  s.add_dependency 'tilt', '~> 1.2', '~> 1.3'
25
25
 
26
- s.add_development_dependency 'rspec', '~> 2.8'
27
- s.add_development_dependency 'rack-test', '~> 0.6'
26
+ s.add_development_dependency 'rspec', '~> 2'
27
+ s.add_development_dependency 'rack-test', '~> 0'
28
28
  end
@@ -2,6 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  describe 'sinatra-mustache', :type => :request do
4
4
  subject { response }
5
+
6
+ context 'with an inline layout and template caching' do
7
+ before(:each) do
8
+ @app = mock_app {
9
+ disable :reload_templates
10
+ layout { 'Hello from {{ yield }}!' }
11
+ get('/foo') { mustache 'foo' }
12
+ get('/bar') { mustache 'bar' }
13
+ }
14
+ end
15
+
16
+ describe "two requests" do
17
+ it "does not cache wrong" do
18
+ get '/foo'
19
+ response.body.should == 'Hello from foo!'
20
+ get '/bar'
21
+ response.body.should == 'Hello from bar!'
22
+ end
23
+ end
24
+ end
5
25
 
6
26
  context 'inline mustache strings' do
7
27
  context 'without the :locals option' do
@@ -56,6 +56,56 @@ describe Tilt::MustacheTemplate do
56
56
  it 'locals should have precedence' do
57
57
  subject.should == 'Beer is great but Whisky is greater.'
58
58
  end
59
+ context "with locals evaluating to false" do
60
+ let(:locals) { { :beer => 'great', :whisky => nil } }
61
+ it 'locals should still have precedence' do
62
+ subject.should == 'Beer is great but Whisky is .'
63
+ end
64
+ end
65
+ end
66
+
67
+ context "data" do
68
+ let(:template) do
69
+ Tilt::MustacheTemplate.new {
70
+ '{{#beers }}{{ preference }} beer is {{ beer }}. {{/beers }} {{#whiskies }}{{ preference }} Whisky is {{ whisky }}. {{/whiskies }}'
71
+ }
72
+ end
73
+ let!(:data) { {:beers => [{:preference => "The best", :beer => "Gulp"}, {:preference => "The second best", :beer => "German Schluck"}],
74
+ :whiskies => [{:preference => "The worst", :whisky => "Rotten Brew"}, {:preference => "The best", :whisky => "Barley Pure"}]} }
75
+ let(:scope) do
76
+ scope = Object.new
77
+ scope
78
+ end
79
+ subject { template.render(scope, data) }
80
+ it "should not be modified through rendering" do
81
+ subject.should == "The best beer is Gulp. The second best beer is German Schluck. The worst Whisky is Rotten Brew. The best Whisky is Barley Pure. "
82
+ data.keys.map(&:to_s).sort.should == %W(beers whiskies)
83
+ end
84
+ end
85
+
86
+ context "when locals are changing for the same template" do
87
+ let(:template) {
88
+ Tilt::MustacheTemplate.new {
89
+ 'Beer is {{ beer }} but Whisky is {{ whisky }}.'
90
+ }
91
+ }
92
+ before(:all) do
93
+ @template = template
94
+ end
95
+ context "first time rendering" do
96
+ let(:first_locals) { { :beer => 'great', :whisky => 'greater' } }
97
+ subject { @template.render(Object.new, first_locals) }
98
+ it 'should render fine' do
99
+ subject.should == 'Beer is great but Whisky is greater.'
100
+ end
101
+ end
102
+ context "second time rendering with changed locals" do
103
+ let(:second_locals) { { :beer => 'nice', :whisky => 'the best' } }
104
+ subject { @template.render(Object.new, second_locals) }
105
+ it 'should render fine' do
106
+ subject.should == 'Beer is nice but Whisky is the best.'
107
+ end
108
+ end
59
109
  end
60
110
 
61
111
  context 'passing a block' do
metadata CHANGED
@@ -1,91 +1,115 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra-mustache
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 5
9
+ version: 0.0.5
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Jason Campbell
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-03-02 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-12-18 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: sinatra
16
- requirement: &70361526468220 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
19
25
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.2'
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ version: "1.2"
22
31
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: '1.3'
32
+ - !ruby/object:Gem::Version
33
+ segments:
34
+ - 1
35
+ - 3
36
+ version: "1.3"
25
37
  type: :runtime
26
- prerelease: false
27
- version_requirements: *70361526468220
28
- - !ruby/object:Gem::Dependency
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
29
40
  name: mustache
30
- requirement: &70361526467140 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ requirements:
33
44
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: '0.99'
45
+ - !ruby/object:Gem::Version
46
+ segments:
47
+ - 0
48
+ - 99
49
+ version: "0.99"
36
50
  type: :runtime
37
- prerelease: false
38
- version_requirements: *70361526467140
39
- - !ruby/object:Gem::Dependency
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
40
53
  name: tilt
41
- requirement: &70361526466500 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ requirements:
44
57
  - - ~>
45
- - !ruby/object:Gem::Version
46
- version: '1.2'
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 1
61
+ - 2
62
+ version: "1.2"
47
63
  - - ~>
48
- - !ruby/object:Gem::Version
49
- version: '1.3'
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 3
68
+ version: "1.3"
50
69
  type: :runtime
51
- prerelease: false
52
- version_requirements: *70361526466500
53
- - !ruby/object:Gem::Dependency
70
+ version_requirements: *id003
71
+ - !ruby/object:Gem::Dependency
54
72
  name: rspec
55
- requirement: &70361526465620 !ruby/object:Gem::Requirement
56
- none: false
57
- requirements:
73
+ prerelease: false
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ requirements:
58
76
  - - ~>
59
- - !ruby/object:Gem::Version
60
- version: '2.8'
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 2
80
+ version: "2"
61
81
  type: :development
62
- prerelease: false
63
- version_requirements: *70361526465620
64
- - !ruby/object:Gem::Dependency
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
65
84
  name: rack-test
66
- requirement: &70361526465020 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ requirements:
69
88
  - - ~>
70
- - !ruby/object:Gem::Version
71
- version: '0.6'
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
72
93
  type: :development
73
- prerelease: false
74
- version_requirements: *70361526465020
94
+ version_requirements: *id005
75
95
  description: Use Mustache in your Sinatra app without the extra view classes
76
- email:
96
+ email:
77
97
  - jason@greatergood.cc
78
98
  executables: []
99
+
79
100
  extensions: []
101
+
80
102
  extra_rdoc_files: []
81
- files:
103
+
104
+ files:
82
105
  - .gitignore
106
+ - .travis.yml
107
+ - Changelog.md
83
108
  - Gemfile
84
109
  - Gemfile.lock
85
110
  - LISCENSE
86
111
  - README.md
87
112
  - Rakefile
88
- - TODO.md
89
113
  - lib/sinatra-mustache/version.rb
90
114
  - lib/sinatra/mustache.rb
91
115
  - lib/tilt/mustache_template.rb
@@ -99,31 +123,37 @@ files:
99
123
  - spec/views/layout_too.mustache
100
124
  - spec/views/needs_partial.mustache
101
125
  - spec/views/yaml.mustache
126
+ has_rdoc: true
102
127
  homepage: http://github.com/jxson/sinatra-mustache
103
128
  licenses: []
129
+
104
130
  post_install_message:
105
131
  rdoc_options: []
106
- require_paths:
132
+
133
+ require_paths:
107
134
  - lib
108
- required_ruby_version: !ruby/object:Gem::Requirement
109
- none: false
110
- requirements:
111
- - - ! '>='
112
- - !ruby/object:Gem::Version
113
- version: '0'
114
- required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
- requirements:
117
- - - ! '>='
118
- - !ruby/object:Gem::Version
119
- version: '0'
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 0
148
+ version: "0"
120
149
  requirements: []
150
+
121
151
  rubyforge_project: sinatra-mustache
122
- rubygems_version: 1.8.6
152
+ rubygems_version: 1.3.6
123
153
  signing_key:
124
154
  specification_version: 3
125
155
  summary: Use Mustache in your Sinatra app without the extra view classes
126
- test_files:
156
+ test_files:
127
157
  - spec/mustache_spec.rb
128
158
  - spec/mustache_template_spec.rb
129
159
  - spec/request_helper.rb
data/TODO.md DELETED
@@ -1 +0,0 @@
1
- Soon: