-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathjekyll-asciidoc_spec.rb
1377 lines (1171 loc) · 50.8 KB
/
jekyll-asciidoc_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require_relative 'spec_helper'
describe 'Jekyll::AsciiDoc' do
let :config do
::Jekyll.configuration fixture_site_params name
end
let :site do
::Jekyll::Site.new config
end
let :converter do
::Jekyll::AsciiDoc::Converter.get_instance site
end
let :integrator do
::Jekyll::AsciiDoc::Integrator.get_instance site
end
describe 'default configuration' do
use_fixture :default_config
before :each do
site.object_id
end
it 'should register AsciiDoc converter' do
(expect site.converters.any? {|c| ::Jekyll::AsciiDoc::Converter === c }).to be true
end
it 'should register AsciiDoc generator' do
(expect site.generators.any? {|g| ::Jekyll::AsciiDoc::Integrator === g }).to be true
end
it 'should configure AsciiDoc converter to match AsciiDoc file extension' do
(expect converter).not_to be_nil
(expect converter.matches '.adoc').to be_truthy
end
it 'should use .html as output extension' do
(expect converter).not_to be_nil
(expect converter.output_ext '.adoc').to eql('.html')
end
it 'should mark configuration as configured to prevent duplicate initialization' do
(expect (asciidoc_config = site.config['asciidoc'])).to be_a ::Jekyll::AsciiDoc::Configured
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Jekyll::AsciiDoc::Configured
site.reset
site.setup
(expect site.config['asciidoc'].object_id).to eql asciidoc_config.object_id
(expect site.config['asciidoctor'].object_id).to eql asciidoctor_config.object_id
end
it 'should use Asciidoctor to process AsciiDoc files by default' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['processor']).to eql 'asciidoctor'
end
it 'should match AsciiDoc file extensions asciidoc,adoc,ad by default' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['ext']).to eql 'asciidoc,adoc,ad'
end
it 'should use page- as page attribute prefix by default' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['page_attribute_prefix']).to eql 'page-'
end
it 'should not require a front matter header by default' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['require_front_matter_header']).to be false
end
it 'should use Asciidoctor in safe mode by default' do
(expect site.config['asciidoctor']).to be_a ::Hash
(expect site.config['asciidoctor'][:safe]).to eql 'safe'
end
it 'should pass implicit attributes to Asciidoctor' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['env']).to eql 'site'
(expect attrs['env-site']).to eql ''
(expect attrs['site-gen']).to eql 'jekyll'
(expect attrs['site-gen-jekyll']).to eql ''
(expect attrs['builder']).to eql 'jekyll'
(expect attrs['builder-jekyll']).to eql ''
(expect attrs['jekyll-version']).to eql ::Jekyll::VERSION
end
it 'should should pass site attributes to Asciidoctor' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['site-root']).to eql ::Dir.pwd
(expect attrs['site-source']).to eql site.source
(expect attrs['site-destination']).to eql site.dest
(expect attrs['site-baseurl']).to eql site.config['baseurl']
(expect attrs['site-url']).to eql 'http://example.org'
end
end
describe 'legacy configuration' do
use_fixture :legacy_config
before :each do
site.object_id
end
it 'should allow processor to be set using asciidoc key' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['processor']).to eql 'asciidoctor'
end
it 'should migrate asciidoc_ext key' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['ext']).to eql 'adoc'
end
it 'should migrate asciidoc_page_attribute_prefix key' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['page_attribute_prefix']).to eql 'jekyll-'
end
end
describe 'hybrid configuration' do
use_fixture :hybrid_config
before :each do
site.object_id
end
it 'should use new key for ext over legacy key' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['ext']).to eql 'asciidoc,adoc'
end
it 'should use new key page_attribute_prefix over legacy key' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['page_attribute_prefix']).to eql 'pg-'
end
end
describe 'parse YAML value' do
use_fixture :default_config
before :each do
site.object_id
end
it 'should parse string as YAML value' do
(expect integrator.send :parse_yaml_value, '').to eql ''
(expect integrator.send :parse_yaml_value, 'true').to be true
(expect integrator.send :parse_yaml_value, 'false').to be false
(expect integrator.send :parse_yaml_value, '~').to be_nil
(expect integrator.send :parse_yaml_value, '1').to eql 1
(expect integrator.send :parse_yaml_value, '[one, two]').to eql %w(one two)
(expect integrator.send :parse_yaml_value, 'John\'s House').to eql 'John\'s House'
(expect integrator.send :parse_yaml_value, '\'bar\'').to eql 'bar'
(expect integrator.send :parse_yaml_value, '\'').to eql ?'
(expect integrator.send :parse_yaml_value, '-').to eql '-'
(expect integrator.send :parse_yaml_value, '@').to eql '@'
end
end
describe 'imagesdir relative to root' do
use_fixture :imagesdir_relative_to_root
before :each do
site.object_id
end
it 'should set imagesoutdir if imagesdir is relative to root' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['imagesdir']).to eql '/images@'
imagesoutdir_expected = ::File.join site.dest, (attrs['imagesdir'].chomp '@')
(expect attrs['imagesoutdir']).to eql imagesoutdir_expected
end
end
describe 'imagesdir not set' do
use_fixture :default_config
before :each do
site.object_id
end
it 'should not set imagesoutdir if imagesdir is not set' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect (attrs.key? 'imagesdir')).to be false
(expect (attrs.key? 'imagesoutdir')).to be false
end
end
describe 'compile attributes' do
use_fixture :default_config
before :each do
site.object_id
end
it 'should assign nil value to attribute for attribute with nil value' do
result = converter.send :compile_attributes, 'icons' => nil
(expect (result.key? 'icons')).to be true
(expect result['icons']).to be_nil
end
it 'should transform negated attribute with trailing ! to attribute with nil value' do
result = converter.send :compile_attributes, 'icons!' => ''
(expect (result.key? 'icons')).to be true
(expect result['icons']).to be_nil
end
it 'should transform negated attribute with leading ! to attribute with nil value' do
result = converter.send :compile_attributes, '!icons' => ''
(expect (result.key? 'icons')).to be true
(expect result['icons']).to be_nil
end
it 'should set existing attribute to nil when attribute is unset' do
result = converter.send :compile_attributes, 'icons' => 'font', '!icons' => ''
(expect (result.key? 'icons')).to be true
(expect result['icons']).to be_nil
end
it 'should assign value to existing attribute when set again' do
result = converter.send :compile_attributes, %w(!icons icons=font !source-highlighter source-highlighter=coderay)
(expect result['icons']).to eql 'font'
(expect result['source-highlighter']).to eql 'coderay'
end
it 'should resolve attribute references in attribute value' do
result = converter.send :compile_attributes,
'foo' => 'foo', 'bar' => 'bar', 'bäz' => nil, 'foobar' => '{foo}{bar}{bäz}'
(expect result['foobar']).to eql 'foobar'
end
it 'should drop trailing @ from value when resolving attribute reference' do
result = converter.send :compile_attributes,
'foo' => 'foo@', 'bar' => 'bar@', 'baz' => '@', 'foobar' => '{foo}{bar}{baz}'
(expect result['foobar']).to eql 'foobar'
end
it 'should not resolve escaped attribute reference' do
result = converter.send :compile_attributes, 'foo' => 'foo', 'bar' => 'bar', 'foobar' => '{foo}\{bar}'
(expect result['foobar']).to eql 'foo{bar}'
end
it 'should leave unresolved attribute reference in place' do
result = converter.send :compile_attributes, 'foo' => 'foo', 'foobar' => '{foo}{bar}'
(expect result['foobar']).to eql 'foo{bar}'
end
it 'should remove matching attribute if attribute starts with minus' do
initial_attrs = { 'idseparator' => '-' }
override_attrs = { '-idseparator' => '' }
result = converter.send :compile_attributes, override_attrs, initial_attrs
(expect result).to be_empty
end
it 'should not fail if attribute to be removed does not exist' do
result = converter.send :compile_attributes, '-idseparator' => ''
(expect result).to be_empty
end
it 'should assign empty string to attribute if value is true' do
result = converter.send :compile_attributes, 'icons' => true
(expect result['icons']).to eql ''
end
it 'should assign nil value to attribute if value is false' do
result = converter.send :compile_attributes, 'icons' => false
(expect (result.key? 'icons')).to be true
(expect result['icons']).to be_nil
end
it 'should assign numeric value as string if value is numeric' do
result = converter.send :compile_attributes, 'count' => 1
(expect result['count']).to eql'1'
end
it 'should pass through Date value to attribute if value is Date' do
date = ::Date.parse '2016-01-01'
result = converter.send :compile_attributes, 'localdate' => date
(expect result['localdate']).to eql date
end
end
describe 'attributes as hash' do
use_fixture :attributes_as_hash
before :each do
site.object_id
end
it 'should merge attributes defined as a Hash into the attributes Hash' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['env']).to eql 'site'
(expect attrs['icons']).to eql 'font'
(expect attrs['sectanchors']).to eql ''
(expect (attrs.key? 'table-caption')).to be true
(expect attrs['table-caption']).to be_nil
end
end
describe 'attributes as array' do
use_fixture :attributes_as_array
before :each do
site.object_id
end
it 'should merge attributes defined as an Array into the attributes Hash' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['env']).to eql 'site'
(expect attrs['icons']).to eql 'font'
(expect attrs['sectanchors']).to eql ''
(expect (attrs.key? 'table-caption')).to be true
(expect attrs['table-caption']).to be_nil
end
end
describe 'alternate page attribute prefix' do
use_fixture :alternate_page_attribute_prefix
before :each do
site.process
end
it 'should strip trailing hyphen from page attribute prefix config value' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['page_attribute_prefix']).to eql 'jekyll-'
end
it 'should recognize page attributes with alternate page attribute prefix' do
page = find_page 'explicit-permalink.adoc'
(expect page).not_to be_nil
(expect page.permalink).to eql '/permalink/'
file = output_file 'permalink/index.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<div class="page-content">'
(expect contents).not_to include %(<meta name="generator" content="Asciidoctor #{::Asciidoctor::VERSION}">)
end
end
describe 'blank page attribute prefix' do
use_fixture :blank_page_attribute_prefix
before :each do
site.process
end
it 'should coerce null value for page attribute prefix to empty string' do
(expect site.config['asciidoc']).to be_a ::Hash
(expect site.config['asciidoc']['page_attribute_prefix']).to eql ''
end
it 'should recognize page attributes with no page attribute prefix' do
page = find_page 'explicit-permalink.adoc'
(expect page).not_to be_nil
(expect page.permalink).to eql '/permalink/'
file = output_file 'permalink/index.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<div class="page-content">'
(expect contents).not_to include %(<meta name="generator" content="Asciidoctor #{::Asciidoctor::VERSION}">)
end
end
describe 'basic site' do
use_fixture :basic_site
before :each do
site.process
end
it 'should add an implicit YAML header to a plain AsciiDoc file' do
file = source_file 'without-front-matter-header.adoc'
(expect (::Jekyll::Utils.has_yaml_header? file)).to be true
end
it 'should convert a plain AsciiDoc file' do
file = output_file 'without-front-matter-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Lorem ipsum.</p>'
end
it 'should promote AsciiDoc document title to page title' do
file = output_file 'without-front-matter-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Page Title</title>'
end
it 'should convert an AsciiDoc with no doctitle or AsciiDoc header' do
page = find_page 'no-doctitle.adoc'
(expect page).not_to be_nil
(expect (page.data.key? 'title')).to be false
file = output_file 'no-doctitle.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Site Title</title>'
(expect contents).to include %(<p>Just content.\nLorem ipsum.</p>)
end
it 'should convert an AsciiDoc that has an AsciiDoc header, but no doctitle' do
page = find_page 'bare-header.adoc'
(expect page).not_to be_nil
(expect (page.data.key? 'title')).to be false
(expect page.permalink).to eql '/bare/'
file = output_file 'bare/index.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Site Title</title>'
(expect contents).to include %(<p>Just content.\nLorem ipsum.</p>)
end
it 'should report an AsciiDoc file with a front matter header as having a YAML header' do
file = source_file 'with-front-matter-header.adoc'
(expect (::Jekyll::Utils.has_yaml_header? file)).to be true
end
it 'should convert an AsciiDoc file with a front matter header' do
file = output_file 'with-front-matter-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Page Title</title>'
(expect contents).to include '<p>Lorem ipsum.</p>'
end
it 'should convert an AsciiDoc file that has only an AsciiDoc header, no body' do
file = output_file 'with-header-only.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Header Only</title>'
(expect contents).to include %(<div class="page-content">\n\n</div>)
end
it 'should convert an AsciiDoc file that has only a front matter header, no body' do
file = output_file 'with-front-matter-header-only.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Front Matter Only</title>'
(expect contents).to include %(<div class="page-content">\n\n</div>)
end
it 'should apply explicit id and role attributes on section titles' do
file = output_file 'section-with-id-and-role.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(<div class="sect1 section-role">\n<h2 id="section-id">Section Title</h2>)
end
it 'should assign AsciiDoc document id, if set, to docid page attribute' do
page = find_page 'docid.adoc'
(expect page).not_to be_nil
(expect (page.data.key? 'docid')).to be true
(expect page.data['docid']).to eq 'page-id'
end
it 'should not use Liquid preprocessor by default' do
file = output_file 'no-liquid.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>{{ page.title }}</p>'
end
it 'should enable Liquid preprocessor if liquid page variable is set' do
file = output_file 'liquid-enabled-front-matter.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Liquid Enabled</p>'
end
it 'should enable Liquid preprocessor if page-liquid page attribute is set' do
file = output_file 'liquid-enabled-asciidoc-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Liquid Enabled</p>'
end
it 'should not publish a page if the published page variable is set in the AsciiDoc header' do
file = output_file 'not-published.html'
(expect ::File).not_to exist file
end
it 'should output a standalone HTML page if the page-layout attribute is unset' do
file = output_file 'standalone-a.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(<meta name="generator" content="Asciidoctor #{::Asciidoctor::VERSION}">)
(expect contents).to include '<title>Standalone Page A</title>'
(expect contents).to include '<h1>Standalone Page A</h1>'
end
it 'should output a standalone HTML page if the page-layout attribute is false' do
file = output_file 'standalone-b.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(<meta name="generator" content="Asciidoctor #{::Asciidoctor::VERSION}">)
(expect contents).to include '<title>Standalone Page B</title>'
(expect contents).to include '<h1>Standalone Page B</h1>'
end
it 'should apply layout named page to page content if page-layout attribute not specified' do
file = output_file 'without-front-matter-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for page layout.</p>'
end
it 'should apply layout named page to page content if page-layout attribute is empty' do
file = output_file 'empty-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for page layout.</p>'
end
it 'should apply layout named page to page content if page-layout attribute has value _auto' do
file = output_file 'auto-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for page layout.</p>'
end
it 'should apply specified layout to page content if page-layout has non-empty string value' do
file = output_file 'custom-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for custom layout.</p>'
end
it 'should not apply a layout to page content if page-layout attribute is nil' do
file = output_file 'nil-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include(%(div class="paragraph">\n<p>Lorem ipsum.</p>\n</div>))
end
it 'should convert an empty page attribute value to empty string' do
page = find_page 'empty-page-attribute.adoc'
(expect page).not_to be_nil
(expect page.data['attribute-with-empty-value']).to eql ''
end
it 'should resolve docdir as base_dir if base_dir value is not :docdir' do
src_file = source_file 'subdir/page-in-subdir.adoc'
out_file = output_file 'subdir/page-in-subdir.html'
(expect ::File).to exist out_file
contents = ::File.read out_file
(expect contents).to include %(docdir=#{::Dir.pwd})
(expect contents).to include %(docfile=#{src_file})
(expect contents).to include %(docname=#{::File.basename src_file, '.adoc'})
end
it 'should only register pre and post render hooks once' do
hooks_registry = ::Jekyll::Hooks.instance_variable_get :@registry
owned_by_plugin = proc do |hooks|
hooks.select {|it| it.source_location[0].end_with? '/jekyll-asciidoc/converter.rb' }
end
(expect owned_by_plugin[hooks_registry[:pages][:pre_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:pages][:post_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:documents][:pre_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:documents][:post_render]].size).to eql 1
site.process
(expect owned_by_plugin[hooks_registry[:pages][:pre_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:pages][:post_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:documents][:pre_render]].size).to eql 1
(expect owned_by_plugin[hooks_registry[:documents][:post_render]].size).to eql 1
end
end
describe 'use site-wide standalone layout' do
use_fixture :site_wide_standalone_layout
before :each do
site.process
end
it 'should output a standalone HTML page if the page-layout attribute is false in site config' do
file = output_file 'standalone.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(<meta name="generator" content="Asciidoctor #{::Asciidoctor::VERSION}">)
(expect contents).to include '<title>Standalone Page</title>'
(expect contents).to include '<h1>Standalone Page</h1>'
end
end
describe 'use site-wide fallback layout' do
use_fixture :site_wide_fallback_layout
before :each do
site.process
end
it 'should use layout defined in front matter if page-layout is soft set in site config' do
file = output_file 'in-front-matter.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for simple layout.</p>'
end
it 'should use layout defined in AsciiDoc header if page-layout is soft set in site config' do
file = output_file 'in-asciidoc-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for simple layout.</p>'
end
it 'should use layout defined in site config if not set in page' do
file = output_file 'not-set.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for default layout.</p>'
end
end
describe 'explicit site time' do
use_fixture :explicit_site_time
before :each do
site.process
end
it 'should set localdatetime on AsciiDoc pages to match site time and time zone' do
(expect (asciidoctor_config = site.config['asciidoctor'])).to be_a ::Hash
(expect (attrs = asciidoctor_config[:attributes])).to be_a ::Hash
(expect attrs['localdate']).to eql (site.time.strftime '%Y-%m-%d')
(expect attrs['localtime']).to eql (site.time.strftime '%H:%M:%S %Z')
file = output_file 'home.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(localdatetime=#{site.time.strftime '%Y-%m-%d %H:%M:%S %Z'})
end
end
describe 'safe mode' do
use_fixture :safe_mode
before :each do
site.process
end
it 'should register converter and generator when running in safe mode' do
(expect site.converters.any? {|c| ::Jekyll::AsciiDoc::Converter === c }).to be true
(expect site.generators.any? {|g| ::Jekyll::AsciiDoc::Integrator === g }).to be true
end
it 'should convert AsciiDoc file when running in safe mode' do
file = output_file 'home.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Home Page</title>'
(expect contents).to include '<p>Footer for home layout.</p>'
end
end
describe 'use default as fallback layout' do
use_fixture :fallback_to_default_layout
before :each do
site.process
end
it 'should use default layout for page if page layout is not available' do
file = output_file 'home.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for default layout.</p>'
end
it 'should use default layout for post if post layout is not available' do
file = output_file '2016/01/01/post.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for default layout.</p>'
end
it 'should use default layout for document if layout for document collection is not available' do
file = output_file 'blueprints/blueprint.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for default layout.</p>'
end
end
describe 'use front matter defaults' do
use_fixture :front_matter_defaults
before :each do
site.process
end
it 'should use the layout for the default scope when no layout is specified' do
file = output_file 'page.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for general layout.</p>'
end
it 'should use the layout for the matching scope when no layout is specified' do
file = output_file 'docs/page.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for docs layout.</p>'
end
end
describe 'require front matter header' do
use_fixture :require_front_matter_header
before :each do
site.process
end
it 'should consider an AsciiDoc file with a front matter header to have a YAML header' do
file = source_file 'with-front-matter-header.adoc'
(expect (::Jekyll::Utils.has_yaml_header? file)).to be true
end
it 'should not consider an AsciiDoc file without a front matter header to have a YAML header' do
file = source_file 'without-front-matter-header.adoc'
(expect (::Jekyll::Utils.has_yaml_header? file)).to be false
end
it 'should convert an AsciiDoc file with a front matter header' do
file = output_file 'with-front-matter-header.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Page Title</title>'
(expect contents).to include '<p>Lorem ipsum.</p>'
end
it 'should not convert an AsciiDoc file without a front matter header' do
file = output_file 'without-front-matter-header.adoc'
(expect ::File).to exist file
end
end
describe 'site with posts' do
use_fixture :with_posts
before :each do
site.show_drafts = true
site.process
end
it 'should use document title as post title' do
post = find_post '2016-01-01-welcome.adoc'
(expect post).not_to be_nil
(expect post.data['title']).to eql 'Welcome, Visitor!'
file = output_file '2016/01/01/welcome.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Welcome, Visitor!</title>'
(expect contents).not_to include '<h1>Welcome, Visitor!</h1>'
end
it 'should use automatic title if no document title is given' do
post = find_post '2016-05-31-automatic-title.adoc'
(expect post).not_to be_nil
(expect post.data['title']).to eql 'Automatic Title'
file = output_file '2016/05/31/automatic-title.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Automatic Title</title>'
end
it 'should set author of post to value defined in AsciiDoc header' do
post = find_post '2016-01-01-welcome.adoc'
(expect post).not_to be_nil
(expect post.data['author']).to eql 'Henry Jekyll'
end
it 'should apply layout named post to post content if page-layout attribute not specified' do
file = output_file '2016/01/01/welcome.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for post layout.</p>'
end
it 'should apply layout named post to post content if page-layout attribute is empty' do
file = output_file '2016/01/02/empty-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for post layout.</p>'
end
it 'should apply layout named post to post content if page-layout attribute has value _auto' do
file = output_file '2016/01/03/auto-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for post layout.</p>'
end
it 'should apply custom layout to post content if page-layout attribute has non-empty string value' do
file = output_file '2016/01/04/custom-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<p>Footer for custom layout.</p>'
end
it 'should not apply a layout to post content if page-layout attribute is nil' do
file = output_file '2016/01/05/nil-layout.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(div class="paragraph">\n<p>Lorem ipsum.</p>\n</div>)
end
it 'should show the title above the content if the showtitle attribute is set' do
file = output_file '2016/04/01/show-me-the-title.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<title>Show Me the Title</title>'
(expect contents).to include '<h1 class="post-title">Show Me the Title</h1>'
(expect contents).to include '<h1>Show Me the Title</h1>'
end
it 'should interpret value of page attribute as YAML data' do
post = find_post '2016-02-01-post-with-categories.adoc'
(expect post).not_to be_nil
(expect post.data['categories']).to eql %w(code javascript)
file = output_file 'code/javascript/2016/02/01/post-with-categories.html'
(expect ::File).to exist file
end
it 'should merge singular variables with collection variables' do
post = find_post '2016-02-02-post-with-singular-vars.adoc'
(expect post).not_to be_nil
(expect post.data['category']).to eql 'code'
(expect post.data['categories']).to eql %w(code node javascript)
(expect post.data['tag']).to eql 'syntax'
(expect post.data['tags']).to eql %w(syntax tip beginner)
file = output_file 'code/node/javascript/2016/02/02/post-with-singular-vars.html'
(expect ::File).to exist file
end
it 'should convert revdate to local Time object and use it as date of post' do
# NOTE Time.parse without time zone assumes time zone of site
date = ::Time.parse '2016-06-15 10:30:00'
date = date.localtime
slug = 'post-with-date'
post = find_post %(#{date.strftime '%Y-%m-%d'}-#{slug}.adoc)
(expect post).not_to be_nil
(expect post.data['date']).to be_a ::Time
(expect post.data['date'].to_s).to eql date.to_s
file = output_file %(#{date.strftime '%Y/%m/%d'}/#{slug}.html)
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include [
%(<time class="date-published" datetime="#{date.xmlschema}">),
(date.strftime '%B %d, %Y'),
'</time>',
].join
end
it 'should convert revdate with time zone to local Time object and use it as date of post' do
date = ::Time.parse '2016-07-15 04:15:30 -0600'
date = date.localtime
slug = 'post-with-date-and-tz'
post = find_post %(#{date.strftime '%Y-%m-%d'}-#{slug}.adoc)
(expect post).not_to be_nil
(expect post.data['date']).to be_a ::Time
(expect post.data['date'].to_s).to eql date.to_s
file = output_file %(#{date.strftime '%Y/%m/%d'}/#{slug}.html)
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include [
%(<time class="date-published" datetime="#{date.xmlschema}">),
(date.strftime '%B %d, %Y'),
'</time>',
].join
end
it 'should convert revdate in revision line to local Time object and use it as date of post' do
date = ::Time.parse '2016-07-20 05:45:25 -0600'
date = date.localtime
slug = 'post-with-date-in-revision-line'
post = find_post %(#{date.strftime '%Y-%m-%d'}-#{slug}.adoc)
(expect post).not_to be_nil
(expect post.data['date']).to be_a ::Time
(expect post.data['date'].to_s).to eql date.to_s
file = output_file %(#{date.strftime '%Y/%m/%d'}/#{slug}.html)
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include [
%(<time class="date-published" datetime="#{date.xmlschema}">),
(date.strftime '%B %d, %Y'),
'</time>',
].join
end
it 'should process AsciiDoc header of draft post' do
draft = find_draft 'a-draft-post.adoc'
(expect draft).not_to be_nil
(expect draft.data['author']).to eql 'Henry Jekyll'
(expect draft.data['tags']).to eql ['draft']
file = output_file %(#{draft.date.strftime '%Y/%m/%d'}/a-draft-post.html)
(expect ::File).to exist file
end
it 'should convert excerpt from AsciiDoc using site-wide doctype' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include '<div class="excerpt">This is the <em>excerpt</em> of this post.</div>'
end
it 'should convert excerpt from AsciiDoc using page-specific doctype' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
(expect contents).to include %(<div class="paragraph">\n<p>Lorem ipsum.</p>\n</div>)
end
end
describe 'posts with excerpts' do
use_fixture :posts_with_excerpts
before :each do
site.process
end
it 'should use page contents as excerpt if excerpt separator not found after AsciiDoc header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="header-and-single-paragraph">(.*?)<\/li>/m
(expect $1).to include '<p>This is the excerpt and body text.</p>'
end
it 'should use first paragraph as excerpt if excerpt separator is found after AsciiDoc header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="header-and-multiple-paragraphs">(.*?)<\/li>/m
(expect $1).to include '<p>This is the excerpt.</p>'
(expect $1).not_to include '<p>This is the rest of the body text that comes after the excerpt.</p>'
end
it 'should use page contents as excerpt if excerpt separator not found with no AsciiDoc header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="single-paragraph-only">(.*?)<\/li>/m
(expect $1).to include '<p>This is the excerpt and body text.</p>'
end
it 'should use first paragraph as excerpt if excerpt separator is found with no AsciiDoc header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="multiple-paragraphs-only">(.*?)<\/li>/m
(expect $1).to include '<p>This is the <em>excerpt</em>.</p>'
(expect $1).not_to include '<p>This is the rest of the body text that comes after the excerpt.</p>'
end
it 'should use excerpt defined as page attribute in AsciiDoc header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="excerpt-in-header">(.*?)<\/li>/m
(expect $1).to include '<p>This is the <em>excerpt</em>.</p>'
(expect $1).not_to include '<p>This is the first paragraph, but not the excerpt.</p>'
end
it 'should use excerpt defined in front matter' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="excerpt-in-front-matter">(.*?)<\/li>/m
(expect $1).to include '<p>This is the <em>excerpt</em>.</p>'
(expect $1).not_to include '<p>This is the first paragraph, but not the excerpt.</p>'
end
it 'should set excerpt to blank if excerpt_separator is blank' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="blank-excerpt">(.*?)<\/li>/m
(expect $1).to include '<p class="excerpt"></p>'
end
it 'should set excerpt to blank if document only has a header' do
file = output_file 'index.html'
(expect ::File).to exist file
contents = ::File.read file
contents =~ %r/<li data-slug="header-only">(.*?)<\/li>/m
(expect $1).to include '<p class="excerpt"></p>'
end
it 'should not process liquid in excerpt by default' do
file = output_file 'index.html'
(expect ::File).to exist file