asciidoctor 1.5.8 → 2.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.adoc +628 -45
  4. data/LICENSE +2 -1
  5. data/README-de.adoc +28 -38
  6. data/README-fr.adoc +30 -43
  7. data/README-jp.adoc +255 -201
  8. data/README-zh_CN.adoc +40 -44
  9. data/README.adoc +170 -143
  10. data/asciidoctor.gemspec +22 -34
  11. data/bin/asciidoctor +5 -4
  12. data/data/locale/attributes-ar.adoc +4 -3
  13. data/data/locale/attributes-be.adoc +23 -0
  14. data/data/locale/attributes-bg.adoc +4 -3
  15. data/data/locale/attributes-ca.adoc +6 -5
  16. data/data/locale/attributes-cs.adoc +4 -3
  17. data/data/locale/attributes-da.adoc +6 -5
  18. data/data/locale/attributes-de.adoc +6 -5
  19. data/data/locale/attributes-en.adoc +4 -4
  20. data/data/locale/attributes-es.adoc +6 -5
  21. data/data/locale/attributes-fa.adoc +4 -3
  22. data/data/locale/attributes-fi.adoc +4 -3
  23. data/data/locale/attributes-fr.adoc +8 -7
  24. data/data/locale/attributes-hu.adoc +4 -3
  25. data/data/locale/attributes-id.adoc +4 -3
  26. data/data/locale/attributes-it.adoc +6 -5
  27. data/data/locale/attributes-ja.adoc +4 -3
  28. data/data/locale/{attributes-kr.adoc → attributes-ko.adoc} +4 -3
  29. data/data/locale/attributes-nb.adoc +4 -3
  30. data/data/locale/attributes-nl.adoc +6 -5
  31. data/data/locale/attributes-nn.adoc +4 -3
  32. data/data/locale/attributes-pl.adoc +8 -7
  33. data/data/locale/attributes-pt.adoc +6 -5
  34. data/data/locale/attributes-pt_BR.adoc +6 -5
  35. data/data/locale/attributes-ro.adoc +4 -3
  36. data/data/locale/attributes-ru.adoc +6 -5
  37. data/data/locale/attributes-sr.adoc +4 -4
  38. data/data/locale/attributes-sr_Latn.adoc +4 -4
  39. data/data/locale/attributes-sv.adoc +4 -4
  40. data/data/locale/attributes-th.adoc +23 -0
  41. data/data/locale/attributes-tr.adoc +4 -3
  42. data/data/locale/attributes-uk.adoc +6 -5
  43. data/data/locale/attributes-vi.adoc +23 -0
  44. data/data/locale/attributes-zh_CN.adoc +4 -3
  45. data/data/locale/attributes-zh_TW.adoc +4 -3
  46. data/data/reference/syntax.adoc +296 -0
  47. data/data/stylesheets/asciidoctor-default.css +120 -114
  48. data/data/stylesheets/coderay-asciidoctor.css +15 -17
  49. data/lib/asciidoctor/abstract_block.rb +146 -140
  50. data/lib/asciidoctor/abstract_node.rb +152 -170
  51. data/lib/asciidoctor/attribute_list.rb +77 -89
  52. data/lib/asciidoctor/block.rb +29 -28
  53. data/lib/asciidoctor/callouts.rb +4 -2
  54. data/lib/asciidoctor/cli/invoker.rb +20 -24
  55. data/lib/asciidoctor/cli/options.rb +107 -96
  56. data/lib/asciidoctor/cli.rb +3 -2
  57. data/lib/asciidoctor/convert.rb +199 -0
  58. data/lib/asciidoctor/converter/composite.rb +40 -48
  59. data/lib/asciidoctor/converter/docbook5.rb +627 -644
  60. data/lib/asciidoctor/converter/html5.rb +1053 -951
  61. data/lib/asciidoctor/converter/manpage.rb +581 -532
  62. data/lib/asciidoctor/converter/template.rb +232 -271
  63. data/lib/asciidoctor/converter.rb +370 -185
  64. data/lib/asciidoctor/core_ext/float/truncate.rb +20 -0
  65. data/lib/asciidoctor/core_ext/hash/merge.rb +8 -0
  66. data/lib/asciidoctor/core_ext/match_data/names.rb +7 -0
  67. data/lib/asciidoctor/core_ext/nil_or_empty.rb +1 -0
  68. data/lib/asciidoctor/core_ext/regexp/is_match.rb +4 -2
  69. data/lib/asciidoctor/core_ext.rb +8 -17
  70. data/lib/asciidoctor/document.rb +503 -461
  71. data/lib/asciidoctor/extensions.rb +127 -174
  72. data/lib/asciidoctor/helpers.rb +184 -107
  73. data/lib/asciidoctor/inline.rb +9 -12
  74. data/lib/asciidoctor/list.rb +11 -29
  75. data/lib/asciidoctor/load.rb +119 -0
  76. data/lib/asciidoctor/logging.rb +22 -17
  77. data/lib/asciidoctor/parser.rb +673 -719
  78. data/lib/asciidoctor/path_resolver.rb +48 -33
  79. data/lib/asciidoctor/reader.rb +383 -338
  80. data/lib/asciidoctor/rouge_ext.rb +39 -0
  81. data/lib/asciidoctor/rx.rb +723 -0
  82. data/lib/asciidoctor/section.rb +17 -16
  83. data/lib/asciidoctor/stylesheets.rb +19 -37
  84. data/lib/asciidoctor/substitutors.rb +926 -1022
  85. data/lib/asciidoctor/syntax_highlighter/coderay.rb +88 -0
  86. data/lib/asciidoctor/syntax_highlighter/highlightjs.rb +34 -0
  87. data/lib/asciidoctor/syntax_highlighter/html_pipeline.rb +10 -0
  88. data/lib/asciidoctor/syntax_highlighter/prettify.rb +30 -0
  89. data/lib/asciidoctor/syntax_highlighter/pygments.rb +157 -0
  90. data/lib/asciidoctor/syntax_highlighter/rouge.rb +143 -0
  91. data/lib/asciidoctor/syntax_highlighter.rb +253 -0
  92. data/lib/asciidoctor/table.rb +152 -114
  93. data/lib/asciidoctor/timings.rb +7 -5
  94. data/lib/asciidoctor/version.rb +2 -1
  95. data/lib/asciidoctor/writer.rb +30 -0
  96. data/lib/asciidoctor.rb +266 -1340
  97. data/man/asciidoctor.1 +49 -47
  98. data/man/asciidoctor.adoc +54 -45
  99. metadata +50 -245
  100. data/CONTRIBUTING.adoc +0 -185
  101. data/Gemfile +0 -60
  102. data/Rakefile +0 -129
  103. data/bin/asciidoctor-safe +0 -15
  104. data/features/open_block.feature +0 -92
  105. data/features/pass_block.feature +0 -66
  106. data/features/step_definitions.rb +0 -49
  107. data/features/text_formatting.feature +0 -57
  108. data/features/xref.feature +0 -1039
  109. data/lib/asciidoctor/converter/base.rb +0 -59
  110. data/lib/asciidoctor/converter/docbook45.rb +0 -93
  111. data/lib/asciidoctor/converter/factory.rb +0 -226
  112. data/lib/asciidoctor/core_ext/1.8.7/base64/strict_encode64.rb +0 -6
  113. data/lib/asciidoctor/core_ext/1.8.7/concurrent/hash.rb +0 -5
  114. data/lib/asciidoctor/core_ext/1.8.7/hash/key.rb +0 -4
  115. data/lib/asciidoctor/core_ext/1.8.7/io/binread.rb +0 -6
  116. data/lib/asciidoctor/core_ext/1.8.7/io/write.rb +0 -5
  117. data/lib/asciidoctor/core_ext/1.8.7/string/chr.rb +0 -6
  118. data/lib/asciidoctor/core_ext/1.8.7/string/limit_bytesize.rb +0 -29
  119. data/lib/asciidoctor/core_ext/1.8.7/symbol/empty.rb +0 -6
  120. data/lib/asciidoctor/core_ext/1.8.7/symbol/length.rb +0 -6
  121. data/lib/asciidoctor/core_ext/string/limit_bytesize.rb +0 -10
  122. data/test/api_test.rb +0 -1240
  123. data/test/attribute_list_test.rb +0 -242
  124. data/test/attributes_test.rb +0 -1623
  125. data/test/blocks_test.rb +0 -3870
  126. data/test/converter_test.rb +0 -470
  127. data/test/document_test.rb +0 -1853
  128. data/test/extensions_test.rb +0 -1560
  129. data/test/fixtures/asciidoc_index.txt +0 -521
  130. data/test/fixtures/basic-docinfo-footer.html +0 -6
  131. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  132. data/test/fixtures/basic-docinfo.html +0 -1
  133. data/test/fixtures/basic-docinfo.xml +0 -4
  134. data/test/fixtures/basic.asciidoc +0 -5
  135. data/test/fixtures/chapter-a.adoc +0 -3
  136. data/test/fixtures/child-include.adoc +0 -5
  137. data/test/fixtures/circle.svg +0 -9
  138. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  139. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  140. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  141. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  142. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  143. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  144. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  145. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  146. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  147. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  148. data/test/fixtures/docinfo-footer.html +0 -1
  149. data/test/fixtures/docinfo-footer.xml +0 -9
  150. data/test/fixtures/docinfo.html +0 -1
  151. data/test/fixtures/docinfo.xml +0 -3
  152. data/test/fixtures/doctime-localtime.adoc +0 -2
  153. data/test/fixtures/dot.gif +0 -0
  154. data/test/fixtures/encoding.asciidoc +0 -13
  155. data/test/fixtures/file-with-missing-include.adoc +0 -1
  156. data/test/fixtures/grandchild-include.adoc +0 -3
  157. data/test/fixtures/hello-asciidoctor.pdf +0 -69
  158. data/test/fixtures/include-file.asciidoc +0 -24
  159. data/test/fixtures/include-file.jsx +0 -8
  160. data/test/fixtures/include-file.ml +0 -3
  161. data/test/fixtures/include-file.xml +0 -5
  162. data/test/fixtures/lists.adoc +0 -96
  163. data/test/fixtures/master.adoc +0 -5
  164. data/test/fixtures/mismatched-end-tag.adoc +0 -7
  165. data/test/fixtures/other-chapters.adoc +0 -11
  166. data/test/fixtures/outer-include.adoc +0 -5
  167. data/test/fixtures/parent-include-restricted.adoc +0 -5
  168. data/test/fixtures/parent-include.adoc +0 -5
  169. data/test/fixtures/sample.asciidoc +0 -30
  170. data/test/fixtures/section-a.adoc +0 -4
  171. data/test/fixtures/stylesheets/custom.css +0 -3
  172. data/test/fixtures/subdir/index.adoc +0 -3
  173. data/test/fixtures/subdir/inner-include.adoc +0 -3
  174. data/test/fixtures/subdir/middle-include.adoc +0 -5
  175. data/test/fixtures/subs-docinfo.html +0 -2
  176. data/test/fixtures/subs.adoc +0 -6
  177. data/test/fixtures/tagged-class-enclosed.rb +0 -25
  178. data/test/fixtures/tagged-class.rb +0 -23
  179. data/test/fixtures/tip.gif +0 -0
  180. data/test/fixtures/unclosed-tag.adoc +0 -3
  181. data/test/fixtures/unexpected-end-tag.adoc +0 -4
  182. data/test/invoker_test.rb +0 -745
  183. data/test/links_test.rb +0 -855
  184. data/test/lists_test.rb +0 -5151
  185. data/test/logger_test.rb +0 -211
  186. data/test/manpage_test.rb +0 -660
  187. data/test/options_test.rb +0 -262
  188. data/test/paragraphs_test.rb +0 -562
  189. data/test/parser_test.rb +0 -742
  190. data/test/paths_test.rb +0 -395
  191. data/test/preamble_test.rb +0 -173
  192. data/test/reader_test.rb +0 -2161
  193. data/test/sections_test.rb +0 -3575
  194. data/test/substitutions_test.rb +0 -2066
  195. data/test/tables_test.rb +0 -2036
  196. data/test/test_helper.rb +0 -447
  197. 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