tilt 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +0,0 @@
1
- require 'bacon'
2
- require 'tilt'
3
-
4
- begin
5
- require 'haml'
6
- require 'sass'
7
-
8
- describe Tilt::SassTemplate do
9
- it "is registered for '.sass' files" do
10
- Tilt['test.sass'].should.equal Tilt::SassTemplate
11
- end
12
-
13
- it "compiles and evaluates the template on #render" do
14
- template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000ff" }
15
- template.render.should.equal "#main {\n background-color: #0000ff; }\n"
16
- end
17
- end
18
-
19
- rescue LoadError => boom
20
- warn "Tilt::SassTemplate (disabled)\n"
21
- end
@@ -1,110 +0,0 @@
1
- require 'bacon'
2
- require 'tilt'
3
-
4
- describe Tilt::Template do
5
- it "raises ArgumentError when a file or block not given" do
6
- lambda { Tilt::Template.new }.should.raise ArgumentError
7
- end
8
-
9
- it "can be constructed with a file" do
10
- inst = Tilt::Template.new('foo.erb')
11
- inst.file.should.equal 'foo.erb'
12
- end
13
-
14
- it "can be constructed with a file and line" do
15
- inst = Tilt::Template.new('foo.erb', 55)
16
- inst.file.should.equal 'foo.erb'
17
- inst.line.should.equal 55
18
- end
19
-
20
- it "uses the filename provided for #eval_file" do
21
- inst = Tilt::Template.new('foo.erb', 55)
22
- inst.eval_file.should.equal 'foo.erb'
23
- end
24
-
25
- it "uses a default filename for #eval_file when no file provided" do
26
- inst = Tilt::Template.new { 'Hi' }
27
- inst.eval_file.should.not.be.nil
28
- inst.eval_file.should.not.include "\n"
29
- end
30
-
31
- it "responds to #basename with the file's basename" do
32
- inst = Tilt::Template.new('/tmp/templates/foo.html.erb')
33
- inst.basename.should.equal 'foo.html.erb'
34
- end
35
-
36
- it "responds to #name with the file's basename minus file extensions" do
37
- inst = Tilt::Template.new('/tmp/templates/foo.html.erb')
38
- inst.name.should.equal 'foo'
39
- end
40
-
41
- it "can be constructed with a data loading block" do
42
- lambda {
43
- Tilt::Template.new { |template| "Hello World!" }
44
- }.should.not.raise
45
- end
46
-
47
- it "raises NotImplementedError when #compile! not defined" do
48
- inst = Tilt::Template.new { |template| "Hello World!" }
49
- lambda { inst.render }.should.raise NotImplementedError
50
- end
51
-
52
- class CompilingMockTemplate < Tilt::Template
53
- def compile!
54
- data.should.not.be.nil
55
- @compiled = true
56
- end
57
- def compiled? ; @compiled ; end
58
- end
59
-
60
- it "raises NotImplementedError when #evaluate or #template_source not defined" do
61
- inst = CompilingMockTemplate.new { |t| "Hello World!" }
62
- lambda { inst.render }.should.raise NotImplementedError
63
- inst.should.be.compiled
64
- end
65
-
66
- class SimpleMockTemplate < CompilingMockTemplate
67
- def evaluate(scope, locals, &block)
68
- should.be.compiled
69
- scope.should.not.be.nil
70
- locals.should.not.be.nil
71
- "<em>#{@data}</em>"
72
- end
73
- end
74
-
75
- it "compiles and evaluates the template on #render" do
76
- inst = SimpleMockTemplate.new { |t| "Hello World!" }
77
- inst.render.should.equal "<em>Hello World!</em>"
78
- inst.should.be.compiled
79
- end
80
-
81
- class SourceGeneratingMockTemplate < CompilingMockTemplate
82
- def template_source
83
- "foo = [] ; foo << %Q{#{data}} ; foo.join"
84
- end
85
- end
86
-
87
- it "evaluates template_source with locals support" do
88
- inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{name}!' }
89
- inst.render(Object.new, :name => 'Joe').should.equal "Hey Joe!"
90
- inst.should.be.compiled
91
- end
92
-
93
- class Person
94
- attr_accessor :name
95
- def initialize(name)
96
- @name = name
97
- end
98
- end
99
-
100
- it "evaluates template_source in the object scope provided" do
101
- inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{@name}!' }
102
- scope = Person.new('Joe')
103
- inst.render(scope).should.equal "Hey Joe!"
104
- end
105
-
106
- it "evaluates template_source with yield support" do
107
- inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{yield}!' }
108
- inst.render(Object.new){ 'Joe' }.should.equal "Hey Joe!"
109
- end
110
- end