tilt 1.4.1 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +33 -26
- data/README.md +21 -48
- data/Rakefile +21 -30
- data/{TEMPLATES.md → docs/TEMPLATES.md} +10 -4
- data/docs/common.css +14 -0
- data/lib/tilt.rb +85 -154
- data/lib/tilt/asciidoc.rb +1 -8
- data/lib/tilt/bluecloth.rb +24 -0
- data/lib/tilt/builder.rb +1 -8
- data/lib/tilt/coffee.rb +1 -8
- data/lib/tilt/creole.rb +25 -0
- data/lib/tilt/csv.rb +7 -13
- data/lib/tilt/erb.rb +2 -55
- data/lib/tilt/erubis.rb +43 -0
- data/lib/tilt/haml.rb +1 -8
- data/lib/tilt/kramdown.rb +33 -0
- data/lib/tilt/less.rb +38 -0
- data/lib/tilt/liquid.rb +1 -8
- data/lib/tilt/mapping.rb +247 -0
- data/lib/tilt/markaby.rb +1 -8
- data/lib/tilt/maruku.rb +22 -0
- data/lib/tilt/nokogiri.rb +1 -8
- data/lib/tilt/radius.rb +1 -8
- data/lib/tilt/rdiscount.rb +39 -0
- data/lib/tilt/rdoc.rb +3 -10
- data/lib/tilt/redcarpet.rb +104 -0
- data/lib/tilt/{textile.rb → redcloth.rb} +1 -8
- data/lib/tilt/sass.rb +41 -0
- data/lib/tilt/template.rb +85 -92
- data/lib/tilt/wikicloth.rb +22 -0
- data/lib/tilt/yajl.rb +1 -8
- data/test/{contest.rb → test_helper.rb} +5 -11
- data/test/tilt_asciidoctor_test.rb +6 -6
- data/test/tilt_blueclothtemplate_test.rb +3 -15
- data/test/tilt_buildertemplate_test.rb +3 -3
- data/test/tilt_cache_test.rb +2 -2
- data/test/tilt_coffeescripttemplate_test.rb +8 -18
- data/test/tilt_compilesite_test.rb +2 -2
- data/test/tilt_creoletemplate_test.rb +3 -7
- data/test/tilt_csv_test.rb +5 -9
- data/test/tilt_erbtemplate_test.rb +7 -7
- data/test/tilt_erubistemplate_test.rb +7 -7
- data/test/tilt_etannitemplate_test.rb +4 -3
- data/test/tilt_hamltemplate_test.rb +4 -4
- data/test/tilt_kramdown_test.rb +5 -27
- data/test/tilt_lesstemplate_test.rb +3 -3
- data/test/tilt_liquidtemplate_test.rb +3 -3
- data/test/tilt_mapping.rb +215 -0
- data/test/tilt_markaby_test.rb +4 -4
- data/test/tilt_markdown_test.rb +13 -14
- data/test/tilt_marukutemplate_test.rb +6 -18
- data/test/tilt_metadata_test.rb +42 -0
- data/test/tilt_nokogiritemplate_test.rb +3 -3
- data/test/tilt_radiustemplate_test.rb +3 -3
- data/test/tilt_rdiscounttemplate_test.rb +6 -18
- data/test/tilt_rdoctemplate_test.rb +3 -5
- data/test/tilt_redcarpettemplate_test.rb +11 -23
- data/test/tilt_redclothtemplate_test.rb +3 -3
- data/test/tilt_sasstemplate_test.rb +4 -4
- data/test/tilt_stringtemplate_test.rb +4 -3
- data/test/tilt_template_test.rb +35 -49
- data/test/tilt_test.rb +10 -15
- data/test/tilt_wikiclothtemplate_test.rb +3 -3
- data/test/tilt_yajltemplate_test.rb +3 -3
- data/tilt.gemspec +19 -32
- metadata +26 -386
- data/lib/tilt/css.rb +0 -80
- data/lib/tilt/markdown.rb +0 -214
- data/lib/tilt/wiki.rb +0 -58
- data/test/tilt_fallback_test.rb +0 -122
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'tilt/template'
|
2
|
+
require 'wikicloth'
|
3
|
+
|
4
|
+
module Tilt
|
5
|
+
# WikiCloth implementation. See:
|
6
|
+
# http://redcloth.org/
|
7
|
+
class WikiClothTemplate < Template
|
8
|
+
def prepare
|
9
|
+
@parser = options.delete(:parser) || WikiCloth::Parser
|
10
|
+
@engine = @parser.new options.merge(:data => data)
|
11
|
+
@output = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def evaluate(scope, locals, &block)
|
15
|
+
@output ||= @engine.to_html
|
16
|
+
end
|
17
|
+
|
18
|
+
def allows_script?
|
19
|
+
false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/tilt/yajl.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'tilt/template'
|
2
|
+
require 'yajl'
|
2
3
|
|
3
4
|
module Tilt
|
4
5
|
|
@@ -42,14 +43,6 @@ module Tilt
|
|
42
43
|
|
43
44
|
self.default_mime_type = 'application/json'
|
44
45
|
|
45
|
-
def self.engine_initialized?
|
46
|
-
defined? ::Yajl
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize_engine
|
50
|
-
require_template_library 'yajl'
|
51
|
-
end
|
52
|
-
|
53
46
|
def prepare
|
54
47
|
end
|
55
48
|
|
@@ -1,21 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
2
3
|
|
3
|
-
|
4
|
-
|
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
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/mock'
|
12
6
|
|
13
7
|
# Contest adds +teardown+, +test+ and +context+ as class methods, and the
|
14
8
|
# instance methods +setup+ and +teardown+ now iterate on the corresponding
|
15
9
|
# blocks. Note that all setup and teardown blocks must be defined with the
|
16
10
|
# block syntax. Adding setup or teardown instance methods defeats the purpose
|
17
11
|
# of this library.
|
18
|
-
class Test
|
12
|
+
class Minitest::Test
|
19
13
|
def self.setup(&block)
|
20
14
|
define_method :setup do
|
21
15
|
super(&block)
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require '
|
5
|
+
require 'tilt/asciidoc'
|
6
6
|
|
7
|
-
class AsciidoctorTemplateTest < Test
|
7
|
+
class AsciidoctorTemplateTest < Minitest::Test
|
8
8
|
HTML5_OUTPUT = "<div class=\"sect1\"><h2 id=\"_hello_world\">Hello World!</h2><div class=\"sectionbody\"></div></div>"
|
9
9
|
DOCBOOK_OUTPUT = "<section id=\"_hello_world\"><title>Hello World!</title></section>"
|
10
10
|
|
@@ -13,15 +13,15 @@ begin
|
|
13
13
|
end
|
14
14
|
|
15
15
|
test "registered for '.ad' files" do
|
16
|
-
|
16
|
+
assert_equal Tilt::AsciidoctorTemplate, Tilt['ad']
|
17
17
|
end
|
18
18
|
|
19
19
|
test "registered for '.adoc' files" do
|
20
|
-
|
20
|
+
assert_equal Tilt::AsciidoctorTemplate, Tilt['adoc']
|
21
21
|
end
|
22
22
|
|
23
23
|
test "registered for '.asciidoc' files" do
|
24
|
-
|
24
|
+
assert_equal Tilt::AsciidoctorTemplate, Tilt['asciidoc']
|
25
25
|
end
|
26
26
|
|
27
27
|
test "preparing and evaluating html5 templates on #render" do
|
@@ -1,22 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'bluecloth'
|
6
|
-
|
7
|
-
class BlueClothTemplateTest < Test::Unit::TestCase
|
8
|
-
test "registered for '.md' files" do
|
9
|
-
assert Tilt.mappings['md'].include?(Tilt::BlueClothTemplate)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "registered for '.mkd' files" do
|
13
|
-
assert Tilt.mappings['mkd'].include?(Tilt::BlueClothTemplate)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "registered for '.markdown' files" do
|
17
|
-
assert Tilt.mappings['markdown'].include?(Tilt::BlueClothTemplate)
|
18
|
-
end
|
5
|
+
require 'tilt/bluecloth'
|
19
6
|
|
7
|
+
class BlueClothTemplateTest < Minitest::Test
|
20
8
|
test "preparing and evaluating templates on #render" do
|
21
9
|
template = Tilt::BlueClothTemplate.new { |t| "# Hello World!" }
|
22
10
|
assert_equal "<h1>Hello World!</h1>", template.render
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'builder'
|
6
|
-
class BuilderTemplateTest < Test
|
5
|
+
require 'tilt/builder'
|
6
|
+
class BuilderTemplateTest < Minitest::Test
|
7
7
|
test "registered for '.builder' files" do
|
8
8
|
assert_equal Tilt::BuilderTemplate, Tilt['test.builder']
|
9
9
|
assert_equal Tilt::BuilderTemplate, Tilt['test.xml.builder']
|
data/test/tilt_cache_test.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require '
|
5
|
+
require 'tilt/coffee'
|
6
6
|
|
7
|
-
class CoffeeScriptTemplateTest < Test
|
8
|
-
|
9
|
-
unless method_defined?(:assert_not_match)
|
10
|
-
# assert_not_match is missing on 1.8.7, which uses assert_no_match
|
11
|
-
def assert_not_match(a, b)
|
12
|
-
unless a.kind_of?(Regexp)
|
13
|
-
a = Regexp.new(Regexp.escape(a))
|
14
|
-
end
|
15
|
-
assert_no_match(a,b)
|
16
|
-
end
|
17
|
-
end
|
7
|
+
class CoffeeScriptTemplateTest < Minitest::Test
|
18
8
|
|
19
9
|
test "is registered for '.coffee' files" do
|
20
10
|
assert_equal Tilt::CoffeeScriptTemplate, Tilt['test.coffee']
|
@@ -42,11 +32,11 @@ begin
|
|
42
32
|
assert_match "puts(\"Hello \" + name);\n", template.render
|
43
33
|
|
44
34
|
template = Tilt::CoffeeScriptTemplate.new(:bare => true) { str }
|
45
|
-
|
35
|
+
refute_match "(function() {", template.render
|
46
36
|
assert_equal "var name;\n\nname = \"Josh\";\n\nputs(\"Hello \" + name);\n", template.render
|
47
37
|
|
48
38
|
template2 = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { str}
|
49
|
-
|
39
|
+
refute_match "(function() {", template.render
|
50
40
|
assert_equal "var name;\n\nname = \"Josh\";\n\nputs(\"Hello \" + name);\n", template.render
|
51
41
|
end
|
52
42
|
|
@@ -69,13 +59,13 @@ begin
|
|
69
59
|
test "overridden by :bare" do
|
70
60
|
template = Tilt::CoffeeScriptTemplate.new(:bare => true) { |t| 'name = "Josh"; puts "Hello, #{name}"' }
|
71
61
|
assert_match "puts(\"Hello, \" + name);", template.render
|
72
|
-
|
62
|
+
refute_match "(function() {", template.render
|
73
63
|
end
|
74
64
|
|
75
65
|
test "overridden by :no_wrap" do
|
76
66
|
template = Tilt::CoffeeScriptTemplate.new(:no_wrap => true) { |t| 'name = "Josh"; puts "Hello, #{name}"' }
|
77
67
|
assert_match "puts(\"Hello, \" + name);", template.render
|
78
|
-
|
68
|
+
refute_match "(function() {", template.render
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
@@ -92,7 +82,7 @@ begin
|
|
92
82
|
test "no options" do
|
93
83
|
template = Tilt::CoffeeScriptTemplate.new { |t| 'name = "Josh"; puts "Hello, #{name}"' }
|
94
84
|
assert_match "puts(\"Hello, \" + name);", template.render
|
95
|
-
|
85
|
+
refute_match "(function() {", template.render
|
96
86
|
end
|
97
87
|
|
98
88
|
test "overridden by :bare" do
|
@@ -1,18 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'creole'
|
5
|
+
require 'tilt/creole'
|
6
6
|
|
7
|
-
class CreoleTemplateTest < Test
|
7
|
+
class CreoleTemplateTest < Minitest::Test
|
8
8
|
test "is registered for '.creole' files" do
|
9
9
|
assert_equal Tilt::CreoleTemplate, Tilt['test.creole']
|
10
10
|
end
|
11
11
|
|
12
|
-
test "registered for '.wiki' files" do
|
13
|
-
assert Tilt.mappings['wiki'].include?(Tilt::CreoleTemplate)
|
14
|
-
end
|
15
|
-
|
16
12
|
test "compiles and evaluates the template on #render" do
|
17
13
|
template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
|
18
14
|
assert_equal "<h1>Hello World!</h1>", template.render
|
data/test/tilt_csv_test.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
|
6
|
-
require 'csv'
|
7
|
-
else
|
8
|
-
require 'fastercsv'
|
9
|
-
end
|
5
|
+
require 'tilt/csv'
|
10
6
|
|
11
|
-
class CSVTemplateTest < Test
|
7
|
+
class CSVTemplateTest < Minitest::Test
|
12
8
|
|
13
9
|
test "registered for '.rcsv' files" do
|
14
|
-
|
10
|
+
assert_equal Tilt::CSVTemplate, Tilt['rcsv']
|
15
11
|
end
|
16
12
|
|
17
13
|
test "compiles and evaluates the template on #render" do
|
@@ -66,4 +62,4 @@ raise NameError
|
|
66
62
|
|
67
63
|
# rows
|
68
64
|
csv << ['Frog', 2]
|
69
|
-
csv << ['Cat', 5]
|
65
|
+
csv << ['Cat', 5]
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require '
|
2
|
+
require 'test_helper'
|
3
3
|
require 'tilt'
|
4
|
-
require 'erb'
|
4
|
+
require 'tilt/erb'
|
5
5
|
require 'tempfile'
|
6
6
|
|
7
|
-
class ERBTemplateTest < Test
|
7
|
+
class ERBTemplateTest < Minitest::Test
|
8
8
|
test "registered for '.erb' files" do
|
9
|
-
|
9
|
+
assert_includes Tilt.lazy_map['erb'], ['Tilt::ERBTemplate', 'tilt/erb']
|
10
10
|
end
|
11
11
|
|
12
12
|
test "registered for '.rhtml' files" do
|
13
|
-
|
13
|
+
assert_includes Tilt.lazy_map['rhtml'], ['Tilt::ERBTemplate', 'tilt/erb']
|
14
14
|
end
|
15
15
|
|
16
16
|
test "loading and evaluating templates on #render" do
|
@@ -45,7 +45,7 @@ class ERBTemplateTest < Test::Unit::TestCase
|
|
45
45
|
template = Tilt::ERBTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
|
46
46
|
scope = MockOutputVariableScope.new
|
47
47
|
template.render(scope)
|
48
|
-
|
48
|
+
refute_nil scope.exposed_buffer
|
49
49
|
assert_equal scope.exposed_buffer, 'hey'
|
50
50
|
ensure
|
51
51
|
Tilt::ERBTemplate.default_output_variable = '_erbout'
|
@@ -118,7 +118,7 @@ class ERBTemplateTest < Test::Unit::TestCase
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
class CompiledERBTemplateTest < Test
|
121
|
+
class CompiledERBTemplateTest < Minitest::Test
|
122
122
|
def teardown
|
123
123
|
GC.start
|
124
124
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'erubis'
|
6
|
-
class ErubisTemplateTest < Test
|
5
|
+
require 'tilt/erubis'
|
6
|
+
class ErubisTemplateTest < Minitest::Test
|
7
7
|
test "registered for '.erubis' files" do
|
8
8
|
assert_equal Tilt::ErubisTemplate, Tilt['test.erubis']
|
9
9
|
assert_equal Tilt::ErubisTemplate, Tilt['test.html.erubis']
|
@@ -11,9 +11,9 @@ begin
|
|
11
11
|
|
12
12
|
test "registered above ERB" do
|
13
13
|
%w[erb rhtml].each do |ext|
|
14
|
-
|
15
|
-
erubis_idx =
|
16
|
-
erb_idx =
|
14
|
+
lazy = Tilt.lazy_map[ext]
|
15
|
+
erubis_idx = lazy.index { |klass, file| klass == 'Tilt::ErubisTemplate' }
|
16
|
+
erb_idx = lazy.index { |klass, file| klass == 'Tilt::ERBTemplate' }
|
17
17
|
assert erubis_idx < erb_idx,
|
18
18
|
"#{erubis_idx} should be lower than #{erb_idx}"
|
19
19
|
end
|
@@ -51,7 +51,7 @@ begin
|
|
51
51
|
template = Tilt::ErubisTemplate.new { '<% self.exposed_buffer = @_out_buf %>hey' }
|
52
52
|
scope = MockOutputVariableScope.new
|
53
53
|
template.render(scope)
|
54
|
-
|
54
|
+
refute_nil scope.exposed_buffer
|
55
55
|
assert_equal scope.exposed_buffer, 'hey'
|
56
56
|
ensure
|
57
57
|
Tilt::ErubisTemplate.default_output_variable = '_erbout'
|
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
|
+
require 'tilt/etanni'
|
3
4
|
|
4
|
-
class EtanniTemplateTest < Test
|
5
|
+
class EtanniTemplateTest < Minitest::Test
|
5
6
|
test "registered for '.etn' files" do
|
6
7
|
assert_equal Tilt::EtanniTemplate, Tilt['test.etn']
|
7
8
|
end
|
@@ -77,7 +78,7 @@ class EtanniTemplateTest < Test::Unit::TestCase
|
|
77
78
|
end
|
78
79
|
|
79
80
|
|
80
|
-
class CompiledEtanniTemplateTest < Test
|
81
|
+
class CompiledEtanniTemplateTest < Minitest::Test
|
81
82
|
def teardown
|
82
83
|
GC.start
|
83
84
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
5
|
class ::MockError < NameError
|
6
6
|
end
|
7
7
|
|
8
|
-
require 'haml'
|
8
|
+
require 'tilt/haml'
|
9
9
|
|
10
|
-
class HamlTemplateTest < Test
|
10
|
+
class HamlTemplateTest < Minitest::Test
|
11
11
|
test "registered for '.haml' files" do
|
12
12
|
assert_equal Tilt::HamlTemplate, Tilt['test.haml']
|
13
13
|
end
|
@@ -71,7 +71,7 @@ begin
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
class CompiledHamlTemplateTest < Test
|
74
|
+
class CompiledHamlTemplateTest < Minitest::Test
|
75
75
|
class Scope
|
76
76
|
end
|
77
77
|
|
data/test/tilt_kramdown_test.rb
CHANGED
@@ -1,40 +1,18 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'tilt'
|
3
3
|
|
4
4
|
begin
|
5
|
-
require 'kramdown'
|
6
|
-
|
7
|
-
class MarukuTemplateTest < Test::Unit::TestCase
|
8
|
-
test "registered for '.md' files" do
|
9
|
-
assert Tilt.mappings['md'].include?(Tilt::KramdownTemplate)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "registered for '.mkd' files" do
|
13
|
-
assert Tilt.mappings['mkd'].include?(Tilt::KramdownTemplate)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "registered for '.markdown' files" do
|
17
|
-
assert Tilt.mappings['markdown'].include?(Tilt::KramdownTemplate)
|
18
|
-
end
|
19
|
-
|
20
|
-
test "registered above MarukuTemplate" do
|
21
|
-
%w[md mkd markdown].each do |ext|
|
22
|
-
mappings = Tilt.mappings[ext]
|
23
|
-
kram_idx = mappings.index(Tilt::KramdownTemplate)
|
24
|
-
maru_idx = mappings.index(Tilt::MarukuTemplate)
|
25
|
-
assert kram_idx < maru_idx,
|
26
|
-
"#{kram_idx} should be lower than #{maru_idx}"
|
27
|
-
end
|
28
|
-
end
|
5
|
+
require 'tilt/kramdown'
|
29
6
|
|
7
|
+
class KramdownTemplateTest < Minitest::Test
|
30
8
|
test "preparing and evaluating templates on #render" do
|
31
9
|
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
32
|
-
assert_equal
|
10
|
+
assert_equal '<h1 id="hello-world">Hello World!</h1>', template.render.strip
|
33
11
|
end
|
34
12
|
|
35
13
|
test "can be rendered more than once" do
|
36
14
|
template = Tilt::KramdownTemplate.new { |t| "# Hello World!" }
|
37
|
-
3.times { assert_equal
|
15
|
+
3.times { assert_equal '<h1 id="hello-world">Hello World!</h1>', template.render.strip }
|
38
16
|
end
|
39
17
|
end
|
40
18
|
rescue LoadError => boom
|