tilt 2.0.8 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/tilt/commonmarker.rb +68 -1
- data/lib/tilt/csv.rb +1 -1
- data/lib/tilt/erb.rb +7 -1
- data/lib/tilt/haml.rb +2 -2
- data/lib/tilt/pandoc.rb +23 -15
- data/lib/tilt/redcarpet.rb +5 -2
- data/lib/tilt/rst-pandoc.rb +12 -7
- data/lib/tilt/sass.rb +40 -3
- data/lib/tilt/template.rb +18 -12
- data/lib/tilt.rb +2 -1
- metadata +8 -110
- data/CHANGELOG.md +0 -127
- data/Gemfile +0 -65
- data/HACKING +0 -16
- data/README.md +0 -233
- data/Rakefile +0 -106
- data/docs/TEMPLATES.md +0 -555
- data/docs/common.css +0 -14
- data/man/index.txt +0 -2
- data/man/tilt.1.ronn +0 -59
- data/test/markaby/locals.mab +0 -1
- data/test/markaby/markaby.mab +0 -1
- data/test/markaby/markaby_other_static.mab +0 -1
- data/test/markaby/render_twice.mab +0 -1
- data/test/markaby/scope.mab +0 -1
- data/test/markaby/yielding.mab +0 -2
- data/test/mytemplate.rb +0 -2
- data/test/test_helper.rb +0 -64
- data/test/tilt_asciidoctor_test.rb +0 -50
- data/test/tilt_babeltemplate.rb +0 -33
- data/test/tilt_blueclothtemplate_test.rb +0 -33
- data/test/tilt_buildertemplate_test.rb +0 -72
- data/test/tilt_cache_test.rb +0 -43
- data/test/tilt_coffeescripttemplate_test.rb +0 -141
- data/test/tilt_commonmarkertemplate_test.rb +0 -20
- data/test/tilt_compilesite_test.rb +0 -51
- data/test/tilt_creoletemplate_test.rb +0 -24
- data/test/tilt_csv_test.rb +0 -77
- data/test/tilt_erbtemplate_test.rb +0 -239
- data/test/tilt_erubistemplate_test.rb +0 -151
- data/test/tilt_erubitemplate_test.rb +0 -158
- data/test/tilt_etannitemplate_test.rb +0 -174
- data/test/tilt_hamltemplate_test.rb +0 -166
- data/test/tilt_kramdown_test.rb +0 -20
- data/test/tilt_lesstemplate_test.less +0 -1
- data/test/tilt_lesstemplate_test.rb +0 -42
- data/test/tilt_liquidtemplate_test.rb +0 -87
- data/test/tilt_livescripttemplate_test.rb +0 -37
- data/test/tilt_mapping_test.rb +0 -232
- data/test/tilt_markaby_test.rb +0 -88
- data/test/tilt_markdown_test.rb +0 -186
- data/test/tilt_marukutemplate_test.rb +0 -36
- data/test/tilt_metadata_test.rb +0 -42
- data/test/tilt_nokogiritemplate_test.rb +0 -87
- data/test/tilt_pandoctemplate_test.rb +0 -67
- data/test/tilt_prawntemplate.prawn +0 -1
- data/test/tilt_prawntemplate_test.rb +0 -75
- data/test/tilt_radiustemplate_test.rb +0 -75
- data/test/tilt_rdiscounttemplate_test.rb +0 -43
- data/test/tilt_rdoctemplate_test.rb +0 -29
- data/test/tilt_redcarpettemplate_test.rb +0 -54
- data/test/tilt_redclothtemplate_test.rb +0 -36
- data/test/tilt_rstpandoctemplate_test.rb +0 -32
- data/test/tilt_sasstemplate_test.rb +0 -41
- data/test/tilt_sigil_test.rb +0 -41
- data/test/tilt_stringtemplate_test.rb +0 -171
- data/test/tilt_template_test.rb +0 -314
- data/test/tilt_test.rb +0 -60
- data/test/tilt_typescript_test.rb +0 -38
- data/test/tilt_wikiclothtemplate_test.rb +0 -32
- data/test/tilt_yajltemplate_test.rb +0 -101
- data/tilt.gemspec +0 -130
data/test/test_helper.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
|
-
|
3
|
-
require 'bundler'
|
4
|
-
Bundler.setup
|
5
|
-
|
6
|
-
require 'minitest/autorun'
|
7
|
-
require 'minitest/mock'
|
8
|
-
|
9
|
-
# Contest adds +teardown+, +test+ and +context+ as class methods, and the
|
10
|
-
# instance methods +setup+ and +teardown+ now iterate on the corresponding
|
11
|
-
# blocks. Note that all setup and teardown blocks must be defined with the
|
12
|
-
# block syntax. Adding setup or teardown instance methods defeats the purpose
|
13
|
-
# of this library.
|
14
|
-
class Minitest::Test
|
15
|
-
def self.setup(&block)
|
16
|
-
define_method :setup do
|
17
|
-
super(&block)
|
18
|
-
instance_eval(&block)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.teardown(&block)
|
23
|
-
define_method :teardown do
|
24
|
-
instance_eval(&block)
|
25
|
-
super(&block)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.context(name, &block)
|
30
|
-
subclass = Class.new(self)
|
31
|
-
remove_tests(subclass)
|
32
|
-
subclass.class_eval(&block) if block_given?
|
33
|
-
const_set(context_name(name), subclass)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.test(name, &block)
|
37
|
-
define_method(test_name(name), &block)
|
38
|
-
end
|
39
|
-
|
40
|
-
class << self
|
41
|
-
alias_method :should, :test
|
42
|
-
alias_method :describe, :context
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def self.context_name(name)
|
48
|
-
"Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.test_name(name)
|
52
|
-
"test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.sanitize_name(name)
|
56
|
-
name.gsub(/\W+/, ' ').strip
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.remove_tests(subclass)
|
60
|
-
subclass.public_instance_methods.grep(/^test_/).each do |meth|
|
61
|
-
subclass.send(:undef_method, meth.to_sym)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/asciidoc'
|
6
|
-
|
7
|
-
class AsciidoctorTemplateTest < Minitest::Test
|
8
|
-
HTML5_OUTPUT = "<div class=\"sect1\"><h2 id=\"_hello_world\">Hello World!</h2><div class=\"sectionbody\"></div></div>"
|
9
|
-
DOCBOOK45_OUTPUT = "<section id=\"_hello_world\"><title>Hello World!</title></section>"
|
10
|
-
DOCBOOK5_OUTPUT = "<section xml:id=\"_hello_world\"><title>Hello World!</title></section>"
|
11
|
-
|
12
|
-
def strip_space(str)
|
13
|
-
str.gsub(/>\s+</, '><').strip
|
14
|
-
end
|
15
|
-
|
16
|
-
test "registered for '.ad' files" do
|
17
|
-
assert_equal Tilt::AsciidoctorTemplate, Tilt['ad']
|
18
|
-
end
|
19
|
-
|
20
|
-
test "registered for '.adoc' files" do
|
21
|
-
assert_equal Tilt::AsciidoctorTemplate, Tilt['adoc']
|
22
|
-
end
|
23
|
-
|
24
|
-
test "registered for '.asciidoc' files" do
|
25
|
-
assert_equal Tilt::AsciidoctorTemplate, Tilt['asciidoc']
|
26
|
-
end
|
27
|
-
|
28
|
-
test "preparing and evaluating html5 templates on #render" do
|
29
|
-
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'html5'}) { |t| "== Hello World!" }
|
30
|
-
assert_equal HTML5_OUTPUT, strip_space(template.render)
|
31
|
-
end
|
32
|
-
|
33
|
-
test "preparing and evaluating docbook 4.5 templates on #render" do
|
34
|
-
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'docbook45'}) { |t| "== Hello World!" }
|
35
|
-
assert_equal DOCBOOK45_OUTPUT, strip_space(template.render)
|
36
|
-
end
|
37
|
-
|
38
|
-
test "preparing and evaluating docbook 5 templates on #render" do
|
39
|
-
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'docbook5'}) { |t| "== Hello World!" }
|
40
|
-
assert_equal DOCBOOK5_OUTPUT, strip_space(template.render)
|
41
|
-
end
|
42
|
-
|
43
|
-
test "can be rendered more than once" do
|
44
|
-
template = Tilt::AsciidoctorTemplate.new(:attributes => {"backend" => 'html5'}) { |t| "== Hello World!" }
|
45
|
-
3.times { assert_equal HTML5_OUTPUT, strip_space(template.render) }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
rescue LoadError
|
49
|
-
warn "Tilt::AsciidoctorTemplate (disabled)"
|
50
|
-
end
|
data/test/tilt_babeltemplate.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/babel'
|
6
|
-
|
7
|
-
class BabelTemplateTest < Minitest::Test
|
8
|
-
test "registered for '.es6' files" do
|
9
|
-
assert_equal Tilt::BabelTemplate, Tilt['es6']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "registered for '.babel' files" do
|
13
|
-
assert_equal Tilt::BabelTemplate, Tilt['babel']
|
14
|
-
end
|
15
|
-
|
16
|
-
test "registered for '.jsx' files" do
|
17
|
-
assert_equal Tilt::BabelTemplate, Tilt['jsx']
|
18
|
-
end
|
19
|
-
|
20
|
-
test "basic ES6 features" do
|
21
|
-
template = Tilt::BabelTemplate.new { "square = (x) => x * x" }
|
22
|
-
assert_match "function", template.render
|
23
|
-
end
|
24
|
-
|
25
|
-
test "JSX support" do
|
26
|
-
template = Tilt::BabelTemplate.new { "<Awesome ness={true} />" }
|
27
|
-
assert_match "React.createElement", template.render
|
28
|
-
end
|
29
|
-
end
|
30
|
-
rescue LoadError => boom
|
31
|
-
warn "Tilt::BabelTemplate (disabled)"
|
32
|
-
end
|
33
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/bluecloth'
|
6
|
-
|
7
|
-
class BlueClothTemplateTest < Minitest::Test
|
8
|
-
test "preparing and evaluating templates on #render" do
|
9
|
-
template = Tilt::BlueClothTemplate.new { |t| "# Hello World!" }
|
10
|
-
assert_equal "<h1>Hello World!</h1>", template.render
|
11
|
-
end
|
12
|
-
|
13
|
-
test "can be rendered more than once" do
|
14
|
-
template = Tilt::BlueClothTemplate.new { |t| "# Hello World!" }
|
15
|
-
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
16
|
-
end
|
17
|
-
|
18
|
-
test "smartypants when :smart is set" do
|
19
|
-
template = Tilt::BlueClothTemplate.new(:smartypants => true) { |t|
|
20
|
-
"OKAY -- 'Smarty Pants'" }
|
21
|
-
assert_equal "<p>OKAY — ‘Smarty Pants’</p>",
|
22
|
-
template.render
|
23
|
-
end
|
24
|
-
|
25
|
-
test "stripping HTML when :filter_html is set" do
|
26
|
-
template = Tilt::BlueClothTemplate.new(:escape_html => true) { |t|
|
27
|
-
"HELLO <blink>WORLD</blink>" }
|
28
|
-
assert_equal "<p>HELLO <blink>WORLD</blink></p>", template.render
|
29
|
-
end
|
30
|
-
end
|
31
|
-
rescue LoadError
|
32
|
-
warn "Tilt::BlueClothTemplate (disabled)"
|
33
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/builder'
|
6
|
-
class BuilderTemplateTest < Minitest::Test
|
7
|
-
test "registered for '.builder' files" do
|
8
|
-
assert_equal Tilt::BuilderTemplate, Tilt['test.builder']
|
9
|
-
assert_equal Tilt::BuilderTemplate, Tilt['test.xml.builder']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "preparing and evaluating the template on #render" do
|
13
|
-
template = Tilt::BuilderTemplate.new { |t| "xml.em 'Hello World!'" }
|
14
|
-
assert_equal "<em>Hello World!</em>\n", template.render
|
15
|
-
end
|
16
|
-
|
17
|
-
test "can be rendered more than once" do
|
18
|
-
template = Tilt::BuilderTemplate.new { |t| "xml.em 'Hello World!'" }
|
19
|
-
3.times { assert_equal "<em>Hello World!</em>\n", template.render }
|
20
|
-
end
|
21
|
-
|
22
|
-
test "passing locals" do
|
23
|
-
template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + name + '!')" }
|
24
|
-
assert_equal "<em>Hey Joe!</em>\n", template.render(Object.new, :name => 'Joe')
|
25
|
-
end
|
26
|
-
|
27
|
-
test "evaluating in an object scope" do
|
28
|
-
template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + @name + '!')" }
|
29
|
-
scope = Object.new
|
30
|
-
scope.instance_variable_set :@name, 'Joe'
|
31
|
-
assert_equal "<em>Hey Joe!</em>\n", template.render(scope)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "passing a block for yield" do
|
35
|
-
template = Tilt::BuilderTemplate.new { "xml.em('Hey ' + yield + '!')" }
|
36
|
-
3.times { assert_equal "<em>Hey Joe!</em>\n", template.render { 'Joe' }}
|
37
|
-
end
|
38
|
-
|
39
|
-
test "block style templates" do
|
40
|
-
template =
|
41
|
-
Tilt::BuilderTemplate.new do |t|
|
42
|
-
lambda { |xml| xml.em('Hey Joe!') }
|
43
|
-
end
|
44
|
-
assert_equal "<em>Hey Joe!</em>\n", template.render
|
45
|
-
end
|
46
|
-
|
47
|
-
test "options can be overridden" do
|
48
|
-
template = Tilt::BuilderTemplate.new(:indent => 0) { "xml.div { xml.em('Hey') }" }
|
49
|
-
assert_equal "<div><em>Hey</em></div>", template.render
|
50
|
-
end
|
51
|
-
|
52
|
-
test "can re-use locals for multiple calls" do
|
53
|
-
locals = { :name => "world" }
|
54
|
-
template = Tilt::BuilderTemplate.new(:indent => 0) { "xml.em name" }
|
55
|
-
3.times do
|
56
|
-
assert_equal "<em>world</em>", template.render(self, locals)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
test "allows nesting raw XML" do
|
61
|
-
subtemplate = Tilt::BuilderTemplate.new { "xml.em 'Hello World!'" }
|
62
|
-
template = Tilt::BuilderTemplate.new { "xml.strong { xml << yield }" }
|
63
|
-
3.times do
|
64
|
-
options = { :xml => Builder::XmlMarkup.new }
|
65
|
-
assert_equal "<strong>\n<em>Hello World!</em>\n</strong>\n",
|
66
|
-
template.render(options) { subtemplate.render(options) }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
rescue LoadError
|
71
|
-
warn "Tilt::BuilderTemplate (disabled)"
|
72
|
-
end
|
data/test/tilt_cache_test.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
class TiltCacheTest < Minitest::Test
|
5
|
-
setup { @cache = Tilt::Cache.new }
|
6
|
-
|
7
|
-
test "caching with single simple argument to #fetch" do
|
8
|
-
template = nil
|
9
|
-
result = @cache.fetch('hello') { template = Tilt::StringTemplate.new {''} }
|
10
|
-
assert_same template, result
|
11
|
-
result = @cache.fetch('hello') { fail 'should be cached' }
|
12
|
-
assert_same template, result
|
13
|
-
end
|
14
|
-
|
15
|
-
test "caching with multiple complex arguments to #fetch" do
|
16
|
-
template = nil
|
17
|
-
result = @cache.fetch('hello', {:foo => 'bar', :baz => 'bizzle'}) { template = Tilt::StringTemplate.new {''} }
|
18
|
-
assert_same template, result
|
19
|
-
result = @cache.fetch('hello', {:foo => 'bar', :baz => 'bizzle'}) { fail 'should be cached' }
|
20
|
-
assert_same template, result
|
21
|
-
end
|
22
|
-
|
23
|
-
test "caching nil" do
|
24
|
-
called = false
|
25
|
-
result = @cache.fetch("blah") {called = true; nil}
|
26
|
-
assert_equal true, called
|
27
|
-
assert_nil result
|
28
|
-
called = false
|
29
|
-
result = @cache.fetch("blah") {called = true; :blah}
|
30
|
-
assert_equal false, called
|
31
|
-
assert_nil result
|
32
|
-
end
|
33
|
-
|
34
|
-
test "clearing the cache with #clear" do
|
35
|
-
template, other = nil
|
36
|
-
result = @cache.fetch('hello') { template = Tilt::StringTemplate.new {''} }
|
37
|
-
assert_same template, result
|
38
|
-
|
39
|
-
@cache.clear
|
40
|
-
result = @cache.fetch('hello') { other = Tilt::StringTemplate.new {''} }
|
41
|
-
assert_same other, result
|
42
|
-
end
|
43
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/coffee'
|
6
|
-
|
7
|
-
module CoffeeScriptTests
|
8
|
-
def self.included(mod)
|
9
|
-
mod.class_eval do
|
10
|
-
test "bare is disabled by default" do
|
11
|
-
assert_equal false, @renderer.default_bare
|
12
|
-
end
|
13
|
-
|
14
|
-
test "compiles and evaluates the template on #render" do
|
15
|
-
template = @renderer.new { |t| @code_without_variables }
|
16
|
-
assert_match "puts('Hello, World!');", template.render
|
17
|
-
end
|
18
|
-
|
19
|
-
test "can be rendered more than once" do
|
20
|
-
template = @renderer.new { |t| @code_without_variables }
|
21
|
-
3.times { assert_match "puts('Hello, World!');", template.render }
|
22
|
-
end
|
23
|
-
|
24
|
-
test "disabling coffee-script wrapper" do
|
25
|
-
template = @renderer.new { @code_with_variables }
|
26
|
-
assert_match "(function() {", template.render
|
27
|
-
assert_match "puts(\"Hello, \" + name);\n", template.render
|
28
|
-
|
29
|
-
template = @renderer.new(:bare => true) { @code_with_variables }
|
30
|
-
refute_match "(function() {", template.render
|
31
|
-
assert_equal "var name;\n\nname = \"Josh\";\n\nputs(\"Hello, \" + name);\n", template.render
|
32
|
-
|
33
|
-
template = @renderer.new(:no_wrap => true) { @code_with_variables}
|
34
|
-
refute_match "(function() {", template.render
|
35
|
-
assert_equal "var name;\n\nname = \"Josh\";\n\nputs(\"Hello, \" + name);\n", template.render
|
36
|
-
end
|
37
|
-
|
38
|
-
context "wrapper globally enabled" do
|
39
|
-
setup do
|
40
|
-
@bare = @renderer.default_bare
|
41
|
-
@renderer.default_bare = false
|
42
|
-
end
|
43
|
-
|
44
|
-
teardown do
|
45
|
-
@renderer.default_bare = @bare
|
46
|
-
end
|
47
|
-
|
48
|
-
test "no options" do
|
49
|
-
template = @renderer.new { |t| @code_with_variables }
|
50
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
51
|
-
assert_match "(function() {", template.render
|
52
|
-
end
|
53
|
-
|
54
|
-
test "overridden by :bare" do
|
55
|
-
template = @renderer.new(:bare => true) { |t| @code_with_variables }
|
56
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
57
|
-
refute_match "(function() {", template.render
|
58
|
-
end
|
59
|
-
|
60
|
-
test "overridden by :no_wrap" do
|
61
|
-
template = @renderer.new(:no_wrap => true) { |t| @code_with_variables }
|
62
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
63
|
-
refute_match "(function() {", template.render
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "wrapper globally disabled" do
|
68
|
-
setup do
|
69
|
-
@bare = @renderer.default_bare
|
70
|
-
@renderer.default_bare = true
|
71
|
-
end
|
72
|
-
|
73
|
-
teardown do
|
74
|
-
@renderer.default_bare = @bare
|
75
|
-
end
|
76
|
-
|
77
|
-
test "no options" do
|
78
|
-
template = @renderer.new { |t| @code_with_variables }
|
79
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
80
|
-
refute_match "(function() {", template.render
|
81
|
-
end
|
82
|
-
|
83
|
-
test "overridden by :bare" do
|
84
|
-
template = @renderer.new(:bare => false) { |t| @code_with_variables }
|
85
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
86
|
-
assert_match "(function() {", template.render
|
87
|
-
end
|
88
|
-
|
89
|
-
test "overridden by :no_wrap" do
|
90
|
-
template = @renderer.new(:no_wrap => false) { |t| @code_with_variables }
|
91
|
-
assert_match "puts(\"Hello, \" + name);", template.render
|
92
|
-
assert_match "(function() {", template.render
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class CoffeeScriptTemplateTest < Minitest::Test
|
100
|
-
setup do
|
101
|
-
@code_without_variables = "puts 'Hello, World!'\n"
|
102
|
-
@code_with_variables = 'name = "Josh"; puts "Hello, #{name}"'
|
103
|
-
@renderer = Tilt::CoffeeScriptTemplate
|
104
|
-
end
|
105
|
-
|
106
|
-
include CoffeeScriptTests
|
107
|
-
|
108
|
-
test "is registered for '.coffee' files" do
|
109
|
-
assert_equal @renderer, Tilt['test.coffee']
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
class LiterateCoffeeScriptTemplateTest < Minitest::Test
|
114
|
-
setup do
|
115
|
-
@code_without_variables = <<EOLIT
|
116
|
-
This is some comment.
|
117
|
-
|
118
|
-
puts 'Hello, World!'
|
119
|
-
|
120
|
-
This is a comment too.
|
121
|
-
EOLIT
|
122
|
-
@code_with_variables = <<EOLIT
|
123
|
-
This is some comment.
|
124
|
-
|
125
|
-
name = "Josh"; puts "Hello, \#{name}"
|
126
|
-
|
127
|
-
This is a comment too.
|
128
|
-
EOLIT
|
129
|
-
@renderer = Tilt::CoffeeScriptLiterateTemplate
|
130
|
-
end
|
131
|
-
|
132
|
-
include CoffeeScriptTests
|
133
|
-
|
134
|
-
test "is registered for '.litcoffee' files" do
|
135
|
-
assert_equal @renderer, Tilt['test.litcoffee']
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
rescue LoadError
|
140
|
-
warn "Tilt::CoffeeScriptTemplate (disabled)"
|
141
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/commonmarker'
|
6
|
-
|
7
|
-
class CommonMarkerTemplateTest < Minitest::Test
|
8
|
-
test "preparing and evaluating templates on #render" do
|
9
|
-
template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }
|
10
|
-
assert_equal "<h1>Hello World!</h1>\n", template.render
|
11
|
-
end
|
12
|
-
|
13
|
-
test "can be rendered more than once" do
|
14
|
-
template = Tilt::CommonMarkerTemplate.new { |t| "# Hello World!" }
|
15
|
-
3.times { assert_equal "<h1>Hello World!</h1>\n", template.render }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
warn "Tilt::CommonMarkerTemplate (disabled)"
|
20
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
require 'thread'
|
4
|
-
|
5
|
-
class CompileSiteTest < Minitest::Test
|
6
|
-
def setup
|
7
|
-
GC.start
|
8
|
-
end
|
9
|
-
|
10
|
-
class CompilingTemplate < Tilt::Template
|
11
|
-
def prepare
|
12
|
-
end
|
13
|
-
|
14
|
-
def precompiled_template(locals)
|
15
|
-
@data.inspect
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Scope
|
20
|
-
end
|
21
|
-
|
22
|
-
test "compiling template source to a method" do
|
23
|
-
template = CompilingTemplate.new { |t| "Hello World!" }
|
24
|
-
template.render(Scope.new)
|
25
|
-
method = template.send(:compiled_method, [])
|
26
|
-
assert_kind_of UnboundMethod, method
|
27
|
-
end
|
28
|
-
|
29
|
-
# This test attempts to surface issues with compiling templates from
|
30
|
-
# multiple threads.
|
31
|
-
test "using compiled templates from multiple threads" do
|
32
|
-
template = CompilingTemplate.new { 'template' }
|
33
|
-
main_thread = Thread.current
|
34
|
-
10.times do |i|
|
35
|
-
threads =
|
36
|
-
(1..50).map do |j|
|
37
|
-
Thread.new {
|
38
|
-
begin
|
39
|
-
locals = { "local#{i}" => 'value' }
|
40
|
-
res = template.render(self, locals)
|
41
|
-
thread_id = Thread.current.object_id
|
42
|
-
res = template.render(self, "local#{thread_id.abs.to_s}" => 'value')
|
43
|
-
rescue => boom
|
44
|
-
main_thread.raise(boom)
|
45
|
-
end
|
46
|
-
}
|
47
|
-
end
|
48
|
-
threads.each { |t| t.join }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/creole'
|
6
|
-
|
7
|
-
class CreoleTemplateTest < Minitest::Test
|
8
|
-
test "is registered for '.creole' files" do
|
9
|
-
assert_equal Tilt::CreoleTemplate, Tilt['test.creole']
|
10
|
-
end
|
11
|
-
|
12
|
-
test "compiles and evaluates the template on #render" do
|
13
|
-
template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
|
14
|
-
assert_equal "<h1>Hello World!</h1>", template.render
|
15
|
-
end
|
16
|
-
|
17
|
-
test "can be rendered more than once" do
|
18
|
-
template = Tilt::CreoleTemplate.new { |t| "= Hello World!" }
|
19
|
-
3.times { assert_equal "<h1>Hello World!</h1>", template.render }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
rescue LoadError
|
23
|
-
warn "Tilt::CreoleTemplate (disabled)"
|
24
|
-
end
|
data/test/tilt_csv_test.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'tilt'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'tilt/csv'
|
6
|
-
|
7
|
-
class CSVTemplateTest < Minitest::Test
|
8
|
-
|
9
|
-
test "registered for '.rcsv' files" do
|
10
|
-
assert_equal Tilt::CSVTemplate, Tilt['rcsv']
|
11
|
-
end
|
12
|
-
|
13
|
-
test "compiles and evaluates the template on #render" do
|
14
|
-
template = Tilt::CSVTemplate.new { "csv << ['hello', 'world']" }
|
15
|
-
assert_equal "hello,world\n", template.render
|
16
|
-
end
|
17
|
-
|
18
|
-
test "can be rendered more than once" do
|
19
|
-
template = Tilt::CSVTemplate.new { "csv << [1,2,3]" }
|
20
|
-
3.times { assert_equal "1,2,3\n", template.render }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "can pass locals" do
|
24
|
-
template = Tilt::CSVTemplate.new { 'csv << [1, name]' }
|
25
|
-
assert_equal "1,Joe\n", template.render(Object.new, :name => 'Joe')
|
26
|
-
end
|
27
|
-
|
28
|
-
test "evaluating in an object scope" do
|
29
|
-
template = Tilt::CSVTemplate.new { 'csv << [1, @name]' }
|
30
|
-
scope = Object.new
|
31
|
-
scope.instance_variable_set :@name, 'Joe'
|
32
|
-
assert_equal "1,Joe\n", template.render(scope)
|
33
|
-
end
|
34
|
-
|
35
|
-
test "backtrace file and line reporting" do
|
36
|
-
data = File.read(__FILE__).split("\n__END__\n").last
|
37
|
-
template = Tilt::CSVTemplate.new('test.csv') { data }
|
38
|
-
begin
|
39
|
-
template.render
|
40
|
-
fail 'should have raised an exception'
|
41
|
-
rescue => boom
|
42
|
-
assert_kind_of NameError, boom
|
43
|
-
line = boom.backtrace.grep(/^test\.csv:/).first
|
44
|
-
assert line, "Backtrace didn't contain test.csv"
|
45
|
-
_file, line, _meth = line.split(":")
|
46
|
-
assert_equal '4', line
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
test "passing options to engine" do
|
51
|
-
template = Tilt::CSVTemplate.new(:col_sep => '|') { 'csv << [1,2,3]' }
|
52
|
-
assert_equal "1|2|3\n", template.render
|
53
|
-
end
|
54
|
-
|
55
|
-
test "outvar option" do
|
56
|
-
outvar = '@_output'
|
57
|
-
scope = Object.new
|
58
|
-
template = Tilt::CSVTemplate.new(:outvar => outvar) { 'csv << [1,2,3]' }
|
59
|
-
output = template.render(scope)
|
60
|
-
assert_equal output, scope.instance_variable_get(outvar.to_sym)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
rescue LoadError
|
65
|
-
warn "Tilt::CSVTemplate (disabled) please install 'fastercsv' if using ruby 1.8.x"
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
__END__
|
70
|
-
# header
|
71
|
-
csv << ['Type', 'Age']
|
72
|
-
|
73
|
-
raise NameError
|
74
|
-
|
75
|
-
# rows
|
76
|
-
csv << ['Frog', 2]
|
77
|
-
csv << ['Cat', 5]
|