asciidoctor 1.5.8 → 2.0.0.rc.1

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.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +162 -17
  3. data/LICENSE +1 -1
  4. data/README-de.adoc +12 -13
  5. data/README-fr.adoc +11 -12
  6. data/README-jp.adoc +11 -12
  7. data/README-zh_CN.adoc +12 -13
  8. data/README.adoc +6 -7
  9. data/asciidoctor.gemspec +19 -24
  10. data/bin/asciidoctor +5 -4
  11. data/data/reference/syntax.adoc +283 -0
  12. data/data/stylesheets/asciidoctor-default.css +56 -52
  13. data/data/stylesheets/coderay-asciidoctor.css +7 -9
  14. data/lib/asciidoctor.rb +171 -232
  15. data/lib/asciidoctor/abstract_block.rb +96 -105
  16. data/lib/asciidoctor/abstract_node.rb +118 -139
  17. data/lib/asciidoctor/attribute_list.rb +10 -14
  18. data/lib/asciidoctor/block.rb +20 -19
  19. data/lib/asciidoctor/callouts.rb +4 -2
  20. data/lib/asciidoctor/cli.rb +3 -2
  21. data/lib/asciidoctor/cli/invoker.rb +14 -21
  22. data/lib/asciidoctor/cli/options.rb +64 -54
  23. data/lib/asciidoctor/converter.rb +357 -185
  24. data/lib/asciidoctor/converter/composite.rb +40 -48
  25. data/lib/asciidoctor/converter/docbook5.rb +604 -640
  26. data/lib/asciidoctor/converter/html5.rb +949 -963
  27. data/lib/asciidoctor/converter/manpage.rb +569 -548
  28. data/lib/asciidoctor/converter/template.rb +231 -272
  29. data/lib/asciidoctor/core_ext.rb +5 -18
  30. data/lib/asciidoctor/core_ext/float/truncate.rb +19 -0
  31. data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
  32. data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
  33. data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
  34. data/lib/asciidoctor/document.rb +399 -377
  35. data/lib/asciidoctor/extensions.rb +72 -140
  36. data/lib/asciidoctor/helpers.rb +122 -83
  37. data/lib/asciidoctor/inline.rb +5 -1
  38. data/lib/asciidoctor/list.rb +13 -11
  39. data/lib/asciidoctor/logging.rb +17 -16
  40. data/lib/asciidoctor/parser.rb +390 -423
  41. data/lib/asciidoctor/path_resolver.rb +10 -5
  42. data/lib/asciidoctor/reader.rb +286 -263
  43. data/lib/asciidoctor/rouge_ext.rb +39 -0
  44. data/lib/asciidoctor/section.rb +9 -8
  45. data/lib/asciidoctor/stylesheets.rb +19 -37
  46. data/lib/asciidoctor/substitutors.rb +364 -509
  47. data/lib/asciidoctor/syntax_highlighter.rb +238 -0
  48. data/lib/asciidoctor/syntax_highlighter/coderay.rb +87 -0
  49. data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +26 -0
  50. data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
  51. data/lib/asciidoctor/syntax_highlighter/prettify.rb +27 -0
  52. data/lib/asciidoctor/syntax_highlighter/pygments.rb +149 -0
  53. data/lib/asciidoctor/syntax_highlighter/rouge.rb +129 -0
  54. data/lib/asciidoctor/table.rb +73 -66
  55. data/lib/asciidoctor/timings.rb +4 -2
  56. data/lib/asciidoctor/version.rb +2 -1
  57. data/lib/asciidoctor/writer.rb +30 -0
  58. data/man/asciidoctor.1 +19 -15
  59. data/man/asciidoctor.adoc +14 -12
  60. metadata +69 -216
  61. data/CONTRIBUTING.adoc +0 -185
  62. data/Gemfile +0 -60
  63. data/Rakefile +0 -129
  64. data/bin/asciidoctor-safe +0 -15
  65. data/features/open_block.feature +0 -92
  66. data/features/pass_block.feature +0 -66
  67. data/features/step_definitions.rb +0 -49
  68. data/features/text_formatting.feature +0 -57
  69. data/features/xref.feature +0 -1039
  70. data/lib/asciidoctor/converter/base.rb +0 -59
  71. data/lib/asciidoctor/converter/docbook45.rb +0 -93
  72. data/lib/asciidoctor/converter/factory.rb +0 -226
  73. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
  74. data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
  75. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
  76. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
  77. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
  78. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
  79. data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
  80. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
  81. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
  82. data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
  83. data/test/api_test.rb +0 -1240
  84. data/test/attribute_list_test.rb +0 -242
  85. data/test/attributes_test.rb +0 -1623
  86. data/test/blocks_test.rb +0 -3870
  87. data/test/converter_test.rb +0 -470
  88. data/test/document_test.rb +0 -1853
  89. data/test/extensions_test.rb +0 -1560
  90. data/test/fixtures/asciidoc_index.txt +0 -521
  91. data/test/fixtures/basic-docinfo-footer.html +0 -6
  92. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  93. data/test/fixtures/basic-docinfo.html +0 -1
  94. data/test/fixtures/basic-docinfo.xml +0 -4
  95. data/test/fixtures/basic.asciidoc +0 -5
  96. data/test/fixtures/chapter-a.adoc +0 -3
  97. data/test/fixtures/child-include.adoc +0 -5
  98. data/test/fixtures/circle.svg +0 -9
  99. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  100. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  101. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  102. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  103. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  104. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  105. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  106. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  107. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  108. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  109. data/test/fixtures/docinfo-footer.html +0 -1
  110. data/test/fixtures/docinfo-footer.xml +0 -9
  111. data/test/fixtures/docinfo.html +0 -1
  112. data/test/fixtures/docinfo.xml +0 -3
  113. data/test/fixtures/doctime-localtime.adoc +0 -2
  114. data/test/fixtures/dot.gif +0 -0
  115. data/test/fixtures/encoding.asciidoc +0 -13
  116. data/test/fixtures/file-with-missing-include.adoc +0 -1
  117. data/test/fixtures/grandchild-include.adoc +0 -3
  118. data/test/fixtures/hello-asciidoctor.pdf +0 -69
  119. data/test/fixtures/include-file.asciidoc +0 -24
  120. data/test/fixtures/include-file.jsx +0 -8
  121. data/test/fixtures/include-file.ml +0 -3
  122. data/test/fixtures/include-file.xml +0 -5
  123. data/test/fixtures/lists.adoc +0 -96
  124. data/test/fixtures/master.adoc +0 -5
  125. data/test/fixtures/mismatched-end-tag.adoc +0 -7
  126. data/test/fixtures/other-chapters.adoc +0 -11
  127. data/test/fixtures/outer-include.adoc +0 -5
  128. data/test/fixtures/parent-include-restricted.adoc +0 -5
  129. data/test/fixtures/parent-include.adoc +0 -5
  130. data/test/fixtures/sample.asciidoc +0 -30
  131. data/test/fixtures/section-a.adoc +0 -4
  132. data/test/fixtures/stylesheets/custom.css +0 -3
  133. data/test/fixtures/subdir/index.adoc +0 -3
  134. data/test/fixtures/subdir/inner-include.adoc +0 -3
  135. data/test/fixtures/subdir/middle-include.adoc +0 -5
  136. data/test/fixtures/subs-docinfo.html +0 -2
  137. data/test/fixtures/subs.adoc +0 -6
  138. data/test/fixtures/tagged-class-enclosed.rb +0 -25
  139. data/test/fixtures/tagged-class.rb +0 -23
  140. data/test/fixtures/tip.gif +0 -0
  141. data/test/fixtures/unclosed-tag.adoc +0 -3
  142. data/test/fixtures/unexpected-end-tag.adoc +0 -4
  143. data/test/invoker_test.rb +0 -745
  144. data/test/links_test.rb +0 -855
  145. data/test/lists_test.rb +0 -5151
  146. data/test/logger_test.rb +0 -211
  147. data/test/manpage_test.rb +0 -660
  148. data/test/options_test.rb +0 -262
  149. data/test/paragraphs_test.rb +0 -562
  150. data/test/parser_test.rb +0 -742
  151. data/test/paths_test.rb +0 -395
  152. data/test/preamble_test.rb +0 -173
  153. data/test/reader_test.rb +0 -2161
  154. data/test/sections_test.rb +0 -3575
  155. data/test/substitutions_test.rb +0 -2066
  156. data/test/tables_test.rb +0 -2036
  157. data/test/test_helper.rb +0 -447
  158. data/test/text_test.rb +0 -309
@@ -1,470 +0,0 @@
1
- # encoding: UTF-8
2
- unless defined? ASCIIDOCTOR_PROJECT_DIR
3
- $: << File.dirname(__FILE__); $:.uniq!
4
- require 'test_helper'
5
- end
6
- require 'tilt' unless defined? ::Tilt
7
-
8
- context 'Converter' do
9
-
10
- context 'View options' do
11
- test 'should set Haml format to html5 for html5 backend' do
12
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
13
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
14
- selected = doc.converter.find_converter('paragraph')
15
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
16
- assert_kind_of Tilt::HamlTemplate, selected.templates['paragraph']
17
- assert_equal :html5, selected.templates['paragraph'].options[:format]
18
- end
19
-
20
- test 'should set Haml format to xhtml for docbook backend' do
21
- doc = Asciidoctor::Document.new [], :backend => 'docbook45', :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
22
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
23
- selected = doc.converter.find_converter('paragraph')
24
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
25
- assert_kind_of Tilt::HamlTemplate, selected.templates['paragraph']
26
- assert_equal :xhtml, selected.templates['paragraph'].options[:format]
27
- end
28
-
29
- test 'should configure Slim to resolve includes in specified template dirs' do
30
- template_dirs = [(fixture_path 'custom-backends/slim'), (fixture_path 'custom-backends/slim-overrides')]
31
- doc = Asciidoctor::Document.new [], :template_dirs => template_dirs, :template_cache => false
32
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
33
- selected = doc.converter.find_converter('paragraph')
34
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
35
- assert_kind_of Slim::Template, selected.templates['paragraph']
36
- assert_equal template_dirs.reverse.map {|dir| File.expand_path dir }, selected.templates['paragraph'].options[:include_dirs]
37
- end
38
-
39
- test 'should coerce template_dirs option to an Array' do
40
- template_dirs = fixture_path 'custom-backends/slim'
41
- doc = Asciidoctor::Document.new [], :template_dirs => template_dirs, :template_cache => false
42
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
43
- selected = doc.converter.find_converter('paragraph')
44
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
45
- assert_kind_of Array, (selected.instance_variable_get :@template_dirs)
46
- end
47
-
48
- test 'should set Slim format to html for html5 backend' do
49
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false
50
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
51
- selected = doc.converter.find_converter('paragraph')
52
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
53
- assert_kind_of Slim::Template, selected.templates['paragraph']
54
- assert_equal :html, selected.templates['paragraph'].options[:format]
55
- end
56
-
57
- test 'should set Slim format to nil for docbook backend' do
58
- doc = Asciidoctor::Document.new [], :backend => 'docbook45', :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false
59
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
60
- selected = doc.converter.find_converter('paragraph')
61
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
62
- assert_kind_of Slim::Template, selected.templates['paragraph']
63
- assert_nil selected.templates['paragraph'].options[:format]
64
- end
65
-
66
- test 'should set safe mode of Slim AsciiDoc engine to match document safe mode when Slim >= 3' do
67
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false, :safe => :unsafe
68
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
69
- selected = doc.converter.find_converter('paragraph')
70
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
71
- slim_asciidoc_opts = selected.instance_variable_get(:@engine_options)[:slim][:asciidoc]
72
- if ::Slim::VERSION >= '3.0'
73
- assert_equal({ :safe => Asciidoctor::SafeMode::UNSAFE }, slim_asciidoc_opts)
74
- else
75
- assert_nil slim_asciidoc_opts
76
- end
77
- end
78
-
79
- test 'should support custom template engine options for known engine' do
80
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false, :template_engine_options => { :slim => { :pretty => true } }
81
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
82
- selected = doc.converter.find_converter('paragraph')
83
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
84
- assert_kind_of Slim::Template, selected.templates['paragraph']
85
- assert_equal true, selected.templates['paragraph'].options[:pretty]
86
- end
87
-
88
- test 'should support custom template engine options' do
89
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false, :template_engine_options => { :slim => { :pretty => true } }
90
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
91
- selected = doc.converter.find_converter('paragraph')
92
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
93
- assert_kind_of Slim::Template, selected.templates['paragraph']
94
- assert_equal false, selected.templates['paragraph'].options[:sort_attrs]
95
- assert_equal true, selected.templates['paragraph'].options[:pretty]
96
- end
97
- end
98
-
99
- context 'Custom backends' do
100
- test 'should load Haml templates for default backend' do
101
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
102
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
103
- ['paragraph', 'sidebar'].each do |node_name|
104
- selected = doc.converter.find_converter node_name
105
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
106
- assert_kind_of Tilt::HamlTemplate, selected.templates[node_name]
107
- assert_equal %(block_#{node_name}.html.haml), File.basename(selected.templates[node_name].file)
108
- end
109
- end
110
-
111
- test 'should set outfilesuffix according to backend info' do
112
- doc = Asciidoctor.load 'content'
113
- doc.convert
114
- assert_equal '.html', doc.attributes['outfilesuffix']
115
-
116
- doc = Asciidoctor.load 'content', :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
117
- doc.convert
118
- assert_equal '.html', doc.attributes['outfilesuffix']
119
- end
120
-
121
- test 'should not override outfilesuffix attribute if locked' do
122
- doc = Asciidoctor.load 'content', :attributes => {'outfilesuffix' => '.foo'}
123
- doc.convert
124
- assert_equal '.foo', doc.attributes['outfilesuffix']
125
-
126
- doc = Asciidoctor.load 'content', :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false, :attributes => {'outfilesuffix' => '.foo'}
127
- doc.convert
128
- assert_equal '.foo', doc.attributes['outfilesuffix']
129
- end
130
-
131
- test 'should load Haml templates for docbook45 backend' do
132
- doc = Asciidoctor::Document.new [], :backend => 'docbook45', :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
133
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
134
- ['paragraph'].each do |node_name|
135
- selected = doc.converter.find_converter node_name
136
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
137
- assert_kind_of Tilt::HamlTemplate, selected.templates[node_name]
138
- assert_equal %(block_#{node_name}.xml.haml), File.basename(selected.templates[node_name].file)
139
- end
140
- end
141
-
142
- test 'should use Haml templates in place of built-in templates' do
143
- input = <<-EOS
144
- = Document Title
145
- Author Name
146
-
147
- == Section One
148
-
149
- Sample paragraph
150
-
151
- .Related
152
- ****
153
- Sidebar content
154
- ****
155
- EOS
156
-
157
- output = convert_string_to_embedded input, :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
158
- assert_xpath '/*[@class="sect1"]/*[@class="sectionbody"]/p', output, 1
159
- assert_xpath '//aside', output, 1
160
- assert_xpath '/*[@class="sect1"]/*[@class="sectionbody"]/p/following-sibling::aside', output, 1
161
- assert_xpath '//aside/header/h1[text()="Related"]', output, 1
162
- assert_xpath '//aside/header/following-sibling::p[text()="Sidebar content"]', output, 1
163
- end
164
-
165
- test 'should use built-in global cache to cache templates' do
166
- begin
167
- # clear out any cache, just to be sure
168
- Asciidoctor::Converter::TemplateConverter.clear_caches if defined? Asciidoctor::Converter::TemplateConverter
169
-
170
- template_dir = fixture_path 'custom-backends/haml'
171
- doc = Asciidoctor::Document.new [], :template_dir => template_dir
172
- doc.converter
173
- caches = Asciidoctor::Converter::TemplateConverter.caches
174
- if defined? ::Concurrent::Hash
175
- assert_kind_of ::Concurrent::Hash, caches[:templates]
176
- refute_empty caches[:templates]
177
- paragraph_template_before = caches[:templates].values.find {|t| File.basename(t.file) == 'block_paragraph.html.haml' }
178
- refute_nil paragraph_template_before
179
-
180
- # should use cache
181
- doc = Asciidoctor::Document.new [], :template_dir => template_dir
182
- template_converter = doc.converter.find_converter('paragraph')
183
- paragraph_template_after = template_converter.templates['paragraph']
184
- refute_nil paragraph_template_after
185
- assert paragraph_template_before.eql?(paragraph_template_after)
186
-
187
- # should not use cache
188
- doc = Asciidoctor::Document.new [], :template_dir => template_dir, :template_cache => false
189
- template_converter = doc.converter.find_converter('paragraph')
190
- paragraph_template_after = template_converter.templates['paragraph']
191
- refute_nil paragraph_template_after
192
- refute paragraph_template_before.eql?(paragraph_template_after)
193
- else
194
- assert_empty caches
195
- end
196
- ensure
197
- # clean up
198
- Asciidoctor::Converter::TemplateConverter.clear_caches if defined? Asciidoctor::Converter::TemplateConverter
199
- end
200
- end
201
-
202
- test 'should use custom cache to cache templates' do
203
- template_dir = fixture_path 'custom-backends/haml'
204
- Asciidoctor::PathResolver.new.system_path(File.join(template_dir, 'html5', 'block_paragraph.html.haml'), nil)
205
- caches = { :scans => {}, :templates => {} }
206
- doc = Asciidoctor::Document.new [], :template_dir => template_dir, :template_cache => caches
207
- doc.converter
208
- refute_empty caches[:scans]
209
- refute_empty caches[:templates]
210
- paragraph_template = caches[:templates].values.find {|t| File.basename(t.file) == 'block_paragraph.html.haml' }
211
- refute_nil paragraph_template
212
- assert_kind_of ::Tilt::HamlTemplate, paragraph_template
213
- end
214
-
215
- test 'should be able to disable template cache' do
216
- begin
217
- # clear out any cache, just to be sure
218
- Asciidoctor::Converter::TemplateConverter.clear_caches if defined? Asciidoctor::Converter::TemplateConverter
219
-
220
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/haml'), :template_cache => false
221
- doc.converter
222
- caches = Asciidoctor::Converter::TemplateConverter.caches
223
- assert caches.empty? || caches[:scans].empty?
224
- assert caches.empty? || caches[:templates].empty?
225
- ensure
226
- # clean up
227
- Asciidoctor::Converter::TemplateConverter.clear_caches if defined? Asciidoctor::Converter::TemplateConverter
228
- end
229
- end
230
-
231
- test 'should load ERB templates using ERBTemplate if eruby is not set' do
232
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/erb'), :template_cache => false
233
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
234
- ['paragraph'].each do |node_name|
235
- selected = doc.converter.find_converter node_name
236
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
237
- template = selected.templates[node_name]
238
- assert_kind_of Tilt::ERBTemplate, template
239
- refute_kind_of Tilt::ErubisTemplate, template
240
- assert_kind_of ::ERB, template.instance_variable_get('@engine')
241
- assert_equal %(block_#{node_name}.html.erb), File.basename(selected.templates[node_name].file)
242
- end
243
- end
244
-
245
- test 'should load ERB templates using ErubisTemplate if eruby is set to erubis' do
246
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/erb'), :template_cache => false, :eruby => 'erubis'
247
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
248
- ['paragraph'].each do |node_name|
249
- selected = doc.converter.find_converter node_name
250
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
251
- template = selected.templates[node_name]
252
- assert_kind_of Tilt::ERBTemplate, template
253
- assert_kind_of Tilt::ErubisTemplate, template
254
- assert_kind_of ::Erubis::FastEruby, template.instance_variable_get('@engine')
255
- assert_equal %(block_#{node_name}.html.erb), File.basename(selected.templates[node_name].file)
256
- end
257
- end
258
-
259
- test 'should load Slim templates for default backend' do
260
- doc = Asciidoctor::Document.new [], :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false
261
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
262
- ['paragraph', 'sidebar'].each do |node_name|
263
- selected = doc.converter.find_converter node_name
264
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
265
- assert_kind_of Slim::Template, selected.templates[node_name]
266
- assert_equal %(block_#{node_name}.html.slim), File.basename(selected.templates[node_name].file)
267
- end
268
- end
269
-
270
- test 'should load Slim templates for docbook45 backend' do
271
- doc = Asciidoctor::Document.new [], :backend => 'docbook45', :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false
272
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
273
- ['paragraph'].each do |node_name|
274
- selected = doc.converter.find_converter node_name
275
- assert_kind_of Asciidoctor::Converter::TemplateConverter, selected
276
- assert_kind_of Slim::Template, selected.templates[node_name]
277
- assert_equal %(block_#{node_name}.xml.slim), File.basename(selected.templates[node_name].file)
278
- end
279
- end
280
-
281
- test 'should use Slim templates in place of built-in templates' do
282
- input = <<-EOS
283
- = Document Title
284
- Author Name
285
-
286
- == Section One
287
-
288
- Sample paragraph
289
-
290
- .Related
291
- ****
292
- Sidebar content
293
- ****
294
- EOS
295
-
296
- output = convert_string_to_embedded input, :template_dir => (fixture_path 'custom-backends/slim'), :template_cache => false
297
- assert_xpath '/*[@class="sect1"]/*[@class="sectionbody"]/p', output, 1
298
- assert_xpath '//aside', output, 1
299
- assert_xpath '/*[@class="sect1"]/*[@class="sectionbody"]/p/following-sibling::aside', output, 1
300
- assert_xpath '//aside/header/h1[text()="Related"]', output, 1
301
- assert_xpath '//aside/header/following-sibling::p[text()="Sidebar content"]', output, 1
302
- end
303
-
304
- test 'should use custom converter if specified' do
305
- input = <<-EOS
306
- = Document Title
307
-
308
- preamble
309
-
310
- == Section
311
-
312
- content
313
- EOS
314
-
315
- class CustomConverterA
316
- def initialize backend, opts = {}
317
- end
318
-
319
- def convert node, name = nil
320
- 'document'
321
- end
322
-
323
- def self.converts? backend
324
- true
325
- end
326
- end
327
-
328
- output = convert_string input, :converter => CustomConverterA
329
- assert 'document', output
330
- end
331
-
332
- test 'should use converter registered for backend' do
333
- input = <<-EOS
334
- content
335
- EOS
336
-
337
- begin
338
- Asciidoctor::Converter::Factory.unregister_all
339
-
340
- class CustomConverterB
341
- include Asciidoctor::Converter
342
- register_for 'foobar'
343
- def convert node, name = nil
344
- 'foobar content'
345
- end
346
- end
347
-
348
- converters = Asciidoctor::Converter::Factory.converters
349
- assert converters.size == 1
350
- assert converters['foobar'] == CustomConverterB
351
- output = convert_string input, :backend => 'foobar'
352
- assert 'foobar content', output
353
- ensure
354
- Asciidoctor::Converter::Factory.unregister_all
355
- end
356
- end
357
-
358
- test 'should map handles? method on converter to respond_to? by default' do
359
- class CustomConverterC
360
- include Asciidoctor::Converter
361
- def paragraph node
362
- 'paragraph'
363
- end
364
- end
365
-
366
- converter = CustomConverterC.new 'myhtml'
367
- assert_respond_to converter, :handles?
368
- assert converter.handles?(:paragraph)
369
- end
370
-
371
- test 'should not configure converter to support templates by default' do
372
- input = <<-EOS
373
- paragraph
374
- EOS
375
-
376
- begin
377
- Asciidoctor::Converter::Factory.unregister_all
378
- class CustomConverterD
379
- include Asciidoctor::Converter
380
- register_for 'myhtml'
381
- def convert node, transform = nil, opts = {}
382
- transform ||= node.node_name
383
- send transform, node
384
- end
385
-
386
- def document node
387
- ['<!DOCTYPE html>', '<html>', '<body>', node.content, '</body>', '</html>'] * %(\n)
388
- end
389
-
390
- def paragraph node
391
- ['<div class="paragraph">', %(<p>#{node.content}</p>), '</div>'] * %(\n)
392
- end
393
- end
394
-
395
- doc = document_from_string input, :backend => 'myhtml', :template_dir => (fixture_path 'custom-backends/slim/html5'), :template_cache => false
396
- assert_kind_of CustomConverterD, doc.converter
397
- refute doc.converter.supports_templates?
398
- output = doc.convert
399
- assert_xpath '//*[@class="paragraph"]/p[text()="paragraph"]', output, 1
400
- ensure
401
- Asciidoctor::Converter::Factory.unregister_all
402
- end
403
- end
404
-
405
- test 'should wrap converter in composite converter with template converter if it declares that it supports templates' do
406
- input = <<-EOS
407
- paragraph
408
- EOS
409
-
410
- begin
411
- Asciidoctor::Converter::Factory.unregister_all
412
- class CustomConverterE
413
- include Asciidoctor::Converter
414
- register_for 'myhtml'
415
-
416
- def initialize *args
417
- super
418
- supports_templates
419
- end
420
-
421
- def convert node, transform = nil, opts = {}
422
- transform ||= node.node_name
423
- send transform, node
424
- end
425
-
426
- def document node
427
- ['<!DOCTYPE html>', '<html>', '<body>', node.content, '</body>', '</html>'] * %(\n)
428
- end
429
-
430
- def paragraph node
431
- ['<div class="paragraph">', %(<p>#{node.content}</p>), '</div>'] * %(\n)
432
- end
433
- end
434
-
435
- doc = document_from_string input, :backend => 'myhtml', :template_dir => (fixture_path 'custom-backends/slim/html5'), :template_cache => false
436
- assert_kind_of Asciidoctor::Converter::CompositeConverter, doc.converter
437
- output = doc.convert
438
- assert_xpath '//*[@class="paragraph"]/p[text()="paragraph"]', output, 0
439
- assert_xpath '//body/p[text()="paragraph"]', output, 1
440
- ensure
441
- Asciidoctor::Converter::Factory.unregister_all
442
- end
443
- end
444
-
445
- test 'should fall back to catch all converter' do
446
- input = <<-EOS
447
- content
448
- EOS
449
-
450
- begin
451
- Asciidoctor::Converter::Factory.unregister_all
452
-
453
- class CustomConverterF
454
- include Asciidoctor::Converter
455
- register_for '*'
456
- def convert node, name = nil
457
- 'foobaz content'
458
- end
459
- end
460
-
461
- converters = Asciidoctor::Converter::Factory.converters
462
- assert converters['*'] == CustomConverterF
463
- output = convert_string input, :backend => 'foobaz'
464
- assert 'foobaz content', output
465
- ensure
466
- Asciidoctor::Converter::Factory.unregister_all
467
- end
468
- end
469
- end
470
- end