tilt 2.0.1 → 2.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/Gemfile +35 -15
- data/README.md +57 -37
- data/Rakefile +23 -13
- data/bin/tilt +16 -6
- data/docs/TEMPLATES.md +1 -0
- data/lib/tilt.rb +25 -3
- data/lib/tilt/babel.rb +15 -0
- data/lib/tilt/coffee.rb +11 -0
- data/lib/tilt/csv.rb +6 -6
- data/lib/tilt/haml.rb +3 -2
- data/lib/tilt/kramdown.rb +0 -8
- data/lib/tilt/less.rb +0 -8
- data/lib/tilt/liquid.rb +1 -1
- data/lib/tilt/plain.rb +0 -4
- data/lib/tilt/prawn.rb +43 -0
- data/lib/tilt/redcarpet.rb +5 -26
- data/lib/tilt/template.rb +11 -2
- data/man/index.txt +2 -0
- data/man/tilt.1.ronn +59 -0
- data/test/tilt_asciidoctor_test.rb +10 -4
- data/test/tilt_babeltemplate.rb +33 -0
- data/test/tilt_cache_test.rb +11 -0
- data/test/tilt_coffeescripttemplate_test.rb +115 -78
- data/test/tilt_csv_test.rb +12 -0
- data/test/tilt_hamltemplate_test.rb +22 -0
- data/test/tilt_markdown_test.rb +5 -2
- data/test/tilt_prawntemplate.prawn +1 -0
- data/test/tilt_prawntemplate_test.rb +75 -0
- data/test/tilt_redcarpettemplate_test.rb +0 -5
- data/test/tilt_template_test.rb +6 -14
- data/test/tilt_wikiclothtemplate_test.rb +2 -2
- data/tilt.gemspec +9 -2
- metadata +11 -3
data/test/tilt_csv_test.rb
CHANGED
@@ -47,6 +47,18 @@ begin
|
|
47
47
|
end
|
48
48
|
end
|
49
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
|
50
62
|
end
|
51
63
|
|
52
64
|
rescue LoadError => boom
|
@@ -27,6 +27,17 @@ begin
|
|
27
27
|
assert_equal "<p>Hey Joe!</p>\n", template.render(Object.new, :name => 'Joe')
|
28
28
|
end
|
29
29
|
|
30
|
+
test 'evaluating in default/nil scope' do
|
31
|
+
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
32
|
+
assert_equal "<p>Hey unknown!</p>\n", template.render
|
33
|
+
assert_equal "<p>Hey unknown!</p>\n", template.render(nil)
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'evaluating in invalid, frozen scope' do
|
37
|
+
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
38
|
+
assert_raises(ArgumentError) { template.render(Object.new.freeze) }
|
39
|
+
end
|
40
|
+
|
30
41
|
test "evaluating in an object scope" do
|
31
42
|
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
32
43
|
scope = Object.new
|
@@ -87,6 +98,17 @@ begin
|
|
87
98
|
assert_equal "<p>Hey Joe!</p>\n", template.render(Scope.new, :name => 'Joe')
|
88
99
|
end
|
89
100
|
|
101
|
+
test 'evaluating in default/nil scope' do
|
102
|
+
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
103
|
+
assert_equal "<p>Hey unknown!</p>\n", template.render
|
104
|
+
assert_equal "<p>Hey unknown!</p>\n", template.render(nil)
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'evaluating in invalid, frozen scope' do
|
108
|
+
template = Tilt::HamlTemplate.new { |t| '%p Hey unknown!' }
|
109
|
+
assert_raises(ArgumentError) { template.render(Object.new.freeze) }
|
110
|
+
end
|
111
|
+
|
90
112
|
test "evaluating in an object scope" do
|
91
113
|
template = Tilt::HamlTemplate.new { "%p= 'Hey ' + @name + '!'" }
|
92
114
|
scope = Scope.new
|
data/test/tilt_markdown_test.rb
CHANGED
@@ -91,8 +91,6 @@ begin
|
|
91
91
|
class MarkdownRedcarpetTest < Minitest::Test
|
92
92
|
include MarkdownTests
|
93
93
|
template Tilt::RedcarpetTemplate
|
94
|
-
# Doesn't support escaping
|
95
|
-
undef test_escape_html_true
|
96
94
|
|
97
95
|
def test_smarty_pants_true
|
98
96
|
# Various versions of Redcarpet support various versions of Smart pants.
|
@@ -100,6 +98,11 @@ begin
|
|
100
98
|
assert_match /<p>Hello “World(''|”) – This is — a test …<\/p>/, html
|
101
99
|
end
|
102
100
|
|
101
|
+
def test_renderer_options
|
102
|
+
html = nrender "Hello [World](http://example.com)", :smartypants => true, :no_links => true
|
103
|
+
assert_equal "<p>Hello [World](http://example.com)</p>", html
|
104
|
+
end
|
105
|
+
|
103
106
|
def test_fenced_code_blocks_with_lang
|
104
107
|
code = <<-COD.gsub(/^\s+/,"")
|
105
108
|
```ruby
|
@@ -0,0 +1 @@
|
|
1
|
+
pdf.text "Hello Template!"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tilt'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'tilt/prawn'
|
6
|
+
require 'pdf-reader'
|
7
|
+
|
8
|
+
class PdfOutput
|
9
|
+
def initialize(pdf_raw)
|
10
|
+
@reader = PDF::Reader.new(StringIO.new(pdf_raw))
|
11
|
+
end
|
12
|
+
|
13
|
+
def text
|
14
|
+
@reader.pages.map(&:text).join
|
15
|
+
end
|
16
|
+
|
17
|
+
def page_attributes(page_num=1)
|
18
|
+
@reader.page(page_num).attributes
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class PrawnTemplateTest < Minitest::Test
|
23
|
+
test "is registered for '.prawn' files" do
|
24
|
+
assert_equal Tilt::PrawnTemplate, Tilt['test.prawn']
|
25
|
+
end
|
26
|
+
|
27
|
+
test "compiles and evaluates the template on #render" do
|
28
|
+
template = Tilt::PrawnTemplate.new { |t| "pdf.text \"Hello PDF!\"" }
|
29
|
+
output = PdfOutput.new(template.render)
|
30
|
+
assert_includes output.text, "Hello PDF!"
|
31
|
+
end
|
32
|
+
|
33
|
+
test "can be rendered more than once" do
|
34
|
+
template = Tilt::PrawnTemplate.new { |t| "pdf.text \"Hello PDF!\"" }
|
35
|
+
3.times do
|
36
|
+
output = PdfOutput.new(template.render)
|
37
|
+
assert_includes output.text, "Hello PDF!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
test "loads the template from a file and renders it correctly" do
|
42
|
+
template = Tilt::PrawnTemplate.new("#{Dir.pwd}/test/tilt_prawntemplate.prawn")
|
43
|
+
output = PdfOutput.new(template.render)
|
44
|
+
assert_includes output.text, "Hello Template!"
|
45
|
+
end
|
46
|
+
|
47
|
+
test "loads the template from a file and can be rendered more than once" do
|
48
|
+
template = Tilt::PrawnTemplate.new("#{Dir.pwd}/test/tilt_prawntemplate.prawn")
|
49
|
+
3.times do
|
50
|
+
output = PdfOutput.new(template.render)
|
51
|
+
assert_includes output.text, "Hello Template!"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test "have the correct default page size & layout settings - (default: A4 portrait)" do
|
56
|
+
# NOTE! Dear North Americans,
|
57
|
+
# Please follow the ISO 216 international standard format (A4) that dominates everywhere else in the world
|
58
|
+
template = Tilt::PrawnTemplate.new { |t| "pdf.text \"Hello A4 portrait!\"" }
|
59
|
+
output = PdfOutput.new(template.render)
|
60
|
+
assert_includes output.text, "Hello A4 portrait!"
|
61
|
+
assert_equal [0, 0, 595.28, 841.89], output.page_attributes(1)[:MediaBox]
|
62
|
+
end
|
63
|
+
|
64
|
+
test "allows page size & layout settings - A3 landscape" do
|
65
|
+
template = Tilt::PrawnTemplate.new( :page_size => 'A3', :page_layout => :landscape) { |t| "pdf.text \"Hello A3 landscape!\"" }
|
66
|
+
output = PdfOutput.new(template.render)
|
67
|
+
assert_includes output.text, "Hello A3 landscape!"
|
68
|
+
assert_equal [0, 0, 1190.55, 841.89], output.page_attributes(1)[:MediaBox]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
rescue LoadError => boom
|
74
|
+
warn "Tilt::PrawnTemplate (disabled)"
|
75
|
+
end
|
@@ -25,11 +25,6 @@ begin
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
test "redcarpet2 is our default choice" do
|
29
|
-
template = Tilt::RedcarpetTemplate.new {}
|
30
|
-
assert_equal Tilt::RedcarpetTemplate::Redcarpet2, template.prepare.class
|
31
|
-
end
|
32
|
-
|
33
28
|
test "preparing and evaluating templates on #render" do
|
34
29
|
template = Tilt::RedcarpetTemplate.new { |t| "# Hello World!" }
|
35
30
|
assert_equal "<h1>Hello World!</h1>\n", template.render
|
data/test/tilt_template_test.rb
CHANGED
@@ -75,20 +75,6 @@ class TiltTemplateTest < Minitest::Test
|
|
75
75
|
MockTemplate.new { |template| "Hello World!" }
|
76
76
|
end
|
77
77
|
|
78
|
-
class InitializingMockTemplate < Tilt::Template
|
79
|
-
@@initialized_count = 0
|
80
|
-
def self.initialized_count
|
81
|
-
@@initialized_count
|
82
|
-
end
|
83
|
-
|
84
|
-
def initialize_engine
|
85
|
-
@@initialized_count += 1
|
86
|
-
end
|
87
|
-
|
88
|
-
def prepare
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
78
|
class PreparingMockTemplate < Tilt::Template
|
93
79
|
def prepare
|
94
80
|
raise "data must be set" if data.nil?
|
@@ -122,6 +108,12 @@ class TiltTemplateTest < Minitest::Test
|
|
122
108
|
assert inst.prepared?
|
123
109
|
end
|
124
110
|
|
111
|
+
test 'prepares and evaluates the template on #render with nil arg' do
|
112
|
+
inst = SimpleMockTemplate.new { |t| "Hello World!" }
|
113
|
+
assert_equal '<em>Hello World!</em>', inst.render(nil)
|
114
|
+
assert inst.prepared?
|
115
|
+
end
|
116
|
+
|
125
117
|
class SourceGeneratingMockTemplate < PreparingMockTemplate
|
126
118
|
def precompiled_template(locals)
|
127
119
|
"foo = [] ; foo << %Q{#{data}} ; foo.join"
|
@@ -19,12 +19,12 @@ begin
|
|
19
19
|
|
20
20
|
test "compiles and evaluates the template on #render" do
|
21
21
|
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
|
22
|
-
assert_match /<h1>.*Hello World!.*<\/h1
|
22
|
+
assert_match /<h1>.*Hello World!.*<\/h1>/m, template.render
|
23
23
|
end
|
24
24
|
|
25
25
|
test "can be rendered more than once" do
|
26
26
|
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
|
27
|
-
3.times { assert_match /<h1>.*Hello World!.*<\/h1
|
27
|
+
3.times { assert_match /<h1>.*Hello World!.*<\/h1>/m, template.render }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
rescue LoadError => boom
|
data/tilt.gemspec
CHANGED
@@ -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 = '2.0.
|
7
|
-
s.date = '
|
6
|
+
s.version = '2.0.2'
|
7
|
+
s.date = '2016-01-05'
|
8
8
|
|
9
9
|
s.description = "Generic interface to multiple Ruby template engines"
|
10
10
|
s.summary = s.description
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
docs/common.css
|
27
27
|
lib/tilt.rb
|
28
28
|
lib/tilt/asciidoc.rb
|
29
|
+
lib/tilt/babel.rb
|
29
30
|
lib/tilt/bluecloth.rb
|
30
31
|
lib/tilt/builder.rb
|
31
32
|
lib/tilt/coffee.rb
|
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
|
|
43
44
|
lib/tilt/maruku.rb
|
44
45
|
lib/tilt/nokogiri.rb
|
45
46
|
lib/tilt/plain.rb
|
47
|
+
lib/tilt/prawn.rb
|
46
48
|
lib/tilt/radius.rb
|
47
49
|
lib/tilt/rdiscount.rb
|
48
50
|
lib/tilt/rdoc.rb
|
@@ -53,6 +55,8 @@ Gem::Specification.new do |s|
|
|
53
55
|
lib/tilt/template.rb
|
54
56
|
lib/tilt/wikicloth.rb
|
55
57
|
lib/tilt/yajl.rb
|
58
|
+
man/index.txt
|
59
|
+
man/tilt.1.ronn
|
56
60
|
test/markaby/locals.mab
|
57
61
|
test/markaby/markaby.mab
|
58
62
|
test/markaby/markaby_other_static.mab
|
@@ -61,6 +65,7 @@ Gem::Specification.new do |s|
|
|
61
65
|
test/markaby/yielding.mab
|
62
66
|
test/test_helper.rb
|
63
67
|
test/tilt_asciidoctor_test.rb
|
68
|
+
test/tilt_babeltemplate.rb
|
64
69
|
test/tilt_blueclothtemplate_test.rb
|
65
70
|
test/tilt_buildertemplate_test.rb
|
66
71
|
test/tilt_cache_test.rb
|
@@ -82,6 +87,8 @@ Gem::Specification.new do |s|
|
|
82
87
|
test/tilt_marukutemplate_test.rb
|
83
88
|
test/tilt_metadata_test.rb
|
84
89
|
test/tilt_nokogiritemplate_test.rb
|
90
|
+
test/tilt_prawntemplate.prawn
|
91
|
+
test/tilt_prawntemplate_test.rb
|
85
92
|
test/tilt_radiustemplate_test.rb
|
86
93
|
test/tilt_rdiscounttemplate_test.rb
|
87
94
|
test/tilt_rdoctemplate_test.rb
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Tomayko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generic interface to multiple Ruby template engines
|
14
14
|
email: r@tomayko.com
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- docs/common.css
|
29
29
|
- lib/tilt.rb
|
30
30
|
- lib/tilt/asciidoc.rb
|
31
|
+
- lib/tilt/babel.rb
|
31
32
|
- lib/tilt/bluecloth.rb
|
32
33
|
- lib/tilt/builder.rb
|
33
34
|
- lib/tilt/coffee.rb
|
@@ -45,6 +46,7 @@ files:
|
|
45
46
|
- lib/tilt/maruku.rb
|
46
47
|
- lib/tilt/nokogiri.rb
|
47
48
|
- lib/tilt/plain.rb
|
49
|
+
- lib/tilt/prawn.rb
|
48
50
|
- lib/tilt/radius.rb
|
49
51
|
- lib/tilt/rdiscount.rb
|
50
52
|
- lib/tilt/rdoc.rb
|
@@ -55,6 +57,8 @@ files:
|
|
55
57
|
- lib/tilt/template.rb
|
56
58
|
- lib/tilt/wikicloth.rb
|
57
59
|
- lib/tilt/yajl.rb
|
60
|
+
- man/index.txt
|
61
|
+
- man/tilt.1.ronn
|
58
62
|
- test/markaby/locals.mab
|
59
63
|
- test/markaby/markaby.mab
|
60
64
|
- test/markaby/markaby_other_static.mab
|
@@ -63,6 +67,7 @@ files:
|
|
63
67
|
- test/markaby/yielding.mab
|
64
68
|
- test/test_helper.rb
|
65
69
|
- test/tilt_asciidoctor_test.rb
|
70
|
+
- test/tilt_babeltemplate.rb
|
66
71
|
- test/tilt_blueclothtemplate_test.rb
|
67
72
|
- test/tilt_buildertemplate_test.rb
|
68
73
|
- test/tilt_cache_test.rb
|
@@ -84,6 +89,8 @@ files:
|
|
84
89
|
- test/tilt_marukutemplate_test.rb
|
85
90
|
- test/tilt_metadata_test.rb
|
86
91
|
- test/tilt_nokogiritemplate_test.rb
|
92
|
+
- test/tilt_prawntemplate.prawn
|
93
|
+
- test/tilt_prawntemplate_test.rb
|
87
94
|
- test/tilt_radiustemplate_test.rb
|
88
95
|
- test/tilt_rdiscounttemplate_test.rb
|
89
96
|
- test/tilt_rdoctemplate_test.rb
|
@@ -122,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
129
|
version: '0'
|
123
130
|
requirements: []
|
124
131
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.2.
|
132
|
+
rubygems_version: 2.2.2
|
126
133
|
signing_key:
|
127
134
|
specification_version: 2
|
128
135
|
summary: Generic interface to multiple Ruby template engines
|
@@ -148,6 +155,7 @@ test_files:
|
|
148
155
|
- test/tilt_marukutemplate_test.rb
|
149
156
|
- test/tilt_metadata_test.rb
|
150
157
|
- test/tilt_nokogiritemplate_test.rb
|
158
|
+
- test/tilt_prawntemplate_test.rb
|
151
159
|
- test/tilt_radiustemplate_test.rb
|
152
160
|
- test/tilt_rdiscounttemplate_test.rb
|
153
161
|
- test/tilt_rdoctemplate_test.rb
|