tilt 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/COPYING +1 -1
  2. data/Gemfile +31 -1
  3. data/HACKING +16 -0
  4. data/README.md +5 -2
  5. data/Rakefile +25 -1
  6. data/TEMPLATES.md +13 -13
  7. data/bin/tilt +8 -6
  8. data/lib/tilt.rb +15 -1
  9. data/lib/tilt/asciidoc.rb +34 -0
  10. data/lib/tilt/coffee.rb +4 -0
  11. data/lib/tilt/css.rb +10 -2
  12. data/lib/tilt/csv.rb +71 -0
  13. data/lib/tilt/erb.rb +1 -1
  14. data/lib/tilt/etanni.rb +27 -0
  15. data/lib/tilt/liquid.rb +4 -0
  16. data/lib/tilt/markdown.rb +35 -11
  17. data/lib/tilt/nokogiri.rb +4 -4
  18. data/lib/tilt/plain.rb +20 -0
  19. data/lib/tilt/radius.rb +4 -0
  20. data/lib/tilt/rdoc.rb +20 -5
  21. data/lib/tilt/template.rb +35 -74
  22. data/lib/tilt/textile.rb +5 -0
  23. data/lib/tilt/wiki.rb +8 -0
  24. data/test/tilt_asciidoctor_test.rb +44 -0
  25. data/test/tilt_blueclothtemplate_test.rb +1 -1
  26. data/test/tilt_coffeescripttemplate_test.rb +64 -11
  27. data/test/tilt_creoletemplate_test.rb +1 -1
  28. data/test/tilt_csv_test.rb +73 -0
  29. data/test/tilt_erbtemplate_test.rb +5 -0
  30. data/test/tilt_erubistemplate_test.rb +1 -1
  31. data/test/tilt_etannitemplate_test.rb +173 -0
  32. data/test/tilt_fallback_test.rb +6 -6
  33. data/test/tilt_hamltemplate_test.rb +1 -1
  34. data/test/tilt_kramdown_test.rb +1 -1
  35. data/test/tilt_lesstemplate_test.less +1 -0
  36. data/test/tilt_lesstemplate_test.rb +19 -3
  37. data/test/tilt_liquidtemplate_test.rb +1 -1
  38. data/test/tilt_markaby_test.rb +1 -1
  39. data/test/tilt_markdown_test.rb +15 -4
  40. data/test/tilt_marukutemplate_test.rb +1 -1
  41. data/test/tilt_radiustemplate_test.rb +1 -1
  42. data/test/tilt_rdiscounttemplate_test.rb +1 -1
  43. data/test/tilt_rdoctemplate_test.rb +10 -3
  44. data/test/tilt_redcarpettemplate_test.rb +15 -3
  45. data/test/tilt_redclothtemplate_test.rb +13 -1
  46. data/test/tilt_sasstemplate_test.rb +1 -1
  47. data/test/tilt_stringtemplate_test.rb +1 -1
  48. data/test/tilt_template_test.rb +13 -0
  49. data/test/tilt_wikiclothtemplate_test.rb +1 -1
  50. data/test/tilt_yajltemplate_test.rb +13 -4
  51. data/tilt.gemspec +27 -17
  52. metadata +203 -75
data/COPYING CHANGED
@@ -13,6 +13,6 @@ all copies or substantial portions of the Software.
13
13
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
14
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
15
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
17
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
18
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Gemfile CHANGED
@@ -1,2 +1,32 @@
1
1
  source "http://rubygems.org"
2
- gemspec
2
+
3
+ gem 'rake'
4
+ gem 'asciidoctor', '>= 0.1.0'
5
+ gem 'builder'
6
+ gem 'coffee-script'
7
+ gem 'contest'
8
+ gem 'creole'
9
+ gem 'erubis'
10
+ gem 'haml', '>= 2.2.11', '< 4'
11
+ gem 'kramdown'
12
+ gem 'less'
13
+ gem 'liquid'
14
+ gem 'markaby'
15
+ gem 'maruku'
16
+ gem 'nokogiri'
17
+ gem 'radius'
18
+ gem 'sass'
19
+ gem 'wikicloth'
20
+ gem 'rdoc', (ENV['RDOC_VERSION'] || '> 0')
21
+
22
+ platform :ruby do
23
+ gem 'yajl-ruby'
24
+ gem 'redcarpet'
25
+ gem 'rdiscount' if RUBY_VERSION != '1.9.2'
26
+ gem 'RedCloth'
27
+ end
28
+
29
+ platform :mri do
30
+ gem 'therubyracer'
31
+ gem 'bluecloth'
32
+ end
data/HACKING ADDED
@@ -0,0 +1,16 @@
1
+ Clone:
2
+
3
+ git clone git://github.com/rtomayko/tilt.git
4
+ cd tilt
5
+
6
+ Install needed packages under ./vendor and run tests (requires bundler):
7
+
8
+ rake
9
+
10
+ Run tests under your current gem environment. Do not install anything:
11
+
12
+ rake test
13
+
14
+ Only install needed packages under ./vendor:
15
+
16
+ rake setup
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Tilt
1
+ Tilt [![Build Status](https://secure.travis-ci.org/rtomayko/tilt.png)](http://travis-ci.org/rtomayko/tilt) [![Dependency Status](https://gemnasium.com/rtomayko/tilt.png)](https://gemnasium.com/rtomayko/tilt)
2
2
  ====
3
3
 
4
4
  Tilt is a thin interface over a bunch of different Ruby template engines in
@@ -23,6 +23,7 @@ Support for these template engines is included with the package:
23
23
 
24
24
  ENGINE FILE EXTENSIONS REQUIRED LIBRARIES
25
25
  -------------------------- ----------------------- ----------------------------
26
+ Asciidoctor .ad, .adoc, .asciidoc asciidoctor (>= 0.1.0)
26
27
  ERB .erb, .rhtml none (included ruby stdlib)
27
28
  Interpolated String .str none (included ruby core)
28
29
  Erubis .erb, .rhtml, .erubis erubis
@@ -46,6 +47,7 @@ Support for these template engines is included with the package:
46
47
  Creole (Wiki markup) .wiki, .creole creole
47
48
  WikiCloth (Wiki markup) .wiki, .mediawiki, .mw wikicloth
48
49
  Yajl .yajl yajl-ruby
50
+ CSV .csv none (Ruby >= 1.9), fastercsv (Ruby < 1.9)
49
51
 
50
52
  These template engines ship with their own Tilt integration:
51
53
 
@@ -55,6 +57,7 @@ These template engines ship with their own Tilt integration:
55
57
  Embedded JavaScript sprockets
56
58
  Embedded CoffeeScript sprockets
57
59
  JST sprockets
60
+ Org-mode .org org-ruby (>= 0.6.2)
58
61
 
59
62
  See [TEMPLATES.md][t] for detailed information on template engine
60
63
  options and supported features.
@@ -184,7 +187,7 @@ template, but if you depend on a specific implementation, you should use #prefer
184
187
 
185
188
  # Prefer BlueCloth for all its registered extensions (markdown, mkd, md)
186
189
  Tilt.prefer Tilt::BlueClothTemplate
187
-
190
+
188
191
  # Prefer Erubis for .erb only:
189
192
  Tilt.prefer Tilt::ErubisTemplate, 'erb'
190
193
 
data/Rakefile CHANGED
@@ -1,5 +1,28 @@
1
+ require 'rbconfig'
1
2
  require 'rake/testtask'
2
- task :default => :test
3
+ task :default => [:setup, :test]
4
+
5
+ # set GEM_HOME to use local ./vendor dir for tests
6
+ vendor_dir = './vendor'
7
+ ruby_version = RbConfig::CONFIG['ruby_version']
8
+ ruby_engine = (defined?(RUBY_ENGINE) && RUBY_ENGINE) || 'ruby'
9
+ gem_home = ENV['GEM_HOME'] = "#{vendor_dir}/#{ruby_engine}/#{ruby_version}"
10
+
11
+ # Write the current version.
12
+ task :version do
13
+ puts "#{ruby_engine} #{RUBY_VERSION} (#{gem_home})"
14
+ end
15
+
16
+ desc "Install gems to #{ENV['GEM_HOME']}"
17
+ task :setup do
18
+ verbose false do
19
+ sh "
20
+ bundle check >/dev/null || {
21
+ echo 'Updating #{gem_home}' &&
22
+ bundle install --path='#{vendor_dir}'; }
23
+ "
24
+ end
25
+ end
3
26
 
4
27
  # SPECS =====================================================================
5
28
 
@@ -14,6 +37,7 @@ Rake::TestTask.new(:test) do |t|
14
37
  t.ruby_opts = ['-Itest']
15
38
  t.ruby_opts << '-rubygems' if defined? Gem
16
39
  end
40
+ task :test => :version
17
41
 
18
42
  # PACKAGING =================================================================
19
43
 
@@ -57,7 +57,7 @@ implementations.
57
57
  ### Example
58
58
 
59
59
  Hello <%= world %>!
60
-
60
+
61
61
  ### Usage
62
62
 
63
63
  ERB templates support custom evaluation scopes and locals:
@@ -197,7 +197,7 @@ a replacement for inline page templating systems such as PHP, ASP, and ERB, the
197
197
  templating language used in most Ruby on Rails applications. However, Haml
198
198
  avoids the need for explicitly coding HTML into the template, because it itself
199
199
  is a description of the HTML, with some code to generate dynamic content.
200
- ([more](http://haml-lang.com/about.html))
200
+ ([more](http://haml.info/about.html))
201
201
 
202
202
 
203
203
  ### Example
@@ -243,13 +243,13 @@ using this template engine within a threaded environment.
243
243
 
244
244
  ### Options
245
245
 
246
- Please see the [Haml Reference](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#options) for all available options.
246
+ Please see the [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for all available options.
247
247
 
248
248
  ### See also
249
249
 
250
- * [#haml.docs](http://haml-lang.com/docs.html)
251
- * [Haml Tutorial](http://haml-lang.com/tutorial.html)
252
- * [Haml Reference](http://haml-lang.com/docs/yardoc/HAML_REFERENCE.md.html)
250
+ * [#haml.docs](http://haml.info/docs.html)
251
+ * [Haml Tutorial](http://haml.info/tutorial.html)
252
+ * [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html)
253
253
 
254
254
 
255
255
  <a name='liquid'></a>
@@ -294,7 +294,7 @@ default. Liquid templates support locals and objects that respond to
294
294
 
295
295
  Or, use `Tilt::LiquidTemplate` directly to process strings:
296
296
 
297
- >> require 'haml'
297
+ >> require 'liquid'
298
298
  >> template = Tilt::LiquidTemplate.new { "<h1>Hello Liquid!</h1>" }
299
299
  => #<Tilt::LiquidTemplate @file=nil ...>
300
300
  >> template.render
@@ -379,7 +379,7 @@ engine, which is a Ruby extension written in C.
379
379
  ### Example
380
380
 
381
381
  h1. Hello Textile Templates
382
-
382
+
383
383
  Hello World. This is a paragraph.
384
384
 
385
385
  ### Usage
@@ -407,9 +407,9 @@ library.
407
407
 
408
408
  ### Usage
409
409
 
410
- __NOTE:__ It's suggested that your program `require 'rdoc/markup'` and
411
- `require 'rdoc/markup/to_html'` at load time when using this template
412
- engine in a threaded environment.
410
+ __NOTE:__ It's suggested that your program `require 'rdoc'`,
411
+ `require 'rdoc/markup'`, and `require 'rdoc/markup/to_html'` at load time
412
+ when using this template engine in a threaded environment.
413
413
 
414
414
  ### See also
415
415
 
@@ -434,7 +434,7 @@ Markdown formatted texts are converted to HTML with one of these libraries:
434
434
  * Maruku - `Tilt::MarukuTemplate`
435
435
 
436
436
  Tilt will use fallback mode (as documented in the README) for determining which
437
- library to use. RDiscount has highest priority - Maruku has lowest.
437
+ library to use. RDiscount has highest priority - Maruku has lowest.
438
438
 
439
439
  ### Example
440
440
 
@@ -504,7 +504,7 @@ using this template engine within a threaded environment.
504
504
  [sass]: http://sass-lang.com/ "Sass"
505
505
  [coffee-script]: http://jashkenas.github.com/coffee-script/ "Coffee Script"
506
506
  [erubis]: http://www.kuwata-lab.com/erubis/ "Erubis"
507
- [haml]: http://haml-lang.org/ "Haml"
507
+ [haml]: http://haml.info/ "Haml"
508
508
  [liquid]: http://www.liquidmarkup.org/ "Liquid"
509
509
  [radius]: http://radius.rubyforge.org/ "Radius"
510
510
  [radiant]: http://radiantcms.org/ "Radiant CMS"
data/bin/tilt CHANGED
@@ -15,7 +15,7 @@ Options
15
15
  -y, --layout=<file> Use <file> as a layout template
16
16
 
17
17
  -D<name>=<value> Define variable <name> as <value>
18
- -o, --vars=<ruby> Evaluate <ruby> to Hash and use for variables
18
+ --vars=<ruby> Evaluate <ruby> to Hash and use for variables
19
19
 
20
20
  -h, --help Show this help message
21
21
 
@@ -27,9 +27,9 @@ Process ERB template:
27
27
  Answer: 4
28
28
 
29
29
  Define variables:
30
- $ echo "Answer: <%= 2 + n %>" | tilt --locals="{:n=>40, :x=>0}"
30
+ $ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}"
31
31
  Answer: 42
32
- $ echo "Answer: <%= 2 + n %>" | tilt -Dn=40 -Dx=0
32
+ $ echo "Answer: <%= 2 + n.to_i %>" | tilt -t erb -Dn=40
33
33
  Answer: 42
34
34
  USAGE
35
35
 
@@ -44,9 +44,11 @@ ARGV.options do |o|
44
44
  # list all available template engines
45
45
  o.on("-l", "--list") do
46
46
  groups = {}
47
- Tilt.mappings.each do |pattern,engine|
48
- key = engine.name.split('::').last.sub(/Template$/, '')
49
- (groups[key] ||= []) << pattern
47
+ Tilt.mappings.each do |pattern,engines|
48
+ engines.each do |engine|
49
+ key = engine.name.split('::').last.sub(/Template$/, '')
50
+ (groups[key] ||= []) << pattern
51
+ end
50
52
  end
51
53
  groups.sort { |(k1,v1),(k2,v2)| k1 <=> k2 }.each do |engine,files|
52
54
  printf "%-15s %s\n", engine, files.sort.join(', ')
@@ -1,5 +1,5 @@
1
1
  module Tilt
2
- VERSION = '1.3.3'
2
+ VERSION = '1.3.4'
3
3
 
4
4
  @preferred_mappings = Hash.new
5
5
  @template_mappings = Hash.new { |h, k| h[k] = [] }
@@ -142,6 +142,9 @@ module Tilt
142
142
  register ERBTemplate, 'erb', 'rhtml'
143
143
  register ErubisTemplate, 'erb', 'rhtml', 'erubis'
144
144
 
145
+ require 'tilt/etanni'
146
+ register EtanniTemplate, 'etn', 'etanni'
147
+
145
148
  require 'tilt/haml'
146
149
  register HamlTemplate, 'haml'
147
150
 
@@ -150,6 +153,9 @@ module Tilt
150
153
  register ScssTemplate, 'scss'
151
154
  register LessTemplate, 'less'
152
155
 
156
+ require 'tilt/csv'
157
+ register CSVTemplate, 'csv'
158
+
153
159
  require 'tilt/coffee'
154
160
  register CoffeeScriptTemplate, 'coffee'
155
161
 
@@ -173,6 +179,8 @@ module Tilt
173
179
  register KramdownTemplate, 'markdown', 'mkd', 'md'
174
180
  register BlueClothTemplate, 'markdown', 'mkd', 'md'
175
181
  register RDiscountTemplate, 'markdown', 'mkd', 'md'
182
+ register RedcarpetTemplate::Redcarpet1, 'markdown', 'mkd', 'md'
183
+ register RedcarpetTemplate::Redcarpet2, 'markdown', 'mkd', 'md'
176
184
  register RedcarpetTemplate, 'markdown', 'mkd', 'md'
177
185
 
178
186
  require 'tilt/textile'
@@ -187,4 +195,10 @@ module Tilt
187
195
 
188
196
  require 'tilt/yajl'
189
197
  register YajlTemplate, 'yajl'
198
+
199
+ require 'tilt/asciidoc'
200
+ register AsciidoctorTemplate, 'ad', 'adoc', 'asciidoc'
201
+
202
+ require 'tilt/plain'
203
+ register PlainTemplate, 'htmf'
190
204
  end
@@ -0,0 +1,34 @@
1
+ require 'tilt/template'
2
+
3
+ # AsciiDoc see: http://asciidoc.org/
4
+ module Tilt
5
+ # Asciidoctor implementation for AsciiDoc see:
6
+ # http://asciidoctor.github.com/
7
+ #
8
+ # Asciidoctor is an open source, pure-Ruby processor for
9
+ # converting AsciiDoc documents or strings into HTML 5,
10
+ # DocBook 4.5 and other formats.
11
+ class AsciidoctorTemplate < Template
12
+ self.default_mime_type = 'text/html'
13
+
14
+ def self.engine_initialized?
15
+ defined? ::Asciidoctor::Document
16
+ end
17
+
18
+ def initialize_engine
19
+ require_template_library 'asciidoctor'
20
+ end
21
+
22
+ def prepare
23
+ options[:header_footer] = false if options[:header_footer].nil?
24
+ end
25
+
26
+ def evaluate(scope, locals, &block)
27
+ @output ||= Asciidoctor.render(data, options, &block)
28
+ end
29
+
30
+ def allows_script?
31
+ false
32
+ end
33
+ end
34
+ end
@@ -45,6 +45,10 @@ module Tilt
45
45
  def evaluate(scope, locals, &block)
46
46
  @output ||= CoffeeScript.compile(data, options)
47
47
  end
48
+
49
+ def allows_script?
50
+ false
51
+ end
48
52
  end
49
53
  end
50
54
 
@@ -24,6 +24,10 @@ module Tilt
24
24
  @output ||= @engine.render
25
25
  end
26
26
 
27
+ def allows_script?
28
+ false
29
+ end
30
+
27
31
  private
28
32
  def sass_options
29
33
  options.merge(:filename => eval_file, :line => line, :syntax => :sass)
@@ -59,13 +63,17 @@ module Tilt
59
63
  if ::Less.const_defined? :Engine
60
64
  @engine = ::Less::Engine.new(data)
61
65
  else
62
- parser = ::Less::Parser.new(:filename => eval_file, :line => line)
66
+ parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
63
67
  @engine = parser.parse(data)
64
68
  end
65
69
  end
66
70
 
67
71
  def evaluate(scope, locals, &block)
68
- @output ||= @engine.to_css
72
+ @output ||= @engine.to_css(options)
73
+ end
74
+
75
+ def allows_script?
76
+ false
69
77
  end
70
78
  end
71
79
  end
@@ -0,0 +1,71 @@
1
+ require 'tilt/template'
2
+
3
+ module Tilt
4
+
5
+ # CSV Template implementation. See:
6
+ # http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html
7
+ #
8
+ # == Example
9
+ #
10
+ # # Example of csv template
11
+ # tpl = <<-EOS
12
+ # # header
13
+ # csv << ['NAME', 'ID']
14
+ #
15
+ # # data rows
16
+ # @people.each do |person|
17
+ # csv << [person[:name], person[:id]]
18
+ # end
19
+ # EOS
20
+ #
21
+ # @people = [
22
+ # {:name => "Joshua Peek", :id => 1},
23
+ # {:name => "Ryan Tomayko", :id => 2},
24
+ # {:name => "Simone Carletti", :id => 3}
25
+ # ]
26
+ #
27
+ # template = Tilt::CSVTemplate.new { tpl }
28
+ # template.render(self)
29
+ #
30
+ class CSVTemplate < Template
31
+ self.default_mime_type = 'text/csv'
32
+
33
+ def self.engine_initialized?
34
+ engine
35
+ end
36
+
37
+ def self.engine
38
+ if RUBY_VERSION >= '1.9.0' && defined? ::CSV
39
+ ::CSV
40
+ elsif defined? ::FasterCSV
41
+ ::FasterCSV
42
+ end
43
+ end
44
+
45
+ def initialize_engine
46
+ if RUBY_VERSION >= '1.9.0'
47
+ require_template_library 'csv'
48
+ else
49
+ require_template_library 'fastercsv'
50
+ end
51
+ end
52
+
53
+ def prepare
54
+ @code =<<-RUBY
55
+ #{self.class.engine}.generate do |csv|
56
+ #{data}
57
+ end
58
+ RUBY
59
+ end
60
+
61
+ def precompiled_template(locals)
62
+ @code
63
+ end
64
+
65
+ def precompiled(locals)
66
+ source, offset = super
67
+ [source, offset + 1]
68
+ end
69
+
70
+ end
71
+ end