asciidoctor 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of asciidoctor might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +85 -0
- data/README.adoc +79 -6
- data/Rakefile +22 -1
- data/benchmark/benchmark.rb +3 -1
- data/compat/asciidoc.conf +2 -2
- data/data/stylesheets/asciidoctor-default.css +3 -3
- data/features/step_definitions.rb +12 -1
- data/lib/asciidoctor.rb +74 -42
- data/lib/asciidoctor/abstract_block.rb +5 -1
- data/lib/asciidoctor/abstract_node.rb +40 -23
- data/lib/asciidoctor/attribute_list.rb +14 -5
- data/lib/asciidoctor/block.rb +45 -12
- data/lib/asciidoctor/callouts.rb +1 -0
- data/lib/asciidoctor/cli/invoker.rb +6 -2
- data/lib/asciidoctor/cli/options.rb +23 -9
- data/lib/asciidoctor/converter.rb +9 -19
- data/lib/asciidoctor/converter/base.rb +11 -14
- data/lib/asciidoctor/converter/composite.rb +8 -19
- data/lib/asciidoctor/converter/docbook45.rb +1 -0
- data/lib/asciidoctor/converter/docbook5.rb +24 -2
- data/lib/asciidoctor/converter/factory.rb +1 -0
- data/lib/asciidoctor/converter/html5.rb +61 -25
- data/lib/asciidoctor/converter/template.rb +19 -26
- data/lib/asciidoctor/document.rb +73 -45
- data/lib/asciidoctor/extensions.rb +121 -9
- data/lib/asciidoctor/helpers.rb +1 -0
- data/lib/asciidoctor/inline.rb +1 -0
- data/lib/asciidoctor/list.rb +1 -0
- data/lib/asciidoctor/opal_ext.rb +22 -0
- data/lib/asciidoctor/opal_ext/file.rb +26 -13
- data/lib/asciidoctor/parser.rb +15 -18
- data/lib/asciidoctor/path_resolver.rb +18 -0
- data/lib/asciidoctor/reader.rb +8 -9
- data/lib/asciidoctor/section.rb +5 -8
- data/lib/asciidoctor/stylesheets.rb +1 -0
- data/lib/asciidoctor/substitutors.rb +18 -18
- data/lib/asciidoctor/table.rb +2 -1
- data/lib/asciidoctor/timings.rb +1 -0
- data/lib/asciidoctor/version.rb +1 -1
- data/man/asciidoctor.1 +10 -11
- data/man/asciidoctor.adoc +80 -99
- data/test/attributes_test.rb +42 -0
- data/test/blocks_test.rb +19 -7
- data/test/document_test.rb +114 -0
- data/test/extensions_test.rb +100 -0
- data/test/fixtures/custom-docinfodir/basic-docinfo.html +1 -0
- data/test/fixtures/custom-docinfodir/docinfo.html +1 -0
- data/test/fixtures/hello-asciidoctor.pdf +0 -0
- data/test/invoker_test.rb +4 -3
- data/test/lists_test.rb +31 -5
- data/test/options_test.rb +1 -1
- data/test/paths_test.rb +21 -0
- data/test/preamble_test.rb +33 -0
- data/test/reader_test.rb +13 -0
- data/test/sections_test.rb +22 -0
- data/test/substitutions_test.rb +49 -0
- data/test/tables_test.rb +76 -0
- data/test/test_helper.rb +4 -2
- metadata +7 -5
- data/lib/asciidoctor/debug.rb +0 -25
data/test/attributes_test.rb
CHANGED
@@ -96,6 +96,34 @@ linus.torvalds@example.com
|
|
96
96
|
assert_equal '', doc.attributes['release']
|
97
97
|
end
|
98
98
|
|
99
|
+
test 'resolves attributes inside attribute value within header' do
|
100
|
+
input = <<-EOS
|
101
|
+
= Document Title
|
102
|
+
:big: big
|
103
|
+
:bigfoot: {big}foot
|
104
|
+
|
105
|
+
{bigfoot}
|
106
|
+
EOS
|
107
|
+
|
108
|
+
result = render_embedded_string input
|
109
|
+
assert result.include? 'bigfoot'
|
110
|
+
end
|
111
|
+
|
112
|
+
test 'resolves attributes and pass macro inside attribute value outside header' do
|
113
|
+
input = <<-EOS
|
114
|
+
= Document Title
|
115
|
+
|
116
|
+
content
|
117
|
+
|
118
|
+
:big: pass:a,q[_big_]
|
119
|
+
:bigfoot: {big}foot
|
120
|
+
{bigfoot}
|
121
|
+
EOS
|
122
|
+
|
123
|
+
result = render_embedded_string input
|
124
|
+
assert result.include? '<em>big</em>foot'
|
125
|
+
end
|
126
|
+
|
99
127
|
test 'resolves user-home attribute if safe mode is less than SERVER' do
|
100
128
|
input = <<-EOS
|
101
129
|
:imagesdir: {user-home}/etc/images
|
@@ -788,6 +816,20 @@ after: {counter:mycounter}
|
|
788
816
|
end
|
789
817
|
|
790
818
|
context 'Block attributes' do
|
819
|
+
test 'parses attribute names as name token' do
|
820
|
+
input = <<-EOS
|
821
|
+
[normal,foo="bar",_foo="_bar",foo1="bar1",foo-foo="bar-bar",foo.foo="bar.bar"]
|
822
|
+
content
|
823
|
+
EOS
|
824
|
+
|
825
|
+
block = block_from_string input
|
826
|
+
assert_equal 'bar', block.attr('foo')
|
827
|
+
assert_equal '_bar', block.attr('_foo')
|
828
|
+
assert_equal 'bar1', block.attr('foo1')
|
829
|
+
assert_equal 'bar-bar', block.attr('foo-foo')
|
830
|
+
assert_equal 'bar.bar', block.attr('foo.foo')
|
831
|
+
end
|
832
|
+
|
791
833
|
test 'positional attributes assigned to block' do
|
792
834
|
input = <<-EOS
|
793
835
|
[quote, author, source]
|
data/test/blocks_test.rb
CHANGED
@@ -1812,12 +1812,24 @@ video::67480300[vimeo, 400, 300, start=60, options=autoplay]
|
|
1812
1812
|
|
1813
1813
|
test 'video macro should output custom HTML with iframe for youtube service' do
|
1814
1814
|
input = <<-EOS
|
1815
|
-
video::
|
1815
|
+
video::U8GBXvdmHT4/PLg7s6cbtAD15Das5LK9mXt_g59DLWxKUe[youtube, 640, 360, start=60, options="autoplay,modest", theme=light]
|
1816
1816
|
EOS
|
1817
1817
|
output = render_embedded_string input
|
1818
1818
|
assert_css 'video', output, 0
|
1819
1819
|
assert_css 'iframe', output, 1
|
1820
|
-
assert_css 'iframe[src="//www.youtube.com/embed/
|
1820
|
+
assert_css 'iframe[src="//www.youtube.com/embed/U8GBXvdmHT4?rel=0&start=60&autoplay=1&list=PLg7s6cbtAD15Das5LK9mXt_g59DLWxKUe&modestbranding=1&theme=light"]', output, 1
|
1821
|
+
assert_css 'iframe[width="640"]', output, 1
|
1822
|
+
assert_css 'iframe[height="360"]', output, 1
|
1823
|
+
end
|
1824
|
+
|
1825
|
+
test 'video macro should output custom HTML with iframe for youtube service with dynamic playlist' do
|
1826
|
+
input = <<-EOS
|
1827
|
+
video::SCZF6I-Rc4I,AsKGOeonbIs,HwrPhOp6-aM[youtube, 640, 360, start=60, options=autoplay]
|
1828
|
+
EOS
|
1829
|
+
output = render_embedded_string input
|
1830
|
+
assert_css 'video', output, 0
|
1831
|
+
assert_css 'iframe', output, 1
|
1832
|
+
assert_css 'iframe[src="//www.youtube.com/embed/SCZF6I-Rc4I?rel=0&start=60&autoplay=1&playlist=AsKGOeonbIs,HwrPhOp6-aM"]', output, 1
|
1821
1833
|
assert_css 'iframe[width="640"]', output, 1
|
1822
1834
|
assert_css 'iframe[height="360"]', output, 1
|
1823
1835
|
end
|
@@ -1949,7 +1961,7 @@ You can use icons for admonitions by setting the 'icons' attribute.
|
|
1949
1961
|
EOS
|
1950
1962
|
|
1951
1963
|
output = render_string input, :safe => Asciidoctor::SafeMode::SERVER
|
1952
|
-
assert_css 'html > head > link[rel="stylesheet"][href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.
|
1964
|
+
assert_css 'html > head > link[rel="stylesheet"][href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"]', output, 1
|
1953
1965
|
assert_xpath '//*[@class="admonitionblock tip"]//*[@class="icon"]/i[@class="fa icon-tip"]', output, 1
|
1954
1966
|
end
|
1955
1967
|
|
@@ -1966,8 +1978,8 @@ puts "AsciiDoc, FTW!"
|
|
1966
1978
|
EOS
|
1967
1979
|
|
1968
1980
|
output = render_string input, :safe => Asciidoctor::SafeMode::SAFE
|
1969
|
-
assert_css 'html > head > link[rel="stylesheet"][href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.
|
1970
|
-
assert_css 'html > head > script[src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.
|
1981
|
+
assert_css 'html > head > link[rel="stylesheet"][href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"]', output, 1
|
1982
|
+
assert_css 'html > head > script[src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"]', output, 1
|
1971
1983
|
end
|
1972
1984
|
|
1973
1985
|
test 'should use no uri scheme for assets when asset-uri-scheme is blank' do
|
@@ -1983,8 +1995,8 @@ puts "AsciiDoc, FTW!"
|
|
1983
1995
|
EOS
|
1984
1996
|
|
1985
1997
|
output = render_string input, :safe => Asciidoctor::SafeMode::SAFE
|
1986
|
-
assert_css 'html > head > link[rel="stylesheet"][href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.
|
1987
|
-
assert_css 'html > head > script[src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.
|
1998
|
+
assert_css 'html > head > link[rel="stylesheet"][href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css"]', output, 1
|
1999
|
+
assert_css 'html > head > script[src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"]', output, 1
|
1988
2000
|
end
|
1989
2001
|
end
|
1990
2002
|
|
data/test/document_test.rb
CHANGED
@@ -133,6 +133,14 @@ context 'Document' do
|
|
133
133
|
assert_equal File.expand_path(File.dirname(sample_input_path)), doc.attr('docdir')
|
134
134
|
end
|
135
135
|
|
136
|
+
test 'should not load invalid file' do
|
137
|
+
sample_input_path = fixture_path('hello-asciidoctor.pdf')
|
138
|
+
exception = assert_raises ArgumentError do
|
139
|
+
Asciidoctor.load_file(sample_input_path, :safe => Asciidoctor::SafeMode::SAFE)
|
140
|
+
end
|
141
|
+
assert_match(/Failed to parse source/, exception.message)
|
142
|
+
end if RUBY_MIN_VERSION_1_9
|
143
|
+
|
136
144
|
test 'should load input IO' do
|
137
145
|
input = StringIO.new(<<-EOS)
|
138
146
|
Document Title
|
@@ -371,6 +379,7 @@ paragraph
|
|
371
379
|
test 'should link to default stylesheet by default when safe mode is SECURE or greater' do
|
372
380
|
sample_input_path = fixture_path('basic.asciidoc')
|
373
381
|
output = Asciidoctor.convert_file sample_input_path, :header_footer => true, :to_file => false
|
382
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 1
|
374
383
|
assert_css 'html:root > head > link[rel="stylesheet"][href="./asciidoctor.css"]', output, 1
|
375
384
|
end
|
376
385
|
|
@@ -382,6 +391,7 @@ text
|
|
382
391
|
EOS
|
383
392
|
|
384
393
|
output = Asciidoctor.render(input, :safe => Asciidoctor::SafeMode::SERVER, :header_footer => true)
|
394
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 1
|
385
395
|
assert_css 'html:root > head > link[rel="stylesheet"][href="./asciidoctor.css"]', output, 0
|
386
396
|
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
|
387
397
|
styles = stylenode.first.content
|
@@ -398,6 +408,7 @@ text
|
|
398
408
|
EOS
|
399
409
|
|
400
410
|
output = Asciidoctor.render(input, :header_footer => true)
|
411
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 1
|
401
412
|
assert_css 'html:root > head > link[rel="stylesheet"][href="./asciidoctor.css"]', output, 1
|
402
413
|
end
|
403
414
|
|
@@ -409,6 +420,7 @@ text
|
|
409
420
|
EOS
|
410
421
|
|
411
422
|
output = Asciidoctor.render(input, :header_footer => true, :attributes => {'linkcss!' => ''})
|
423
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 1
|
412
424
|
assert_css 'html:root > head > link[rel="stylesheet"][href="./asciidoctor.css"]', output, 1
|
413
425
|
end
|
414
426
|
|
@@ -431,6 +443,7 @@ text
|
|
431
443
|
EOS
|
432
444
|
|
433
445
|
output = Asciidoctor.render(input, :header_footer => true, :attributes => {'stylesheet!' => ''})
|
446
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 0
|
434
447
|
assert_css 'html:root > head > link[rel="stylesheet"]', output, 0
|
435
448
|
end
|
436
449
|
|
@@ -442,7 +455,11 @@ text
|
|
442
455
|
EOS
|
443
456
|
|
444
457
|
output = Asciidoctor.render(input, :header_footer => true, :attributes => {'stylesheet' => './custom.css'})
|
458
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href^="https://fonts.googleapis.com"]', output, 0
|
445
459
|
assert_css 'html:root > head > link[rel="stylesheet"][href="./custom.css"]', output, 1
|
460
|
+
|
461
|
+
output = Asciidoctor.render(input, :header_footer => true, :attributes => {'stylesheet' => 'file:///home/username/custom.css'})
|
462
|
+
assert_css 'html:root > head > link[rel="stylesheet"][href="file:///home/username/custom.css"]', output, 1
|
446
463
|
end
|
447
464
|
|
448
465
|
test 'should resolve custom stylesheet relative to stylesdir' do
|
@@ -636,6 +653,34 @@ text
|
|
636
653
|
assert_css 'meta[http-equiv="imagetoolbar"]', output, 1
|
637
654
|
end
|
638
655
|
|
656
|
+
test 'should include docinfo files for html backend with custom docinfodir' do
|
657
|
+
sample_input_path = fixture_path('basic.asciidoc')
|
658
|
+
|
659
|
+
output = Asciidoctor.convert_file sample_input_path, :to_file => false,
|
660
|
+
:header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo' => '', 'docinfodir' => 'custom-docinfodir'}
|
661
|
+
assert !output.empty?
|
662
|
+
assert_css 'script[src="bootstrap.js"]', output, 1
|
663
|
+
assert_css 'meta[name="robots"]', output, 0
|
664
|
+
|
665
|
+
output = Asciidoctor.convert_file sample_input_path, :to_file => false,
|
666
|
+
:header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo1' => '', 'docinfodir' => 'custom-docinfodir'}
|
667
|
+
assert !output.empty?
|
668
|
+
assert_css 'script[src="bootstrap.js"]', output, 0
|
669
|
+
assert_css 'meta[name="robots"]', output, 1
|
670
|
+
|
671
|
+
output = Asciidoctor.convert_file sample_input_path, :to_file => false,
|
672
|
+
:header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => '', 'docinfodir' => './custom-docinfodir'}
|
673
|
+
assert !output.empty?
|
674
|
+
assert_css 'script[src="bootstrap.js"]', output, 1
|
675
|
+
assert_css 'meta[name="robots"]', output, 1
|
676
|
+
|
677
|
+
output = Asciidoctor.convert_file sample_input_path, :to_file => false,
|
678
|
+
:header_footer => true, :safe => Asciidoctor::SafeMode::SERVER, :attributes => {'docinfo2' => '', 'docinfodir' => 'custom-docinfodir/subfolder'}
|
679
|
+
assert !output.empty?
|
680
|
+
assert_css 'script[src="bootstrap.js"]', output, 0
|
681
|
+
assert_css 'meta[name="robots"]', output, 0
|
682
|
+
end
|
683
|
+
|
639
684
|
test 'should include docinfo files for docbook backend' do
|
640
685
|
sample_input_path = fixture_path('basic.asciidoc')
|
641
686
|
|
@@ -1441,6 +1486,36 @@ section body
|
|
1441
1486
|
refute_match(RE_XMLNS_ATTRIBUTE, result)
|
1442
1487
|
end
|
1443
1488
|
|
1489
|
+
test 'docbook45 backend doctype manpage' do
|
1490
|
+
input = <<-EOS
|
1491
|
+
= asciidoctor(1)
|
1492
|
+
|
1493
|
+
== NAME
|
1494
|
+
|
1495
|
+
asciidoctor - Process text
|
1496
|
+
|
1497
|
+
== SYNOPSIS
|
1498
|
+
|
1499
|
+
some text
|
1500
|
+
|
1501
|
+
== First Section
|
1502
|
+
|
1503
|
+
section body
|
1504
|
+
EOS
|
1505
|
+
result = render_string(input, :attributes => {'backend' => 'docbook45', 'doctype' => 'manpage'})
|
1506
|
+
assert_xpath '/refentry', result, 1
|
1507
|
+
assert_xpath '/refentry/refentryinfo/title[text() = "asciidoctor(1)"]', result, 1
|
1508
|
+
assert_xpath '/refentry/refmeta/refentrytitle[text() = "asciidoctor"]', result, 1
|
1509
|
+
assert_xpath '/refentry/refmeta/manvolnum[text() = "1"]', result, 1
|
1510
|
+
assert_xpath '/refentry/refnamediv/refname[text() = "asciidoctor"]', result, 1
|
1511
|
+
assert_xpath '/refentry/refnamediv/refpurpose[text() = "Process text"]', result, 1
|
1512
|
+
assert_xpath '/refentry/refsynopsisdiv', result, 1
|
1513
|
+
assert_xpath '/refentry/refsynopsisdiv/simpara[text() = "some text"]', result, 1
|
1514
|
+
assert_xpath '/refentry/refsection', result, 1
|
1515
|
+
assert_xpath '/refentry/refsection[@id = "_first_section"]/title[text() = "First Section"]', result, 1
|
1516
|
+
assert_xpath '/refentry/refsection[@id = "_first_section"]/simpara[text() = "section body"]', result, 1
|
1517
|
+
end
|
1518
|
+
|
1444
1519
|
test 'docbook45 backend doctype book' do
|
1445
1520
|
input = <<-EOS
|
1446
1521
|
= Title
|
@@ -1515,6 +1590,45 @@ section body
|
|
1515
1590
|
assert_equal '_first_section', id_attr.value
|
1516
1591
|
end
|
1517
1592
|
|
1593
|
+
test 'docbook5 backend doctype manpage' do
|
1594
|
+
input = <<-EOS
|
1595
|
+
= asciidoctor(1)
|
1596
|
+
|
1597
|
+
== NAME
|
1598
|
+
|
1599
|
+
asciidoctor - Process text
|
1600
|
+
|
1601
|
+
== SYNOPSIS
|
1602
|
+
|
1603
|
+
some text
|
1604
|
+
|
1605
|
+
== First Section
|
1606
|
+
|
1607
|
+
section body
|
1608
|
+
EOS
|
1609
|
+
result = render_string(input, :keep_namespaces => true, :attributes => {'backend' => 'docbook5', 'doctype' => 'manpage'})
|
1610
|
+
assert_xpath '/xmlns:refentry', result, 1
|
1611
|
+
doc = xmlnodes_at_xpath('/xmlns:refentry', result, 1).first
|
1612
|
+
assert_equal 'http://docbook.org/ns/docbook', doc.namespaces['xmlns']
|
1613
|
+
assert_equal 'http://www.w3.org/1999/xlink', doc.namespaces['xmlns:xlink']
|
1614
|
+
assert_xpath '/xmlns:refentry[@version="5.0"]', result, 1
|
1615
|
+
assert_xpath '/xmlns:refentry/xmlns:info/xmlns:title[text() = "asciidoctor(1)"]', result, 1
|
1616
|
+
assert_xpath '/xmlns:refentry/xmlns:refmeta/xmlns:refentrytitle[text() = "asciidoctor"]', result, 1
|
1617
|
+
assert_xpath '/xmlns:refentry/xmlns:refmeta/xmlns:manvolnum[text() = "1"]', result, 1
|
1618
|
+
assert_xpath '/xmlns:refentry/xmlns:refnamediv/xmlns:refname[text() = "asciidoctor"]', result, 1
|
1619
|
+
assert_xpath '/xmlns:refentry/xmlns:refnamediv/xmlns:refpurpose[text() = "Process text"]', result, 1
|
1620
|
+
assert_xpath '/xmlns:refentry/xmlns:refsynopsisdiv', result, 1
|
1621
|
+
assert_xpath '/xmlns:refentry/xmlns:refsynopsisdiv/xmlns:simpara[text() = "some text"]', result, 1
|
1622
|
+
assert_xpath '/xmlns:refentry/xmlns:refsection', result, 1
|
1623
|
+
section = xmlnodes_at_xpath('/xmlns:refentry/xmlns:refsection', result, 1).first
|
1624
|
+
# nokogiri can't make up its mind
|
1625
|
+
id_attr = section.attribute('id') || section.attribute('xml:id')
|
1626
|
+
refute_nil id_attr
|
1627
|
+
refute_nil id_attr.namespace
|
1628
|
+
assert_equal 'xml', id_attr.namespace.prefix
|
1629
|
+
assert_equal '_first_section', id_attr.value
|
1630
|
+
end
|
1631
|
+
|
1518
1632
|
test 'docbook5 backend doctype book' do
|
1519
1633
|
input = <<-EOS
|
1520
1634
|
= Title
|
data/test/extensions_test.rb
CHANGED
@@ -14,6 +14,9 @@ end
|
|
14
14
|
class SampleIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
|
15
15
|
end
|
16
16
|
|
17
|
+
class SampleDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor
|
18
|
+
end
|
19
|
+
|
17
20
|
class SampleTreeprocessor < Asciidoctor::Extensions::Treeprocessor
|
18
21
|
end
|
19
22
|
|
@@ -114,6 +117,21 @@ class TemperatureMacro < Asciidoctor::Extensions::InlineMacroProcessor; use_dsl
|
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
120
|
+
class MetaRobotsDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor
|
121
|
+
def process document
|
122
|
+
'<meta name="robots" content="index,follow">'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class MetaAppDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor
|
127
|
+
use_dsl
|
128
|
+
at_location :header
|
129
|
+
|
130
|
+
def process document
|
131
|
+
'<meta name="application-name" content="Asciidoctor App">'
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
117
135
|
class SampleExtensionGroup < Asciidoctor::Extensions::Group
|
118
136
|
def activate registry
|
119
137
|
registry.document.attributes['activate-method-called'] = ''
|
@@ -287,6 +305,19 @@ context 'Extensions' do
|
|
287
305
|
assert extensions.first.process_method.is_a? ::Method
|
288
306
|
end
|
289
307
|
|
308
|
+
test 'should instantiate docinfo processors' do
|
309
|
+
registry = Asciidoctor::Extensions::Registry.new
|
310
|
+
registry.docinfo_processor SampleDocinfoProcessor
|
311
|
+
registry.activate Asciidoctor::Document.new
|
312
|
+
assert registry.docinfo_processors?
|
313
|
+
assert registry.docinfo_processors?(:header)
|
314
|
+
extensions = registry.docinfo_processors
|
315
|
+
assert_equal 1, extensions.size
|
316
|
+
assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
|
317
|
+
assert extensions.first.instance.is_a? SampleDocinfoProcessor
|
318
|
+
assert extensions.first.process_method.is_a? ::Method
|
319
|
+
end
|
320
|
+
|
290
321
|
test 'should instantiate treeprocessors' do
|
291
322
|
registry = Asciidoctor::Extensions::Registry.new
|
292
323
|
registry.treeprocessor SampleTreeprocessor
|
@@ -614,5 +645,74 @@ content
|
|
614
645
|
Asciidoctor::Extensions.unregister_all
|
615
646
|
end
|
616
647
|
end
|
648
|
+
|
649
|
+
test 'should add docinfo to document' do
|
650
|
+
input = <<-EOS
|
651
|
+
= Document Title
|
652
|
+
|
653
|
+
sample content
|
654
|
+
EOS
|
655
|
+
|
656
|
+
begin
|
657
|
+
Asciidoctor::Extensions.register do
|
658
|
+
docinfo_processor MetaRobotsDocinfoProcessor
|
659
|
+
end
|
660
|
+
|
661
|
+
doc = document_from_string input, :safe => :server
|
662
|
+
assert_equal '<meta name="robots" content="index,follow">', doc.docinfo
|
663
|
+
ensure
|
664
|
+
Asciidoctor::Extensions.unregister_all
|
665
|
+
end
|
666
|
+
end
|
667
|
+
|
668
|
+
|
669
|
+
test 'should add multiple docinfo to document' do
|
670
|
+
input = <<-EOS
|
671
|
+
= Document Title
|
672
|
+
|
673
|
+
sample content
|
674
|
+
EOS
|
675
|
+
|
676
|
+
begin
|
677
|
+
Asciidoctor::Extensions.register do
|
678
|
+
docinfo_processor MetaAppDocinfoProcessor
|
679
|
+
docinfo_processor MetaRobotsDocinfoProcessor, :position => :>>
|
680
|
+
docinfo_processor do
|
681
|
+
at_location :footer
|
682
|
+
process do |doc|
|
683
|
+
'<script><!-- analytics code --></script>'
|
684
|
+
end
|
685
|
+
end
|
686
|
+
end
|
687
|
+
|
688
|
+
doc = document_from_string input, :safe => :server
|
689
|
+
assert_equal '<meta name="robots" content="index,follow">
|
690
|
+
<meta name="application-name" content="Asciidoctor App">', doc.docinfo(:header)
|
691
|
+
assert_equal '<script><!-- analytics code --></script>', doc.docinfo(:footer)
|
692
|
+
ensure
|
693
|
+
Asciidoctor::Extensions.unregister_all
|
694
|
+
end
|
695
|
+
end
|
696
|
+
|
697
|
+
|
698
|
+
test 'should append docinfo to document' do
|
699
|
+
begin
|
700
|
+
Asciidoctor::Extensions.register do
|
701
|
+
docinfo_processor MetaRobotsDocinfoProcessor
|
702
|
+
end
|
703
|
+
sample_input_path = fixture_path('basic.asciidoc')
|
704
|
+
|
705
|
+
output = Asciidoctor.convert_file sample_input_path, :to_file => false,
|
706
|
+
:header_footer => true,
|
707
|
+
:safe => Asciidoctor::SafeMode::SERVER,
|
708
|
+
:attributes => {'docinfo' => ''}
|
709
|
+
assert !output.empty?
|
710
|
+
assert_css 'script[src="modernizr.js"]', output, 1
|
711
|
+
assert_css 'meta[name="robots"]', output, 1
|
712
|
+
assert_css 'meta[http-equiv="imagetoolbar"]', output, 0
|
713
|
+
ensure
|
714
|
+
Asciidoctor::Extensions.unregister_all
|
715
|
+
end
|
716
|
+
end
|
617
717
|
end
|
618
718
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<script src="bootstrap.js"></script>
|
@@ -0,0 +1 @@
|
|
1
|
+
<meta name="robots" content="index,follow">
|
Binary file
|
data/test/invoker_test.rb
CHANGED
@@ -108,7 +108,8 @@ context 'Invoker' do
|
|
108
108
|
invoke_cli [switch]
|
109
109
|
actual = out.string.rstrip
|
110
110
|
end
|
111
|
-
|
111
|
+
refute_nil actual
|
112
|
+
assert actual.start_with?(expected), %(Expected to print version when using #{switch} switch)
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -148,7 +149,7 @@ context 'Invoker' do
|
|
148
149
|
test 'should report error if input file does not exist' do
|
149
150
|
redirect_streams do |out, err|
|
150
151
|
invoker = invoke_cli [], 'missing_file.asciidoc'
|
151
|
-
assert_match(/input file .* missing/, err.string)
|
152
|
+
assert_match(/input file .* missing or cannot be read/, err.string)
|
152
153
|
assert_equal 1, invoker.code
|
153
154
|
end
|
154
155
|
end
|
@@ -156,7 +157,7 @@ context 'Invoker' do
|
|
156
157
|
test 'should treat extra arguments as files' do
|
157
158
|
redirect_streams do |out, err|
|
158
159
|
invoker = invoke_cli %w(-o /dev/null extra arguments sample.asciidoc), nil
|
159
|
-
assert_match(/input file .* missing/, err.string)
|
160
|
+
assert_match(/input file .* missing or cannot be read/, err.string)
|
160
161
|
assert_equal 1, invoker.code
|
161
162
|
end
|
162
163
|
end
|