tilt 1.3.3 → 1.4.0
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/CHANGELOG.md +40 -0
- data/COPYING +1 -1
- data/Gemfile +31 -1
- data/HACKING +16 -0
- data/README.md +26 -2
- data/Rakefile +25 -1
- data/TEMPLATES.md +13 -13
- data/bin/tilt +8 -6
- data/lib/tilt/asciidoc.rb +34 -0
- data/lib/tilt/coffee.rb +4 -0
- data/lib/tilt/css.rb +10 -2
- data/lib/tilt/csv.rb +71 -0
- data/lib/tilt/erb.rb +2 -2
- data/lib/tilt/etanni.rb +27 -0
- data/lib/tilt/liquid.rb +4 -0
- data/lib/tilt/markdown.rb +35 -11
- data/lib/tilt/nokogiri.rb +4 -4
- data/lib/tilt/plain.rb +20 -0
- data/lib/tilt/radius.rb +4 -0
- data/lib/tilt/rdoc.rb +20 -5
- data/lib/tilt/template.rb +96 -92
- data/lib/tilt/textile.rb +5 -0
- data/lib/tilt/wiki.rb +8 -0
- data/lib/tilt.rb +15 -1
- data/test/tilt_asciidoctor_test.rb +44 -0
- data/test/tilt_blueclothtemplate_test.rb +1 -1
- data/test/tilt_coffeescripttemplate_test.rb +64 -11
- data/test/tilt_creoletemplate_test.rb +1 -1
- data/test/tilt_csv_test.rb +69 -0
- data/test/tilt_erbtemplate_test.rb +5 -0
- data/test/tilt_erubistemplate_test.rb +1 -1
- data/test/tilt_etannitemplate_test.rb +173 -0
- data/test/tilt_fallback_test.rb +6 -6
- data/test/tilt_hamltemplate_test.rb +1 -1
- data/test/tilt_kramdown_test.rb +1 -1
- data/test/tilt_lesstemplate_test.less +1 -0
- data/test/tilt_lesstemplate_test.rb +19 -3
- data/test/tilt_liquidtemplate_test.rb +1 -1
- data/test/tilt_markaby_test.rb +1 -1
- data/test/tilt_markdown_test.rb +16 -5
- data/test/tilt_marukutemplate_test.rb +1 -1
- data/test/tilt_radiustemplate_test.rb +1 -1
- data/test/tilt_rdiscounttemplate_test.rb +1 -1
- data/test/tilt_rdoctemplate_test.rb +10 -3
- data/test/tilt_redcarpettemplate_test.rb +15 -3
- data/test/tilt_redclothtemplate_test.rb +13 -1
- data/test/tilt_sasstemplate_test.rb +1 -1
- data/test/tilt_stringtemplate_test.rb +1 -1
- data/test/tilt_template_test.rb +122 -0
- data/test/tilt_wikiclothtemplate_test.rb +1 -1
- data/test/tilt_yajltemplate_test.rb +13 -4
- data/tilt.gemspec +28 -17
- metadata +204 -75
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
## master
|
|
2
|
+
|
|
3
|
+
## 1.4.0 (2013-05-01)
|
|
4
|
+
|
|
5
|
+
* Better encoding support
|
|
6
|
+
|
|
7
|
+
## 1.3.7 (2013-04-09)
|
|
8
|
+
|
|
9
|
+
* Erubis: Check for the correct constant (#183, mattwildig)
|
|
10
|
+
* Don't fail when BasicObject is defined in 1.8 (#182, technobrat, judofyr)
|
|
11
|
+
|
|
12
|
+
## 1.3.6 (2013-03-17)
|
|
13
|
+
|
|
14
|
+
* Accept Hash that implements #path as options (#180, lawso017)
|
|
15
|
+
* Changed extension for CsvTemplate from '.csv' to '.rcsv' (#177, alexgb)
|
|
16
|
+
|
|
17
|
+
## 1.3.5 (2013-03-06)
|
|
18
|
+
|
|
19
|
+
* Fixed extension for PlainTemplate (judofyr)
|
|
20
|
+
* Improved local variables regexp (#174, razorinc)
|
|
21
|
+
* Added CHANGELOG.md
|
|
22
|
+
|
|
23
|
+
## 1.3.4 (2013-02-28)
|
|
24
|
+
|
|
25
|
+
* Support RDoc 4.0 (#168, judofyr)
|
|
26
|
+
* Add mention of Org-Mode support (#165, aslakknutsen)
|
|
27
|
+
* Add AsciiDoctorTemplate (#163, #164, aslakknutsen)
|
|
28
|
+
* Add PlainTextTemplate (nathanaeljones)
|
|
29
|
+
* Restrict locals to valid variable names (#158, thinkerbot)
|
|
30
|
+
* ERB: Improve trim mode support (#156, ssimeonov)
|
|
31
|
+
* Add CSVTemplate (#153, alexgb)
|
|
32
|
+
* Remove special case for 1.9.1 (#147, guilleiguaran)
|
|
33
|
+
* Add allows\_script? method to Template (#143, bhollis)
|
|
34
|
+
* Default to using Redcarpet2 (#139, DAddYE)
|
|
35
|
+
* Allow File/Tempfile as filenames (#134, jamesotron)
|
|
36
|
+
* Add EtanniTemplate (#131, manveru)
|
|
37
|
+
* Support RDoc 3.10 (#112, timfel)
|
|
38
|
+
* Always compile templates; remove old source evaluator (rtomayko)
|
|
39
|
+
* Less: Options are now being passed to the parser (#106, cowboyd)
|
|
40
|
+
|
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
|
-
|
|
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 [](http://travis-ci.org/rtomayko/tilt) [](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 .rcsv 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,13 +187,34 @@ 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
|
|
|
191
194
|
When a file extension has a preferred template class, Tilt will *always* use
|
|
192
195
|
that class, even if it raises an exception.
|
|
193
196
|
|
|
197
|
+
Encodings
|
|
198
|
+
---------
|
|
199
|
+
|
|
200
|
+
Tilt needs to know the encoding of the template in order to work properly:
|
|
201
|
+
|
|
202
|
+
Tilt will use `Encoding.default_external` as the encoding when reading external
|
|
203
|
+
files. If you're mostly working with one encoding (e.g. UTF-8) we *highly*
|
|
204
|
+
recommend setting this option. When providing a custom reader block (`Tilt.new
|
|
205
|
+
{ custom_string }`) you'll have ensure the string is properly encoded yourself.
|
|
206
|
+
|
|
207
|
+
Most of the template engines in Tilt also allows you to override the encoding
|
|
208
|
+
using the `:default_encoding`-option:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5')
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Ultimately it's up to the template engine how to handle the encoding: It might
|
|
215
|
+
respect `:default_encoding`, it might always assume it's UTF-8 (like
|
|
216
|
+
CoffeScript), or it can do its own encoding detection.
|
|
217
|
+
|
|
194
218
|
Template Compilation
|
|
195
219
|
--------------------
|
|
196
220
|
|
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
|
|
data/TEMPLATES.md
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
251
|
-
* [Haml Tutorial](http://haml
|
|
252
|
-
* [Haml Reference](http://haml
|
|
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 '
|
|
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
|
|
411
|
-
`require 'rdoc/markup/to_html'` at load time
|
|
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
|
|
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
|
-
|
|
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 --
|
|
30
|
+
$ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}"
|
|
31
31
|
Answer: 42
|
|
32
|
-
$ echo "Answer: <%= 2 + n %>" | tilt -Dn=40
|
|
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,
|
|
48
|
-
|
|
49
|
-
|
|
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(', ')
|
|
@@ -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
|
data/lib/tilt/coffee.rb
CHANGED
data/lib/tilt/css.rb
CHANGED
|
@@ -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
|
data/lib/tilt/csv.rb
ADDED
|
@@ -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
|
data/lib/tilt/erb.rb
CHANGED
|
@@ -24,7 +24,7 @@ module Tilt
|
|
|
24
24
|
|
|
25
25
|
def prepare
|
|
26
26
|
@outvar = options[:outvar] || self.class.default_output_variable
|
|
27
|
-
options[:trim] = '<>' if options[:trim].nil? || options[:trim] == true
|
|
27
|
+
options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true)
|
|
28
28
|
@engine = ::ERB.new(data, options[:safe], options[:trim], @outvar)
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -74,7 +74,7 @@ module Tilt
|
|
|
74
74
|
# within <%= %> blocks will be automatically html escaped.
|
|
75
75
|
class ErubisTemplate < ERBTemplate
|
|
76
76
|
def self.engine_initialized?
|
|
77
|
-
defined? ::Erubis
|
|
77
|
+
defined? ::Erubis::Eruby
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def initialize_engine
|
data/lib/tilt/etanni.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'tilt/template'
|
|
2
|
+
|
|
3
|
+
module Tilt
|
|
4
|
+
class EtanniTemplate < Template
|
|
5
|
+
def prepare
|
|
6
|
+
separator = data.hash.abs
|
|
7
|
+
chomp = "<<#{separator}.chomp!"
|
|
8
|
+
start = "\n_out_ << #{chomp}\n"
|
|
9
|
+
stop = "\n#{separator}\n"
|
|
10
|
+
replacement = "#{stop}\\1#{start}"
|
|
11
|
+
|
|
12
|
+
temp = data.strip
|
|
13
|
+
temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement)
|
|
14
|
+
|
|
15
|
+
@code = "_out_ = [<<#{separator}.chomp!]\n#{temp}#{stop}_out_.join"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def precompiled_template(locals)
|
|
19
|
+
@code
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def precompiled(locals)
|
|
23
|
+
source, offset = super
|
|
24
|
+
[source, offset + 1]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/tilt/liquid.rb
CHANGED
data/lib/tilt/markdown.rb
CHANGED
|
@@ -37,6 +37,10 @@ module Tilt
|
|
|
37
37
|
def evaluate(scope, locals, &block)
|
|
38
38
|
@output ||= @engine.to_html
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
def allows_script?
|
|
42
|
+
false
|
|
43
|
+
end
|
|
40
44
|
end
|
|
41
45
|
|
|
42
46
|
# Upskirt Markdown implementation. See:
|
|
@@ -53,7 +57,7 @@ module Tilt
|
|
|
53
57
|
end
|
|
54
58
|
|
|
55
59
|
def prepare
|
|
56
|
-
klass = [
|
|
60
|
+
klass = [Redcarpet2, Redcarpet1].detect { |e| e.engine_initialized? }
|
|
57
61
|
@engine = klass.new(file, line, options) { data }
|
|
58
62
|
end
|
|
59
63
|
|
|
@@ -61,6 +65,10 @@ module Tilt
|
|
|
61
65
|
@engine.evaluate(scope, locals, &block)
|
|
62
66
|
end
|
|
63
67
|
|
|
68
|
+
def allows_script?
|
|
69
|
+
false
|
|
70
|
+
end
|
|
71
|
+
|
|
64
72
|
# Compatibility mode for Redcarpet 1.x
|
|
65
73
|
class Redcarpet1 < RDiscountTemplate
|
|
66
74
|
self.default_mime_type = 'text/html'
|
|
@@ -80,22 +88,22 @@ module Tilt
|
|
|
80
88
|
self.default_mime_type = 'text/html'
|
|
81
89
|
|
|
82
90
|
def self.engine_initialized?
|
|
83
|
-
defined? ::Redcarpet::Render
|
|
91
|
+
defined? ::Redcarpet::Render and defined? ::Redcarpet::Markdown
|
|
84
92
|
end
|
|
85
93
|
|
|
86
94
|
def generate_renderer
|
|
87
|
-
renderer = options.delete(:renderer) || Redcarpet::Render::HTML
|
|
95
|
+
renderer = options.delete(:renderer) || ::Redcarpet::Render::HTML
|
|
88
96
|
return renderer unless options.delete(:smartypants)
|
|
89
|
-
return renderer if renderer <= Redcarpet::Render::SmartyPants
|
|
97
|
+
return renderer if renderer.is_a?(Class) && renderer <= ::Redcarpet::Render::SmartyPants
|
|
90
98
|
|
|
91
|
-
if renderer == Redcarpet::Render::XHTML
|
|
92
|
-
Redcarpet::Render::SmartyHTML.new(:xhtml => true)
|
|
93
|
-
elsif renderer == Redcarpet::Render::HTML
|
|
94
|
-
Redcarpet::Render::SmartyHTML
|
|
99
|
+
if renderer == ::Redcarpet::Render::XHTML
|
|
100
|
+
::Redcarpet::Render::SmartyHTML.new(:xhtml => true)
|
|
101
|
+
elsif renderer == ::Redcarpet::Render::HTML
|
|
102
|
+
::Redcarpet::Render::SmartyHTML
|
|
95
103
|
elsif renderer.is_a? Class
|
|
96
|
-
Class.new(renderer) { include Redcarpet::Render::SmartyPants }
|
|
104
|
+
Class.new(renderer) { include ::Redcarpet::Render::SmartyPants }
|
|
97
105
|
else
|
|
98
|
-
renderer.extend Redcarpet::Render::SmartyPants
|
|
106
|
+
renderer.extend ::Redcarpet::Render::SmartyPants
|
|
99
107
|
end
|
|
100
108
|
end
|
|
101
109
|
|
|
@@ -109,13 +117,17 @@ module Tilt
|
|
|
109
117
|
# only raise an exception if someone is trying to enable :escape_html
|
|
110
118
|
options.delete(:escape_html) unless options[:escape_html]
|
|
111
119
|
|
|
112
|
-
@engine = Redcarpet::Markdown.new(generate_renderer, options)
|
|
120
|
+
@engine = ::Redcarpet::Markdown.new(generate_renderer, options)
|
|
113
121
|
@output = nil
|
|
114
122
|
end
|
|
115
123
|
|
|
116
124
|
def evaluate(scope, locals, &block)
|
|
117
125
|
@output ||= @engine.render(data)
|
|
118
126
|
end
|
|
127
|
+
|
|
128
|
+
def allows_script?
|
|
129
|
+
false
|
|
130
|
+
end
|
|
119
131
|
end
|
|
120
132
|
end
|
|
121
133
|
|
|
@@ -140,6 +152,10 @@ module Tilt
|
|
|
140
152
|
def evaluate(scope, locals, &block)
|
|
141
153
|
@output ||= @engine.to_html
|
|
142
154
|
end
|
|
155
|
+
|
|
156
|
+
def allows_script?
|
|
157
|
+
false
|
|
158
|
+
end
|
|
143
159
|
end
|
|
144
160
|
|
|
145
161
|
# Maruku markdown implementation. See:
|
|
@@ -161,6 +177,10 @@ module Tilt
|
|
|
161
177
|
def evaluate(scope, locals, &block)
|
|
162
178
|
@output ||= @engine.to_html
|
|
163
179
|
end
|
|
180
|
+
|
|
181
|
+
def allows_script?
|
|
182
|
+
false
|
|
183
|
+
end
|
|
164
184
|
end
|
|
165
185
|
|
|
166
186
|
# Kramdown Markdown implementation. See:
|
|
@@ -185,6 +205,10 @@ module Tilt
|
|
|
185
205
|
def evaluate(scope, locals, &block)
|
|
186
206
|
@output ||= @engine.to_html
|
|
187
207
|
end
|
|
208
|
+
|
|
209
|
+
def allows_script?
|
|
210
|
+
false
|
|
211
|
+
end
|
|
188
212
|
end
|
|
189
213
|
end
|
|
190
214
|
|
data/lib/tilt/nokogiri.rb
CHANGED
|
@@ -4,6 +4,7 @@ module Tilt
|
|
|
4
4
|
# Nokogiri template implementation. See:
|
|
5
5
|
# http://nokogiri.org/
|
|
6
6
|
class NokogiriTemplate < Template
|
|
7
|
+
DOCUMENT_HEADER = /^<\?xml version=\"1\.0\"\?>\n?/
|
|
7
8
|
self.default_mime_type = 'text/xml'
|
|
8
9
|
|
|
9
10
|
def self.engine_initialized?
|
|
@@ -16,11 +17,10 @@ module Tilt
|
|
|
16
17
|
|
|
17
18
|
def prepare; end
|
|
18
19
|
|
|
19
|
-
def evaluate(scope, locals
|
|
20
|
-
block &&= proc { yield.gsub(/^<\?xml version=\"1\.0\"\?>\n?/, "") }
|
|
21
|
-
|
|
20
|
+
def evaluate(scope, locals)
|
|
22
21
|
if data.respond_to?(:to_str)
|
|
23
|
-
|
|
22
|
+
wrapper = proc { yield.sub(DOCUMENT_HEADER, "") } if block_given?
|
|
23
|
+
super(scope, locals, &wrapper)
|
|
24
24
|
else
|
|
25
25
|
::Nokogiri::XML::Builder.new.tap(&data).to_xml
|
|
26
26
|
end
|