tilt 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/Rakefile +6 -9
- data/TEMPLATES.md +369 -8
- data/lib/tilt.rb +156 -96
- data/test/tilt_buildertemplate_test.rb +44 -0
- data/test/tilt_cache_test.rb +33 -0
- data/test/tilt_erbtemplate_test.rb +93 -0
- data/test/tilt_erubistemplate_test.rb +85 -0
- data/test/{spec_tilt_hamltemplate.rb → tilt_hamltemplate_test.rb} +20 -20
- data/test/tilt_liquidtemplate_test.rb +73 -0
- data/test/{spec_tilt_mustachetemplate.rb → tilt_mustachetemplate_test.rb} +23 -23
- data/test/tilt_rdiscounttemplate_test.rb +40 -0
- data/test/tilt_rdoctemplate_test.rb +19 -0
- data/test/tilt_redclothtemplate_test.rb +20 -0
- data/test/tilt_sasstemplate_test.rb +21 -0
- data/test/{spec_tilt_stringtemplate.rb → tilt_stringtemplate_test.rb} +24 -24
- data/test/tilt_template_test.rb +136 -0
- data/test/tilt_test.rb +57 -0
- data/tilt.gemspec +23 -14
- metadata +90 -29
- data/test/.bacon +0 -0
- data/test/spec_tilt.rb +0 -53
- data/test/spec_tilt_buildertemplate.rb +0 -41
- data/test/spec_tilt_erbtemplate.rb +0 -93
- data/test/spec_tilt_erubistemplate.rb +0 -78
- data/test/spec_tilt_liquid_template.rb +0 -25
- data/test/spec_tilt_rdiscount.rb +0 -19
- data/test/spec_tilt_sasstemplate.rb +0 -21
- data/test/spec_tilt_template.rb +0 -110
@@ -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
|
data/test/spec_tilt_template.rb
DELETED
@@ -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
|