tilt 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tilt.rb +1 -1
  3. data/lib/tilt/template.rb +7 -12
  4. metadata +3 -104
  5. data/CHANGELOG.md +0 -132
  6. data/Gemfile +0 -70
  7. data/HACKING +0 -16
  8. data/README.md +0 -233
  9. data/Rakefile +0 -106
  10. data/docs/TEMPLATES.md +0 -555
  11. data/docs/common.css +0 -14
  12. data/man/index.txt +0 -2
  13. data/man/tilt.1.ronn +0 -59
  14. data/test/markaby/locals.mab +0 -1
  15. data/test/markaby/markaby.mab +0 -1
  16. data/test/markaby/markaby_other_static.mab +0 -1
  17. data/test/markaby/render_twice.mab +0 -1
  18. data/test/markaby/scope.mab +0 -1
  19. data/test/markaby/yielding.mab +0 -2
  20. data/test/mytemplate.rb +0 -2
  21. data/test/test_helper.rb +0 -64
  22. data/test/tilt_asciidoctor_test.rb +0 -50
  23. data/test/tilt_babeltemplate.rb +0 -33
  24. data/test/tilt_blueclothtemplate_test.rb +0 -33
  25. data/test/tilt_buildertemplate_test.rb +0 -72
  26. data/test/tilt_cache_test.rb +0 -43
  27. data/test/tilt_coffeescripttemplate_test.rb +0 -141
  28. data/test/tilt_commonmarkertemplate_test.rb +0 -28
  29. data/test/tilt_compilesite_test.rb +0 -51
  30. data/test/tilt_creoletemplate_test.rb +0 -24
  31. data/test/tilt_csv_test.rb +0 -77
  32. data/test/tilt_erbtemplate_test.rb +0 -239
  33. data/test/tilt_erubistemplate_test.rb +0 -151
  34. data/test/tilt_erubitemplate_test.rb +0 -158
  35. data/test/tilt_etannitemplate_test.rb +0 -174
  36. data/test/tilt_hamltemplate_test.rb +0 -166
  37. data/test/tilt_kramdown_test.rb +0 -20
  38. data/test/tilt_lesstemplate_test.less +0 -1
  39. data/test/tilt_lesstemplate_test.rb +0 -42
  40. data/test/tilt_liquidtemplate_test.rb +0 -87
  41. data/test/tilt_livescripttemplate_test.rb +0 -37
  42. data/test/tilt_mapping_test.rb +0 -232
  43. data/test/tilt_markaby_test.rb +0 -88
  44. data/test/tilt_markdown_test.rb +0 -186
  45. data/test/tilt_marukutemplate_test.rb +0 -36
  46. data/test/tilt_metadata_test.rb +0 -42
  47. data/test/tilt_nokogiritemplate_test.rb +0 -87
  48. data/test/tilt_pandoctemplate_test.rb +0 -67
  49. data/test/tilt_prawntemplate.prawn +0 -1
  50. data/test/tilt_prawntemplate_test.rb +0 -75
  51. data/test/tilt_radiustemplate_test.rb +0 -75
  52. data/test/tilt_rdiscounttemplate_test.rb +0 -43
  53. data/test/tilt_rdoctemplate_test.rb +0 -29
  54. data/test/tilt_redcarpettemplate_test.rb +0 -54
  55. data/test/tilt_redclothtemplate_test.rb +0 -36
  56. data/test/tilt_rstpandoctemplate_test.rb +0 -32
  57. data/test/tilt_sasstemplate_test.rb +0 -42
  58. data/test/tilt_sigil_test.rb +0 -41
  59. data/test/tilt_stringtemplate_test.rb +0 -171
  60. data/test/tilt_template_test.rb +0 -314
  61. data/test/tilt_test.rb +0 -60
  62. data/test/tilt_typescript_test.rb +0 -38
  63. data/test/tilt_wikiclothtemplate_test.rb +0 -32
  64. data/test/tilt_yajltemplate_test.rb +0 -101
  65. data/tilt.gemspec +0 -130
@@ -1,186 +0,0 @@
1
- # coding: UTF-8
2
- require 'tilt'
3
- require 'test_helper'
4
-
5
- begin
6
- require 'nokogiri'
7
-
8
- module MarkdownTests
9
- def self.included(mod)
10
- class << mod
11
- def template(t = nil)
12
- t.nil? ? @template : @template = t
13
- end
14
- end
15
- end
16
-
17
- def render(text, options = {})
18
- self.class.template.new(options) { text }.render
19
- end
20
-
21
- def normalize(html)
22
- Nokogiri::HTML.fragment(html).to_s.strip
23
- end
24
-
25
- def nrender(text, options = {})
26
- html = render(text, options)
27
- html.encode!("UTF-8") if html.respond_to?(:encode)
28
- normalize(html)
29
- end
30
-
31
- def test_escape_html
32
- html = nrender "Hello <b>World</b>"
33
- assert_equal "<p>Hello <b>World</b></p>", html
34
- end
35
-
36
- def test_escape_html_false
37
- html = nrender "Hello <b>World</b>", :escape_html => false
38
- assert_equal "<p>Hello <b>World</b></p>", html
39
- end
40
-
41
- def test_escape_html_true
42
- html = nrender "Hello <b>World</b>", :escape_html => true
43
- assert_equal "<p>Hello &lt;b&gt;World&lt;/b&gt;</p>", html
44
- end
45
-
46
- def test_smart_quotes
47
- html = nrender 'Hello "World"'
48
- assert_equal '<p>Hello "World"</p>', html
49
- end
50
-
51
- def test_smart_quotes_false
52
- html = nrender 'Hello "World"', :smartypants => false
53
- assert_equal '<p>Hello "World"</p>', html
54
- end
55
-
56
- def test_smart_quotes_true
57
- html = nrender 'Hello "World"', :smartypants => true
58
- assert_equal '<p>Hello “World”</p>', html
59
- end
60
-
61
- def test_smarty_pants
62
- html = nrender "Hello ``World'' -- This is --- a test ..."
63
- assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
64
- end
65
-
66
- def test_smarty_pants_false
67
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => false
68
- assert_equal "<p>Hello ``World'' -- This is --- a test ...</p>", html
69
- end
70
- end
71
-
72
- begin
73
- require 'tilt/rdiscount'
74
-
75
- class MarkdownRDiscountTest < Minitest::Test
76
- include MarkdownTests
77
- template Tilt::RDiscountTemplate
78
-
79
- def test_smarty_pants_true
80
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
81
- assert_equal "<p>Hello “World” – This is — a test …</p>", html
82
- end
83
- end
84
- rescue LoadError => boom
85
- # It should already be warned in the main tests
86
- end
87
-
88
- begin
89
- require 'tilt/redcarpet'
90
-
91
- class MarkdownRedcarpetTest < Minitest::Test
92
- include MarkdownTests
93
- template Tilt::RedcarpetTemplate
94
-
95
- def test_smarty_pants_true
96
- # Various versions of Redcarpet support various versions of Smart pants.
97
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
98
- assert_match %r!<p>Hello “World(''|”) – This is — a test …<\/p>!, html
99
- end
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
-
106
- def test_fenced_code_blocks_with_lang
107
- code = <<-COD.gsub(/^\s+/,"")
108
- ```ruby
109
- puts "hello world"
110
- ```
111
- COD
112
-
113
- html = nrender code, :fenced_code_blocks => true
114
- assert_equal %Q{<pre><code class="ruby">puts "hello world"\n</code></pre>}, html
115
- end
116
- end
117
- rescue LoadError => boom
118
- # It should already be warned in the main tests
119
- end
120
-
121
- begin
122
- require 'tilt/bluecloth'
123
-
124
- class MarkdownBlueClothTest < Minitest::Test
125
- include MarkdownTests
126
- template Tilt::BlueClothTemplate
127
-
128
- def test_smarty_pants_true
129
- html = nrender "Hello ``World'' -- This is --- a test ...", :smartypants => true
130
- assert_equal "<p>Hello “World” — This is —– a test …</p>", html
131
- end
132
- end
133
- rescue LoadError => boom
134
- # It should already be warned in the main tests
135
- end
136
-
137
- begin
138
- require 'tilt/kramdown'
139
-
140
- class MarkdownKramdownTest < Minitest::Test
141
- include MarkdownTests
142
- template Tilt::KramdownTemplate
143
- # Doesn't support escaping
144
- undef test_escape_html_true
145
- # Smarty Pants is *always* on, but doesn't support it fully
146
- undef test_smarty_pants
147
- undef test_smarty_pants_false
148
- end
149
- rescue LoadError => boom
150
- # It should already be warned in the main tests
151
- end
152
-
153
-
154
- begin
155
- require 'tilt/maruku'
156
-
157
- class MarkdownMarukuTest < Minitest::Test
158
- include MarkdownTests
159
- template Tilt::MarukuTemplate
160
- # Doesn't support escaping
161
- undef test_escape_html_true
162
- # Doesn't support Smarty Pants, and even fails on ``Foobar''
163
- undef test_smarty_pants
164
- undef test_smarty_pants_false
165
- # Smart Quotes is always on
166
- undef test_smart_quotes
167
- undef test_smart_quotes_false
168
- end
169
- rescue LoadError => boom
170
- # It should already be warned in the main tests
171
- end
172
-
173
- rescue LoadError
174
- warn "Markdown tests need Nokogiri"
175
- end
176
-
177
- begin
178
- require 'tilt/pandoc'
179
-
180
- class MarkdownPandocTest < Minitest::Test
181
- include MarkdownTests
182
- template Tilt::PandocTemplate
183
- end
184
- rescue LoadError => boom
185
- # It should already be warned in the main tests
186
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/maruku'
6
-
7
- class MarukuTemplateTest < Minitest::Test
8
- test "registered below Kramdown" do
9
- %w[md mkd markdown].each do |ext|
10
- lazy = Tilt.lazy_map[ext]
11
- kram_idx = lazy.index { |klass, file| klass == 'Tilt::KramdownTemplate' }
12
- maru_idx = lazy.index { |klass, file| klass == 'Tilt::MarukuTemplate' }
13
- assert maru_idx > kram_idx,
14
- "#{maru_idx} should be higher than #{kram_idx}"
15
- end
16
- end
17
-
18
- test "preparing and evaluating templates on #render" do
19
- template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
20
- assert_equal "<h1 id=\"hello_world\">Hello World!</h1>", template.render.strip
21
- end
22
-
23
- test "can be rendered more than once" do
24
- template = Tilt::MarukuTemplate.new { |t| "# Hello World!" }
25
- 3.times { assert_equal "<h1 id=\"hello_world\">Hello World!</h1>", template.render.strip }
26
- end
27
-
28
- test "removes HTML when :filter_html is set" do
29
- template = Tilt::MarukuTemplate.new(:filter_html => true) { |t|
30
- "HELLO <blink>WORLD</blink>" }
31
- assert_equal "<p>HELLO</p>", template.render.strip
32
- end
33
- end
34
- rescue LoadError
35
- warn "Tilt::MarukuTemplate (disabled)"
36
- end
@@ -1,42 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt/template'
3
-
4
- module Tilt
5
- class TemplateMetadataTest < Minitest::Test
6
- class MyTemplate < Template
7
- metadata[:global] = 1
8
- self.default_mime_type = 'text/html'
9
-
10
- def prepare
11
- end
12
-
13
- def allows_script?
14
- true
15
- end
16
- end
17
-
18
- test "global metadata" do
19
- assert MyTemplate.metadata
20
- assert_equal 1, MyTemplate.metadata[:global]
21
- end
22
-
23
- test "instance metadata" do
24
- tmpl = MyTemplate.new { '' }
25
- assert_equal 1, tmpl.metadata[:global]
26
- end
27
-
28
- test "gracefully handles default_mime_type" do
29
- assert_equal 'text/html', MyTemplate.metadata[:mime_type]
30
- end
31
-
32
- test "still allows .default_mime_type" do
33
- assert_equal 'text/html', MyTemplate.default_mime_type
34
- end
35
-
36
- test "gracefully handles allows_script?" do
37
- tmpl = MyTemplate.new { '' }
38
- assert_equal true, tmpl.metadata[:allows_script]
39
- end
40
- end
41
- end
42
-
@@ -1,87 +0,0 @@
1
- require 'test_helper'
2
- require 'tilt'
3
-
4
- begin
5
- require 'tilt/nokogiri'
6
- class NokogiriTemplateTest < Minitest::Test
7
- test "registered for '.nokogiri' files" do
8
- assert_equal Tilt::NokogiriTemplate, Tilt['test.nokogiri']
9
- assert_equal Tilt::NokogiriTemplate, Tilt['test.xml.nokogiri']
10
- end
11
-
12
- test "preparing and evaluating the template on #render" do
13
- template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
14
- doc = Nokogiri.XML template.render
15
- assert_equal 'Hello World!', doc.root.text
16
- assert_equal 'em', doc.root.name
17
- end
18
-
19
- test "can be rendered more than once" do
20
- template = Tilt::NokogiriTemplate.new { |t| "xml.em 'Hello World!'" }
21
- 3.times do
22
- doc = Nokogiri.XML template.render
23
- assert_equal 'Hello World!', doc.root.text
24
- assert_equal 'em', doc.root.name
25
- end
26
- end
27
-
28
- test "passing locals" do
29
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + name + '!')" }
30
- doc = Nokogiri.XML template.render(Object.new, :name => 'Joe')
31
- assert_equal 'Hey Joe!', doc.root.text
32
- assert_equal 'em', doc.root.name
33
- end
34
-
35
- test "evaluating in an object scope" do
36
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + @name + '!')" }
37
- scope = Object.new
38
- scope.instance_variable_set :@name, 'Joe'
39
- doc = Nokogiri.XML template.render(scope)
40
- assert_equal 'Hey Joe!', doc.root.text
41
- assert_equal 'em', doc.root.name
42
- end
43
-
44
- test "passing a block for yield" do
45
- template = Tilt::NokogiriTemplate.new { "xml.em('Hey ' + yield + '!')" }
46
- 3.times do
47
- doc = Nokogiri.XML template.render { 'Joe' }
48
- assert_equal 'Hey Joe!', doc.root.text
49
- assert_equal 'em', doc.root.name
50
- end
51
- end
52
-
53
- test "block style templates" do
54
- template =
55
- Tilt::NokogiriTemplate.new do |t|
56
- lambda { |xml| xml.em('Hey Joe!') }
57
- end
58
- doc = Nokogiri.XML template.render
59
- assert_equal 'Hey Joe!', doc.root.text
60
- assert_equal 'em', doc.root.name
61
- end
62
-
63
- test "allows nesting raw XML, API-compatible to Builder" do
64
- subtemplate = Tilt::NokogiriTemplate.new { "xml.em 'Hello World!'" }
65
- template = Tilt::NokogiriTemplate.new { "xml.strong { xml << yield }" }
66
- 3.times do
67
- options = { :xml => Nokogiri::XML::Builder.new }
68
- doc = Nokogiri.XML(template.render(options) { subtemplate.render(options) })
69
- assert_equal 'Hello World!', doc.root.text.strip
70
- assert_equal 'strong', doc.root.name
71
- end
72
- end
73
-
74
- test "doesn't modify self when template is a string" do
75
- template = Tilt::NokogiriTemplate.new { "xml.root { xml.child @hello }" }
76
- scope = Object.new
77
- scope.instance_variable_set(:@hello, "Hello World!")
78
-
79
- 3.times do
80
- doc = Nokogiri.XML(template.render(scope))
81
- assert_equal "Hello World!", doc.text.strip
82
- end
83
- end
84
- end
85
- rescue LoadError
86
- warn "Tilt::NokogiriTemplate (disabled)"
87
- end
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test_helper'
4
- require 'tilt'
5
-
6
- begin
7
- require 'tilt/pandoc'
8
-
9
- class PandocTemplateTest < Minitest::Test
10
- test "preparing and evaluating templates on #render" do
11
- template = Tilt::PandocTemplate.new { |t| "# Hello World!" }
12
- assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render
13
- end
14
-
15
- test "can be rendered more than once" do
16
- template = Tilt::PandocTemplate.new { |t| "# Hello World!" }
17
- 3.times { assert_equal "<h1 id=\"hello-world\">Hello World!</h1>", template.render }
18
- end
19
-
20
- test "smartypants when :smartypants is set" do
21
- template = Tilt::PandocTemplate.new(:smartypants => true) { |t| "OKAY -- 'Smarty Pants'" }
22
- assert_equal "<p>OKAY – ‘Smarty Pants’</p>", template.render
23
- end
24
-
25
- test "stripping HTML when :escape_html is set" do
26
- template = Tilt::PandocTemplate.new(:escape_html => true) { |t| "HELLO <blink>WORLD</blink>" }
27
- assert_equal "<p>HELLO &lt;blink&gt;WORLD&lt;/blink&gt;</p>", template.render
28
- end
29
-
30
- # Pandoc has tons of additional markdown features (see http://pandoc.org/README.html#pandocs-markdown).
31
- # The test for footnotes should be seen as a general representation for all of them.
32
- # use markdown_strict => true to disable additional markdown features
33
- describe "passing in Pandoc options" do
34
- test "generates footnotes" do
35
- template = Tilt::PandocTemplate.new { |t| "Here is an inline note.^[Inlines notes are cool!]" }
36
- assert_equal "<p>Here is an inline note.<a href=\"#fn1\" class=\"footnoteRef\" id=\"fnref1\"><sup>1</sup></a></p>\n<div class=\"footnotes\">\n<hr />\n<ol>\n<li id=\"fn1\"><p>Inlines notes are cool!<a href=\"#fnref1\">↩</a></p></li>\n</ol>\n</div>", template.render
37
- end
38
-
39
- test "doesn't generate footnotes with markdown_strict option" do
40
- template = Tilt::PandocTemplate.new(:markdown_strict => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" }
41
- assert_equal "<p>Here is an inline note.^[Inlines notes are cool!]</p>", template.render
42
- end
43
-
44
- test "doesn't generate footnotes with commonmark option" do
45
- template = Tilt::PandocTemplate.new(:commonmark => true) { |t| "Here is an inline note.^[Inlines notes are cool!]" }
46
- assert_equal "<p>Here is an inline note.^[Inlines notes are cool!]</p>", template.render
47
- end
48
-
49
- test "accepts arguments with values (e.g. :id_prefix => 'xyz')" do
50
- # Table of contents isn't on by default
51
- template = Tilt::PandocTemplate.new { |t| "# This is a heading" }
52
- assert_equal "<h1 id=\"this-is-a-heading\">This is a heading</h1>", template.render
53
-
54
- # But it can be activated
55
- template = Tilt::PandocTemplate.new(:id_prefix => 'test-') { |t| "# This is a heading" }
56
- assert_equal "<h1 id=\"test-this-is-a-heading\">This is a heading</h1>", template.render
57
- end
58
-
59
- test "requires arguments without value (e.g. --standalone) to be passed as hash keys (:standalone => true)" do
60
- template = Tilt::PandocTemplate.new(:standalone => true) { |t| "# This is a heading" }
61
- assert_match(/^<!DOCTYPE html.*<h1 id="this-is-a-heading">This is a heading<\/h1>.*<\/html>$/m, template.render)
62
- end
63
- end
64
- end
65
- rescue LoadError
66
- warn "Tilt::PandocTemplate (disabled)"
67
- end
@@ -1 +0,0 @@
1
- pdf.text "Hello Template!"
@@ -1,75 +0,0 @@
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
74
- warn "Tilt::PrawnTemplate (disabled)"
75
- end