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.
- data/.travis.yml +15 -0
- data/Changelog.md +5 -0
- data/Gemfile.lock +14 -14
- data/README.md +1 -1
- data/lib/sinatra-mustache/version.rb +1 -1
- data/lib/tilt/mustache_template.rb +11 -7
- data/sinatra-mustache.gemspec +2 -2
- data/spec/mustache_spec.rb +20 -0
- data/spec/mustache_template_spec.rb +50 -0
- metadata +99 -69
- data/TODO.md +0 -1
data/.travis.yml
ADDED
data/Changelog.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sinatra-mustache (0.0.
|
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
|
15
|
+
rack-protection (1.3.2)
|
16
16
|
rack
|
17
|
-
rack-test (0.6.
|
17
|
+
rack-test (0.6.2)
|
18
18
|
rack (>= 1.0)
|
19
|
-
rspec (2.
|
20
|
-
rspec-core (~> 2.
|
21
|
-
rspec-expectations (~> 2.
|
22
|
-
rspec-mocks (~> 2.
|
23
|
-
rspec-core (2.
|
24
|
-
rspec-expectations (2.
|
25
|
-
diff-lcs (~> 1.1.
|
26
|
-
rspec-mocks (2.
|
27
|
-
sinatra (1.3.
|
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
|
38
|
-
rspec (~> 2
|
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
|
@@ -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|
|
26
|
-
|
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
|
-
|
36
|
-
|
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
|
-
|
41
|
-
|
43
|
+
mustache_locals[:yield] = block.nil? ? '' : yield
|
44
|
+
mustache_locals[:content] = mustache_locals[:yield]
|
42
45
|
|
43
|
-
@output
|
46
|
+
@output = ::Mustache.render(template, mustache_locals)
|
44
47
|
end
|
45
48
|
end
|
49
|
+
|
46
50
|
register 'mustache', MustacheTemplate
|
47
51
|
end
|
data/sinatra-mustache.gemspec
CHANGED
@@ -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
|
27
|
-
s.add_development_dependency 'rack-test', '~> 0
|
26
|
+
s.add_development_dependency 'rspec', '~> 2'
|
27
|
+
s.add_development_dependency 'rack-test', '~> 0'
|
28
28
|
end
|
data/spec/mustache_spec.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
requirements:
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
19
25
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
version: "1.2"
|
22
31
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
segments:
|
34
|
+
- 1
|
35
|
+
- 3
|
36
|
+
version: "1.3"
|
25
37
|
type: :runtime
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
29
40
|
name: mustache
|
30
|
-
|
31
|
-
|
32
|
-
requirements:
|
41
|
+
prerelease: false
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
33
44
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 99
|
49
|
+
version: "0.99"
|
36
50
|
type: :runtime
|
37
|
-
|
38
|
-
|
39
|
-
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
40
53
|
name: tilt
|
41
|
-
|
42
|
-
|
43
|
-
requirements:
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
44
57
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 2
|
62
|
+
version: "1.2"
|
47
63
|
- - ~>
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 1
|
67
|
+
- 3
|
68
|
+
version: "1.3"
|
50
69
|
type: :runtime
|
51
|
-
|
52
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: *id003
|
71
|
+
- !ruby/object:Gem::Dependency
|
54
72
|
name: rspec
|
55
|
-
|
56
|
-
|
57
|
-
requirements:
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
58
76
|
- - ~>
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
segments:
|
79
|
+
- 2
|
80
|
+
version: "2"
|
61
81
|
type: :development
|
62
|
-
|
63
|
-
|
64
|
-
- !ruby/object:Gem::Dependency
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
65
84
|
name: rack-test
|
66
|
-
|
67
|
-
|
68
|
-
requirements:
|
85
|
+
prerelease: false
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
69
88
|
- - ~>
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
72
93
|
type: :development
|
73
|
-
|
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
|
-
|
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
|
-
|
132
|
+
|
133
|
+
require_paths:
|
107
134
|
- lib
|
108
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
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.
|
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:
|