tilt 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -308,9 +308,9 @@ The class or module where View classes are located. If you have
308
308
  `Hurl::App::Views`, namespace should be `Hurl:App`. This defaults to `Object`,
309
309
  causing `::Views` to be searched for classes.
310
310
 
311
- #### `:mustaches => nil`
311
+ #### `:mustaches => nil` or `:view_path => nil`
312
312
 
313
- Where mustache views (.rb files) are located, or nil to disable auto-requiring
313
+ Where mustache views (`.rb` files) are located, or `nil` to disable auto-requiring
314
314
  of views based on template names. By default, the view file is assumed to be in
315
315
  the same directory as the template file.
316
316
 
@@ -1,5 +1,5 @@
1
1
  module Tilt
2
- VERSION = '0.5'
2
+ VERSION = '0.6'
3
3
 
4
4
  @template_mappings = {}
5
5
 
@@ -77,6 +77,7 @@ module Tilt
77
77
  @line = line || 1
78
78
  @options = options || {}
79
79
  @reader = block || lambda { |t| File.read(file) }
80
+ @data = nil
80
81
 
81
82
  if !self.class.engine_initialized
82
83
  initialize_engine
@@ -400,9 +401,8 @@ module Tilt
400
401
  scope = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h }
401
402
  locals = scope.merge(locals)
402
403
  end
403
- # TODO: Is it possible to lazy yield ?
404
404
  locals['yield'] = block.nil? ? '' : yield
405
- locals['content'] = block.nil? ? '' : yield
405
+ locals['content'] = locals['yield']
406
406
  @engine.render(locals)
407
407
  end
408
408
  end
@@ -437,22 +437,22 @@ module Tilt
437
437
  register 'md', RDiscountTemplate
438
438
 
439
439
 
440
- # RedCloth implementation. See:
441
- # http://redcloth.org/
442
- class RedClothTemplate < Template
443
- def initialize_engine
444
- require_template_library 'redcloth' unless defined? ::RedCloth
445
- end
440
+ # RedCloth implementation. See:
441
+ # http://redcloth.org/
442
+ class RedClothTemplate < Template
443
+ def initialize_engine
444
+ require_template_library 'redcloth' unless defined? ::RedCloth
445
+ end
446
446
 
447
- def compile!
448
- @engine = RedCloth.new(data)
449
- end
447
+ def compile!
448
+ @engine = RedCloth.new(data)
449
+ end
450
450
 
451
- def evaluate(scope, locals, &block)
452
- @engine.to_html
451
+ def evaluate(scope, locals, &block)
452
+ @engine.to_html
453
+ end
453
454
  end
454
- end
455
- register 'textile', RedClothTemplate
455
+ register 'textile', RedClothTemplate
456
456
 
457
457
 
458
458
  # Mustache is written and maintained by Chris Wanstrath. See:
@@ -470,9 +470,10 @@ register 'textile', RedClothTemplate
470
470
 
471
471
  def compile!
472
472
  Mustache.view_namespace = options[:namespace]
473
+ Mustache.view_path = options[:view_path] || options[:mustaches]
473
474
  @engine = options[:view] || Mustache.view_class(name)
474
475
  options.each do |key, value|
475
- next if %w[view namespace mustaches].include?(key.to_s)
476
+ next if %w[view view_path namespace mustaches].include?(key.to_s)
476
477
  @engine.send("#{key}=", value) if @engine.respond_to? "#{key}="
477
478
  end
478
479
  end
@@ -525,4 +526,21 @@ register 'textile', RedClothTemplate
525
526
  end
526
527
  end
527
528
  register 'rdoc', RDocTemplate
529
+
530
+ # CoffeeScript info:
531
+ # http://jashkenas.github.com/coffee-script/
532
+ class CoffeeTemplate < Template
533
+ def initialize_engine
534
+ require_template_library 'coffee-script' unless defined? ::CoffeeScript
535
+ end
536
+
537
+ def compile!
538
+ @engine = ::CoffeeScript::compile(data, options)
539
+ end
540
+
541
+ def evaluate(scope, locals, &block)
542
+ @engine
543
+ end
544
+ end
545
+ register 'coffee', CoffeeTemplate
528
546
  end
@@ -0,0 +1,20 @@
1
+ require 'contest'
2
+ require 'tilt'
3
+
4
+ begin
5
+ require 'coffee-script'
6
+
7
+ class CoffeeTemplateTest < Test::Unit::TestCase
8
+ test "is registered for '.coffee' files" do
9
+ assert_equal Tilt::CoffeeTemplate, Tilt['test.coffee']
10
+ end
11
+
12
+ test "compiles and evaluates the template on #render" do
13
+ template = Tilt::CoffeeTemplate.new { |t| "greeting: \"Hello CoffeeScript\"" }
14
+ assert_equal "(function(){\n var greeting;\n greeting = \"Hello CoffeeScript\";\n})();", template.render
15
+ end
16
+ end
17
+
18
+ rescue LoadError => boom
19
+ warn "Tilt::CoffeeTemplate (disabled)\n"
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'mustache'
2
+
3
+ module Views
4
+ class External < Mustache
5
+ def hello
6
+ "Stached"
7
+ end
8
+ end
9
+ end
@@ -51,6 +51,15 @@ begin
51
51
  assert_equal "<p>Hello World!</p>", template.render
52
52
  end
53
53
 
54
+ test "locating views in files" do
55
+ view_path = File.expand_path('../tilt_mustache_views', __FILE__)
56
+ template = Tilt::MustacheTemplate.new('external.mustache', :view_path => view_path) { "<p>{{hello}}!</p>" }
57
+ template.compile
58
+ assert defined?(Views::External), "external.rb should have been required"
59
+ assert_equal Views::External, template.engine
60
+ assert_equal "<p>Stached!</p>", template.render
61
+ end
62
+
54
63
  test "copying instance variables from scope object" do
55
64
  template = Tilt::MustacheTemplate.new('foo.mustache') { "<p>Hey {{foo}}!</p>" }
56
65
  scope = Object.new
@@ -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.5'
7
- s.date = '2010-01-15'
6
+ s.version = '0.6'
7
+ s.date = '2010-02-22'
8
8
 
9
9
  s.description = "Generic interface to multiple Ruby template engines"
10
10
  s.summary = s.description
@@ -22,11 +22,13 @@ Gem::Specification.new do |s|
22
22
  lib/tilt.rb
23
23
  test/tilt_buildertemplate_test.rb
24
24
  test/tilt_cache_test.rb
25
+ test/tilt_coffeetemplate_test.rb
25
26
  test/tilt_erbtemplate_test.rb
26
27
  test/tilt_erubistemplate_test.rb
27
28
  test/tilt_hamltemplate_test.rb
28
29
  test/tilt_lesstemplate_test.rb
29
30
  test/tilt_liquidtemplate_test.rb
31
+ test/tilt_mustache_views/external.rb
30
32
  test/tilt_mustachetemplate_test.rb
31
33
  test/tilt_rdiscounttemplate_test.rb
32
34
  test/tilt_rdoctemplate_test.rb
metadata CHANGED
@@ -1,7 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tilt
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 6
8
+ version: "0.6"
5
9
  platform: ruby
6
10
  authors:
7
11
  - Ryan Tomayko
@@ -9,89 +13,105 @@ autorequire:
9
13
  bindir: bin
10
14
  cert_chain: []
11
15
 
12
- date: 2010-01-15 00:00:00 -08:00
16
+ date: 2010-02-22 00:00:00 -08:00
13
17
  default_executable:
14
18
  dependencies:
15
19
  - !ruby/object:Gem::Dependency
16
20
  name: contest
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
20
23
  requirements:
21
24
  - - ">="
22
25
  - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
23
28
  version: "0"
24
- version:
29
+ type: :development
30
+ version_requirements: *id001
25
31
  - !ruby/object:Gem::Dependency
26
32
  name: builder
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
33
+ prerelease: false
34
+ requirement: &id002 !ruby/object:Gem::Requirement
30
35
  requirements:
31
36
  - - ">="
32
37
  - !ruby/object:Gem::Version
38
+ segments:
39
+ - 0
33
40
  version: "0"
34
- version:
41
+ type: :development
42
+ version_requirements: *id002
35
43
  - !ruby/object:Gem::Dependency
36
44
  name: erubis
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
45
+ prerelease: false
46
+ requirement: &id003 !ruby/object:Gem::Requirement
40
47
  requirements:
41
48
  - - ">="
42
49
  - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
43
52
  version: "0"
44
- version:
53
+ type: :development
54
+ version_requirements: *id003
45
55
  - !ruby/object:Gem::Dependency
46
56
  name: haml
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
57
+ prerelease: false
58
+ requirement: &id004 !ruby/object:Gem::Requirement
50
59
  requirements:
51
60
  - - ">="
52
61
  - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
53
64
  version: "0"
54
- version:
65
+ type: :development
66
+ version_requirements: *id004
55
67
  - !ruby/object:Gem::Dependency
56
68
  name: mustache
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
69
+ prerelease: false
70
+ requirement: &id005 !ruby/object:Gem::Requirement
60
71
  requirements:
61
72
  - - ">="
62
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
63
76
  version: "0"
64
- version:
77
+ type: :development
78
+ version_requirements: *id005
65
79
  - !ruby/object:Gem::Dependency
66
80
  name: rdiscount
67
- type: :development
68
- version_requirement:
69
- version_requirements: !ruby/object:Gem::Requirement
81
+ prerelease: false
82
+ requirement: &id006 !ruby/object:Gem::Requirement
70
83
  requirements:
71
84
  - - ">="
72
85
  - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
73
88
  version: "0"
74
- version:
89
+ type: :development
90
+ version_requirements: *id006
75
91
  - !ruby/object:Gem::Dependency
76
92
  name: liquid
77
- type: :development
78
- version_requirement:
79
- version_requirements: !ruby/object:Gem::Requirement
93
+ prerelease: false
94
+ requirement: &id007 !ruby/object:Gem::Requirement
80
95
  requirements:
81
96
  - - ">="
82
97
  - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
83
100
  version: "0"
84
- version:
101
+ type: :development
102
+ version_requirements: *id007
85
103
  - !ruby/object:Gem::Dependency
86
104
  name: less
87
- type: :development
88
- version_requirement:
89
- version_requirements: !ruby/object:Gem::Requirement
105
+ prerelease: false
106
+ requirement: &id008 !ruby/object:Gem::Requirement
90
107
  requirements:
91
108
  - - ">="
92
109
  - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
93
112
  version: "0"
94
- version:
113
+ type: :development
114
+ version_requirements: *id008
95
115
  description: Generic interface to multiple Ruby template engines
96
116
  email: r@tomayko.com
97
117
  executables: []
@@ -109,11 +129,13 @@ files:
109
129
  - lib/tilt.rb
110
130
  - test/tilt_buildertemplate_test.rb
111
131
  - test/tilt_cache_test.rb
132
+ - test/tilt_coffeetemplate_test.rb
112
133
  - test/tilt_erbtemplate_test.rb
113
134
  - test/tilt_erubistemplate_test.rb
114
135
  - test/tilt_hamltemplate_test.rb
115
136
  - test/tilt_lesstemplate_test.rb
116
137
  - test/tilt_liquidtemplate_test.rb
138
+ - test/tilt_mustache_views/external.rb
117
139
  - test/tilt_mustachetemplate_test.rb
118
140
  - test/tilt_rdiscounttemplate_test.rb
119
141
  - test/tilt_rdoctemplate_test.rb
@@ -141,18 +163,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
163
  requirements:
142
164
  - - ">="
143
165
  - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
144
168
  version: "0"
145
- version:
146
169
  required_rubygems_version: !ruby/object:Gem::Requirement
147
170
  requirements:
148
171
  - - ">="
149
172
  - !ruby/object:Gem::Version
173
+ segments:
174
+ - 0
150
175
  version: "0"
151
- version:
152
176
  requirements: []
153
177
 
154
178
  rubyforge_project: wink
155
- rubygems_version: 1.3.5
179
+ rubygems_version: 1.3.6
156
180
  signing_key:
157
181
  specification_version: 2
158
182
  summary: Generic interface to multiple Ruby template engines