tilt 0.7 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/contest.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "test/unit"
2
+
3
+ # Test::Unit loads a default test if the suite is empty, whose purpose is to
4
+ # fail. Since having empty contexts is a common practice, we decided to
5
+ # overwrite TestSuite#empty? in order to allow them. Having a failure when no
6
+ # tests have been defined seems counter-intuitive.
7
+ class Test::Unit::TestSuite
8
+ def empty?
9
+ false
10
+ end
11
+ end
12
+
13
+ # Contest adds +teardown+, +test+ and +context+ as class methods, and the
14
+ # instance methods +setup+ and +teardown+ now iterate on the corresponding
15
+ # blocks. Note that all setup and teardown blocks must be defined with the
16
+ # block syntax. Adding setup or teardown instance methods defeats the purpose
17
+ # of this library.
18
+ class Test::Unit::TestCase
19
+ def self.setup(&block)
20
+ define_method :setup do
21
+ super(&block)
22
+ instance_eval(&block)
23
+ end
24
+ end
25
+
26
+ def self.teardown(&block)
27
+ define_method :teardown do
28
+ instance_eval(&block)
29
+ super(&block)
30
+ end
31
+ end
32
+
33
+ def self.context(name, &block)
34
+ subclass = Class.new(self)
35
+ remove_tests(subclass)
36
+ subclass.class_eval(&block) if block_given?
37
+ const_set(context_name(name), subclass)
38
+ end
39
+
40
+ def self.test(name, &block)
41
+ define_method(test_name(name), &block)
42
+ end
43
+
44
+ class << self
45
+ alias_method :should, :test
46
+ alias_method :describe, :context
47
+ end
48
+
49
+ private
50
+
51
+ def self.context_name(name)
52
+ "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
53
+ end
54
+
55
+ def self.test_name(name)
56
+ "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
57
+ end
58
+
59
+ def self.sanitize_name(name)
60
+ name.gsub(/\W+/, ' ').strip
61
+ end
62
+
63
+ def self.remove_tests(subclass)
64
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
65
+ subclass.send(:undef_method, meth.to_sym)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1 @@
1
+ li foo
@@ -0,0 +1 @@
1
+ text "hello from markaby!"
@@ -0,0 +1 @@
1
+ text "_why?"
@@ -0,0 +1 @@
1
+ text "foo"
@@ -0,0 +1 @@
1
+ li foo
@@ -0,0 +1,2 @@
1
+ text("Hey ")
2
+ yield
@@ -14,10 +14,9 @@ class TiltCacheTest < Test::Unit::TestCase
14
14
 
15
15
  test "caching with multiple complex arguments to #fetch" do
16
16
  template = nil
17
- args = ['hello', {:foo => 'bar', :baz => 'bizzle'}]
18
- result = @cache.fetch(*args) { template = Tilt::StringTemplate.new {''} }
17
+ result = @cache.fetch('hello', {:foo => 'bar', :baz => 'bizzle'}) { template = Tilt::StringTemplate.new {''} }
19
18
  assert_same template, result
20
- result = @cache.fetch(*args) { fail 'should be cached' }
19
+ result = @cache.fetch('hello', {:foo => 'bar', :baz => 'bizzle'}) { fail 'should be cached' }
21
20
  assert_same template, result
22
21
  end
23
22
 
@@ -0,0 +1,25 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'coffee_script'
6
+
7
+ class CoffeeScriptTemplateTest < Test::Unit::TestCase
8
+ test "is registered for '.coffee' files" do
9
+ assert_equal Tilt::CoffeeScriptTemplate, Tilt['test.coffee']
10
+ end
11
+
12
+ test "compiles and evaluates the template on #render" do
13
+ template = Tilt::CoffeeScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
14
+ assert_equal "(function() {\n puts('Hello, World!');\n})();\n", template.render
15
+ end
16
+
17
+ test "disabling coffee-script wrapper" do
18
+ template = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { |t| "puts 'Hello, World!'\n" }
19
+ assert_equal "puts('Hello, World!');", template.render
20
+ end
21
+ end
22
+
23
+ rescue LoadError => boom
24
+ warn "Tilt::CoffeeScriptTemplate (disabled)\n"
25
+ end
@@ -1,5 +1,6 @@
1
1
  require 'contest'
2
2
  require 'tilt'
3
+ require 'thread'
3
4
 
4
5
  class CompileSiteTest < Test::Unit::TestCase
5
6
  def setup
@@ -10,7 +11,7 @@ class CompileSiteTest < Test::Unit::TestCase
10
11
  def prepare
11
12
  end
12
13
 
13
- def template_source
14
+ def precompiled_template(locals)
14
15
  @data.inspect
15
16
  end
16
17
  end
@@ -22,7 +23,7 @@ class CompileSiteTest < Test::Unit::TestCase
22
23
  test "compiling template source to a method" do
23
24
  template = CompilingTemplate.new { |t| "Hello World!" }
24
25
  template.render(Scope.new)
25
- method_name = template.send(:compiled_method_name, [].hash)
26
+ method_name = template.send(:compiled_method_name, [])
26
27
  method_name = method_name.to_sym if Symbol === Kernel.methods.first
27
28
  assert Tilt::CompileSite.instance_methods.include?(method_name),
28
29
  "CompileSite.instance_methods.include?(#{method_name.inspect})"
@@ -32,7 +33,7 @@ class CompileSiteTest < Test::Unit::TestCase
32
33
 
33
34
  test 'garbage collecting compiled methods' do
34
35
  template = CompilingTemplate.new { '' }
35
- method_name = template.send(:compiled_method_name, [].hash)
36
+ method_name = template.send(:compiled_method_name, [])
36
37
  template.render(Scope.new)
37
38
  assert Scope.new.respond_to?(method_name)
38
39
  Tilt::Template.send(
@@ -46,7 +47,7 @@ class CompileSiteTest < Test::Unit::TestCase
46
47
  def self.create_and_destroy_template
47
48
  template = CompilingTemplate.new { 'Hello World' }
48
49
  template.render(Scope.new)
49
- method_name = template.send(:compiled_method_name, [].hash)
50
+ method_name = template.send(:compiled_method_name, [])
50
51
  method_name = method_name.to_sym if Symbol === Kernel.methods.first
51
52
  [template.object_id, method_name]
52
53
  end
@@ -59,4 +60,27 @@ class CompileSiteTest < Test::Unit::TestCase
59
60
  assert !Scope.new.respond_to?(finalized_method_name),
60
61
  "Scope.new.respond_to?(#{finalized_method_name.inspect})"
61
62
  end
63
+
64
+ # This test attempts to surface issues with compiling templates from
65
+ # multiple threads.
66
+ test "using compiled templates from multiple threads" do
67
+ template = CompilingTemplate.new { 'template' }
68
+ main_thread = Thread.current
69
+ 10.times do |i|
70
+ threads =
71
+ (1..50).map do |j|
72
+ Thread.new {
73
+ begin
74
+ locals = { "local#{i}" => 'value' }
75
+ res = template.render(self, locals)
76
+ thread_id = Thread.current.object_id
77
+ res = template.render(self, "local#{thread_id.to_s}" => 'value')
78
+ rescue => boom
79
+ main_thread.raise(boom)
80
+ end
81
+ }
82
+ end
83
+ threads.each { |t| t.join }
84
+ end
85
+ end
62
86
  end
@@ -29,6 +29,23 @@ class ERBTemplateTest < Test::Unit::TestCase
29
29
  assert_equal "Hey Joe!", template.render(scope)
30
30
  end
31
31
 
32
+ class MockOutputVariableScope
33
+ attr_accessor :exposed_buffer
34
+ end
35
+
36
+ test "exposing the buffer to the template by default" do
37
+ begin
38
+ Tilt::ERBTemplate.default_output_variable = '@_out_buf'
39
+ template = Tilt::ERBTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
40
+ scope = MockOutputVariableScope.new
41
+ template.render(scope)
42
+ assert_not_nil scope.exposed_buffer
43
+ assert_equal scope.exposed_buffer, 'hey'
44
+ ensure
45
+ Tilt::ERBTemplate.default_output_variable = '_erbout'
46
+ end
47
+ end
48
+
32
49
  test "passing a block for yield" do
33
50
  template = Tilt::ERBTemplate.new { 'Hey <%= yield %>!' }
34
51
  assert_equal "Hey Joe!", template.render { 'Joe' }
@@ -102,7 +119,7 @@ class CompiledERBTemplateTest < Test::Unit::TestCase
102
119
  test "compiling template source to a method" do
103
120
  template = Tilt::ERBTemplate.new { |t| "Hello World!" }
104
121
  template.render(Scope.new)
105
- method_name = template.send(:compiled_method_name, [].hash)
122
+ method_name = template.send(:compiled_method_name, [])
106
123
  method_name = method_name.to_sym if Symbol === Kernel.methods.first
107
124
  assert Tilt::CompileSite.instance_methods.include?(method_name),
108
125
  "CompileSite.instance_methods.include?(#{method_name.inspect})"
@@ -26,6 +26,23 @@ begin
26
26
  assert_equal "Hey Joe!", template.render(scope)
27
27
  end
28
28
 
29
+ class MockOutputVariableScope
30
+ attr_accessor :exposed_buffer
31
+ end
32
+
33
+ test "exposing the buffer to the template by default" do
34
+ begin
35
+ Tilt::ErubisTemplate.default_output_variable = '@_out_buf'
36
+ template = Tilt::ErubisTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
37
+ scope = MockOutputVariableScope.new
38
+ template.render(scope)
39
+ assert_not_nil scope.exposed_buffer
40
+ assert_equal scope.exposed_buffer, 'hey'
41
+ ensure
42
+ Tilt::ErubisTemplate.default_output_variable = '_erbout'
43
+ end
44
+ end
45
+
29
46
  test "passing a block for yield" do
30
47
  template = Tilt::ErubisTemplate.new { 'Hey <%= yield %>!' }
31
48
  assert_equal "Hey Joe!", template.render { 'Joe' }
@@ -77,6 +94,32 @@ begin
77
94
  assert_equal '2', template.render(scope)
78
95
  assert_equal 'original value', scope.instance_variable_get(:@buf)
79
96
  end
97
+
98
+ test "using Erubis::EscapedEruby subclass via :engine_class option" do
99
+ template = Tilt::ErubisTemplate.new(nil, :engine_class => ::Erubis::EscapedEruby) { |t| %(<%= "<p>Hello World!</p>" %>) }
100
+ assert_equal "&lt;p&gt;Hello World!&lt;/p&gt;", template.render
101
+ end
102
+
103
+ test "using :escape_html => true option" do
104
+ template = Tilt::ErubisTemplate.new(nil, :escape_html => true) { |t| %(<%= "<p>Hello World!</p>" %>) }
105
+ assert_equal "&lt;p&gt;Hello World!&lt;/p&gt;", template.render
106
+ end
107
+
108
+ test "using :escape_html => false option" do
109
+ template = Tilt::ErubisTemplate.new(nil, :escape_html => false) { |t| %(<%= "<p>Hello World!</p>" %>) }
110
+ assert_equal "<p>Hello World!</p>", template.render
111
+ end
112
+
113
+ test "erubis default does not escape html" do
114
+ template = Tilt::ErubisTemplate.new { |t| %(<%= "<p>Hello World!</p>" %>) }
115
+ assert_equal "<p>Hello World!</p>", template.render
116
+ end
117
+
118
+ test "does not modify options argument" do
119
+ options_hash = {:escape_html => true}
120
+ template = Tilt::ErubisTemplate.new(nil, options_hash) { |t| "Hello World!" }
121
+ assert_equal({:escape_html => true}, options_hash)
122
+ end
80
123
  end
81
124
  rescue LoadError => boom
82
125
  warn "Tilt::ErubisTemplate (disabled)\n"
@@ -71,6 +71,17 @@ begin
71
71
  include Tilt::CompileSite
72
72
  end
73
73
 
74
+ test "compiling template source to a method" do
75
+ template = Tilt::HamlTemplate.new { |t| "Hello World!" }
76
+ template.render(Scope.new)
77
+ method_name = template.send(:compiled_method_name, [])
78
+ method_name = method_name.to_sym if Symbol === Kernel.methods.first
79
+ assert Tilt::CompileSite.instance_methods.include?(method_name),
80
+ "CompileSite.instance_methods.include?(#{method_name.inspect})"
81
+ assert Scope.new.respond_to?(method_name),
82
+ "scope.respond_to?(#{method_name.inspect})"
83
+ end
84
+
74
85
  test "passing locals" do
75
86
  template = Tilt::HamlTemplate.new { "%p= 'Hey ' + name + '!'" }
76
87
  assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new, :name => 'Joe')
@@ -0,0 +1,73 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'markaby'
6
+
7
+ class MarkabyTiltTest < Test::Unit::TestCase
8
+ def setup
9
+ @block = lambda do |t|
10
+ File.read(File.dirname(__FILE__) + "/#{t.file}")
11
+ end
12
+ end
13
+
14
+ test "should be able to render a markaby template with static html" do
15
+ tilt = Tilt::MarkabyTemplate.new("markaby/markaby.mab", &@block)
16
+ assert_equal "hello from markaby!", tilt.render
17
+ end
18
+
19
+ test "should use the contents of the template" do
20
+ tilt = ::Tilt::MarkabyTemplate.new("markaby/markaby_other_static.mab", &@block)
21
+ assert_equal "_why?", tilt.render
22
+ end
23
+
24
+ test "should render from a string (given as data)" do
25
+ tilt = ::Tilt::MarkabyTemplate.new { "html do; end" }
26
+ assert_equal "<html></html>", tilt.render
27
+ end
28
+
29
+ test "should evaluate a template file in the scope given" do
30
+ scope = Object.new
31
+ def scope.foo
32
+ "bar"
33
+ end
34
+
35
+ tilt = ::Tilt::MarkabyTemplate.new("markaby/scope.mab", &@block)
36
+ assert_equal "<li>bar</li>", tilt.render(scope)
37
+ end
38
+
39
+ test "should pass locals to the template" do
40
+ tilt = ::Tilt::MarkabyTemplate.new("markaby/locals.mab", &@block)
41
+ assert_equal "<li>bar</li>", tilt.render(Object.new, { :foo => "bar" })
42
+ end
43
+
44
+ test "should yield to the block given" do
45
+ tilt = ::Tilt::MarkabyTemplate.new("markaby/yielding.mab", &@block)
46
+ eval_scope = Markaby::Builder.new
47
+
48
+ output = tilt.render(Object.new, {}) do
49
+ text("Joe")
50
+ end
51
+
52
+ assert_equal "Hey Joe", output
53
+ end
54
+
55
+ test "should be able to render two templates in a row" do
56
+ tilt = ::Tilt::MarkabyTemplate.new("markaby/render_twice.mab", &@block)
57
+
58
+ assert_equal "foo", tilt.render
59
+ assert_equal "foo", tilt.render
60
+ end
61
+
62
+ test "should retrieve a Tilt::MarkabyTemplate when calling Tilt['hello.mab']" do
63
+ assert_equal Tilt::MarkabyTemplate, ::Tilt['./markaby/markaby.mab']
64
+ end
65
+
66
+ test "should return a new instance of the implementation class (when calling Tilt.new)" do
67
+ assert ::Tilt.new(File.dirname(__FILE__) + "/markaby/markaby.mab").kind_of?(Tilt::MarkabyTemplate)
68
+ end
69
+ end
70
+
71
+ rescue LoadError => boom
72
+ warn "Tilt::MarkabyTemplate (disabled)\n"
73
+ end
@@ -0,0 +1,54 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'nokogiri'
6
+ class NokogiriTemplateTest < Test::Unit::TestCase
7
+ test "registered for '.nokogiri' files" do
8
+ assert_equal Tilt::NokogiriTemplate, Tilt['test.nokogiri']
9
+ assert_equal Tilt::NokogiriTemplate, Tilt['test.xml.nokogiri']
10
+ end
11
+
12
+ test "preparing and evaluating the template on #render" do
13
+ template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
14
+ doc = Nokogiri.XML template.render
15
+ assert_equal 'Hello World!', doc.root.text
16
+ assert_equal 'em', doc.root.name
17
+ end
18
+
19
+ test "passing locals" do
20
+ template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + name + '!')" }
21
+ doc = Nokogiri.XML template.render(Object.new, :name => 'Joe')
22
+ assert_equal 'Hey Joe!', doc.root.text
23
+ assert_equal 'em', doc.root.name
24
+ end
25
+
26
+ test "evaluating in an object scope" do
27
+ template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + @name + '!')" }
28
+ scope = Object.new
29
+ scope.instance_variable_set :@name, 'Joe'
30
+ doc = Nokogiri.XML template.render(scope)
31
+ assert_equal 'Hey Joe!', doc.root.text
32
+ assert_equal 'em', doc.root.name
33
+ end
34
+
35
+ test "passing a block for yield" do
36
+ template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + yield + '!')" }
37
+ doc = Nokogiri.XML template.render { 'Joe' }
38
+ assert_equal 'Hey Joe!', doc.root.text
39
+ assert_equal 'em', doc.root.name
40
+ end
41
+
42
+ test "block style templates" do
43
+ template =
44
+ Tilt::NokogiriTemplate.new do |t|
45
+ lambda { |xml| xml.em('Hey Joe!') }
46
+ end
47
+ doc = Nokogiri.XML template.render template.render
48
+ assert_equal 'Hey Joe!', doc.root.text
49
+ assert_equal 'em', doc.root.name
50
+ end
51
+ end
52
+ rescue LoadError
53
+ warn "Tilt::NokogiriTemplate (disabled)"
54
+ end
@@ -0,0 +1,70 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ # Disable radius tests under Ruby versions >= 1.9.1 since it's still buggy.
6
+ # Remove when fixed upstream.
7
+ raise LoadError if RUBY_VERSION >= "1.9.1"
8
+
9
+ require 'radius'
10
+
11
+ class RadiusTemplateTest < Test::Unit::TestCase
12
+ test "registered for '.radius' files" do
13
+ assert_equal Tilt::RadiusTemplate, Tilt['test.radius']
14
+ end
15
+
16
+ test "preparing and evaluating templates on #render" do
17
+ template = Tilt::RadiusTemplate.new { |t| "Hello World!" }
18
+ assert_equal "Hello World!", template.render
19
+ end
20
+
21
+ test "passing locals" do
22
+ template = Tilt::RadiusTemplate.new { "Hey <r:name />!" }
23
+ assert_equal "Hey Joe!", template.render(nil, :name => 'Joe')
24
+ end
25
+
26
+ class ExampleRadiusScope
27
+ def beer; 'wet'; end
28
+ def whisky; 'wetter'; end
29
+ end
30
+
31
+ test "combining scope and locals when scope responds" do
32
+ template = Tilt::RadiusTemplate.new {
33
+ 'Beer is <r:beer /> but Whisky is <r:whisky />.'
34
+ }
35
+ scope = ExampleRadiusScope.new
36
+ assert_equal "Beer is wet but Whisky is wetter.", template.render(scope)
37
+ end
38
+
39
+ test "precedence when locals and scope define same variables" do
40
+ template = Tilt::RadiusTemplate.new {
41
+ 'Beer is <r:beer /> but Whisky is <r:whisky />.'
42
+ }
43
+ scope = ExampleRadiusScope.new
44
+ assert_equal "Beer is great but Whisky is greater.",
45
+ template.render(scope, :beer => 'great', :whisky => 'greater')
46
+ end
47
+
48
+ #test "handles local scope" do
49
+ # beer = 'wet'
50
+ # whisky = 'wetter'
51
+ #
52
+ # template = Tilt::RadiusTemplate.new {
53
+ # 'Beer is <r:beer /> but Whisky is <r:whisky />.'
54
+ # }
55
+ # assert_equal "Beer is wet but Whisky is wetter.", template.render(self)
56
+ #end
57
+
58
+ test "passing a block for yield" do
59
+ template = Tilt::RadiusTemplate.new {
60
+ 'Beer is <r:yield /> but Whisky is <r:yield />ter.'
61
+ }
62
+ assert_equal "Beer is wet but Whisky is wetter.",
63
+ template.render({}) { 'wet' }
64
+ end
65
+ end
66
+
67
+ rescue LoadError => boom
68
+ warn "Tilt::RadiusTemplate (disabled)\n"
69
+ end
70
+
@@ -11,8 +11,19 @@ begin
11
11
  end
12
12
 
13
13
  test "compiles and evaluates the template on #render" do
14
- template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000ff" }
15
- assert_equal "#main {\n background-color: #0000ff; }\n", template.render
14
+ template = Tilt::SassTemplate.new { |t| "#main\n :background-color #0000f1" }
15
+ assert_equal "#main {\n background-color: #0000f1; }\n", template.render
16
+ end
17
+ end
18
+
19
+ class ScssTemplateTest < Test::Unit::TestCase
20
+ test "is registered for '.scss' files" do
21
+ assert_equal Tilt::ScssTemplate, Tilt['test.scss']
22
+ end
23
+
24
+ test "compiles and evaluates the template on #render" do
25
+ template = Tilt::ScssTemplate.new { |t| "#main {\n background-color: #0000f1;\n}" }
26
+ assert_equal "#main {\n background-color: #0000f1; }\n", template.render
16
27
  end
17
28
  end
18
29
 
@@ -80,7 +80,7 @@ class CompiledStringTemplateTest < Test::Unit::TestCase
80
80
  test "compiling template source to a method" do
81
81
  template = Tilt::StringTemplate.new { |t| "Hello World!" }
82
82
  template.render(Scope.new)
83
- method_name = template.send(:compiled_method_name, [].hash)
83
+ method_name = template.send(:compiled_method_name, [])
84
84
  method_name = method_name.to_sym if Symbol === Kernel.methods.first
85
85
  assert Tilt::CompileSite.instance_methods.include?(method_name),
86
86
  "CompileSite.instance_methods.include?(#{method_name.inspect})"
@@ -110,7 +110,7 @@ class TiltTemplateTest < Test::Unit::TestCase
110
110
  end
111
111
 
112
112
  class SourceGeneratingMockTemplate < PreparingMockTemplate
113
- def template_source
113
+ def precompiled_template(locals)
114
114
  "foo = [] ; foo << %Q{#{data}} ; foo.join"
115
115
  end
116
116
  end
@@ -122,6 +122,8 @@ class TiltTemplateTest < Test::Unit::TestCase
122
122
  end
123
123
 
124
124
  class Person
125
+ CONSTANT = "Bob"
126
+
125
127
  attr_accessor :name
126
128
  def initialize(name)
127
129
  @name = name
@@ -138,4 +140,19 @@ class TiltTemplateTest < Test::Unit::TestCase
138
140
  inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{yield}!' }
139
141
  assert_equal "Hey Joe!", inst.render(Object.new){ 'Joe' }
140
142
  end
143
+
144
+ test "template which accesses a constant" do
145
+ inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
146
+ assert_equal "Hey Bob!", inst.render(Person.new("Joe"))
147
+ end
148
+
149
+ class FastPerson < Person
150
+ include Tilt::CompileSite
151
+ end
152
+
153
+ test "template which accesses a constant with Tilt::CompileSite" do
154
+ flunk "known broken under 1.9.1" if RUBY_VERSION =~ /^1.9.1/
155
+ inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
156
+ assert_equal "Hey Bob!", inst.render(FastPerson.new("Joe"))
157
+ end
141
158
  end
data/test/tilt_test.rb CHANGED
@@ -14,15 +14,23 @@ class TiltTest < Test::Unit::TestCase
14
14
  Tilt.register('mock', MockTemplate)
15
15
  end
16
16
 
17
+ test "an extension is registered if explicit handle is found" do
18
+ Tilt.register('mock', MockTemplate)
19
+ assert Tilt.registered?('mock')
20
+ end
21
+
17
22
  test "registering template classes by symbol file extension" do
18
23
  Tilt.register(:mock, MockTemplate)
19
24
  end
20
25
 
21
- test "looking up template classes by file extension" do
26
+ test "looking up template classes by exact file extension" do
22
27
  Tilt.register('mock', MockTemplate)
23
28
  impl = Tilt['mock']
24
29
  assert_equal MockTemplate, impl
30
+ end
25
31
 
32
+ test "looking up template classes by implicit file extension" do
33
+ Tilt.register('mock', MockTemplate)
26
34
  impl = Tilt['.mock']
27
35
  assert_equal MockTemplate, impl
28
36
  end
data/tilt.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'tilt'
6
- s.version = '0.7'
7
- s.date = '2010-03-04'
6
+ s.version = '1.1'
7
+ s.date = '2010-09-10'
8
8
 
9
9
  s.description = "Generic interface to multiple Ruby template engines"
10
10
  s.summary = s.description
@@ -20,17 +20,25 @@ Gem::Specification.new do |s|
20
20
  TEMPLATES.md
21
21
  bin/tilt
22
22
  lib/tilt.rb
23
+ test/contest.rb
24
+ test/markaby/locals.mab
25
+ test/markaby/markaby.mab
26
+ test/markaby/markaby_other_static.mab
27
+ test/markaby/render_twice.mab
28
+ test/markaby/scope.mab
29
+ test/markaby/yielding.mab
23
30
  test/tilt_buildertemplate_test.rb
24
31
  test/tilt_cache_test.rb
25
- test/tilt_coffeetemplate_test.rb
32
+ test/tilt_coffeescripttemplate_test.rb
26
33
  test/tilt_compilesite_test.rb
27
34
  test/tilt_erbtemplate_test.rb
28
35
  test/tilt_erubistemplate_test.rb
29
36
  test/tilt_hamltemplate_test.rb
30
37
  test/tilt_lesstemplate_test.rb
31
38
  test/tilt_liquidtemplate_test.rb
32
- test/tilt_mustache_views/external.rb
33
- test/tilt_mustachetemplate_test.rb
39
+ test/tilt_markaby_test.rb
40
+ test/tilt_nokogiritemplate_test.rb
41
+ test/tilt_radiustemplate_test.rb
34
42
  test/tilt_rdiscounttemplate_test.rb
35
43
  test/tilt_rdoctemplate_test.rb
36
44
  test/tilt_redclothtemplate_test.rb
@@ -42,15 +50,20 @@ Gem::Specification.new do |s|
42
50
  ]
43
51
  # = MANIFEST =
44
52
 
45
- s.test_files = s.files.select {|path| path =~ /^test\/spec_.*.rb/}
53
+ s.default_executable = 'tilt'
54
+ s.executables = ['tilt']
55
+
56
+ s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
46
57
  s.add_development_dependency 'contest'
47
58
  s.add_development_dependency 'builder'
48
59
  s.add_development_dependency 'erubis'
49
- s.add_development_dependency 'haml'
50
- s.add_development_dependency 'mustache'
60
+ s.add_development_dependency 'haml', '>= 2.2.11'
51
61
  s.add_development_dependency 'rdiscount'
52
62
  s.add_development_dependency 'liquid'
53
63
  s.add_development_dependency 'less'
64
+ s.add_development_dependency 'radius'
65
+ s.add_development_dependency 'nokogiri'
66
+ s.add_development_dependency 'markaby'
54
67
  s.add_development_dependency 'coffee-script'
55
68
 
56
69
  s.extra_rdoc_files = %w[COPYING]