middleman-asciidoc 1.0.0.rc.6 → 1.0.0.rc.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fbada42f7900398ed4146ab4c34415730ff11250e7fe0aeac5fb0a9ab79052f
4
- data.tar.gz: 8f8d642ddad76e9543043b12537b8d993e187a488b8441345e6251d868d95b65
3
+ metadata.gz: 7ae4f8ddef716de5e418a26661263c42e49aaf6904d8a8afc909ea0edf780242
4
+ data.tar.gz: e46fca12ff3c1406ef222daf7e0d0b62d99955d523b35a63bf855fb87eaf137d
5
5
  SHA512:
6
- metadata.gz: 08bef99c6140b5dfbfe52cdf0ea75a4fb493cc086b5cd56ba31cd3bf0cdc6bf0b673ad160adf36cb2105e023e6b8363089dab51c895603bf77bfd62aac2a191d
7
- data.tar.gz: e205ad469ba66138631ea7cf0040a64df009c7f78129ec658c125e73dcfbd2f49f23edd9a12d73d988463da26c9837a3479395ef123b3f27d727139abb79bb68
6
+ metadata.gz: 0dce20bf3fda0ac2d72f39fccd325c948a2536bc80fe1d64dfc3412c82ffcb22b4ec31902c31a4629612081ba29804ed67ad343b0e2274e6a0ee83f9256283f6
7
+ data.tar.gz: e8cc0aa2f4345a7a025d20c6b36d08d9fdb4c5854733392ffb8371ad42e9e2e7f289ae8feb12a65449e33dcef3811c37f771096f40d8926e4212ca1ffdea0246
data/Gemfile CHANGED
@@ -19,8 +19,8 @@ gem 'cucumber', '~> 2.0', require: false
19
19
  gem 'aruba', '~> 0.7.4', require: false
20
20
  gem 'capybara', '~> 2.5.0', require: false
21
21
 
22
- # Code quality tools
23
- gem 'cane', platforms: :mri, require: false
22
+ # Code coverage tools
23
+ gem 'simplecov', require: false
24
24
 
25
25
  # Additional libraries for testing
26
26
  # Middleman itself (use for testing against development version)
data/README.adoc CHANGED
@@ -1,9 +1,10 @@
1
1
  = AsciiDoc Extension for Middleman (powered by Asciidoctor)
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
- v1.0.0.rc.6, 2017-12-07
3
+ v1.0.0.rc.7, 2017-12-20
4
4
  // Settings:
5
5
  :idprefix:
6
6
  :idseparator: -
7
+ :hide-uri-scheme:
7
8
  ifndef::env-github[:icons: font]
8
9
  ifdef::env-github,env-browser[]
9
10
  :toc: preamble
@@ -20,12 +21,18 @@ ifdef::env-github[]
20
21
  endif::[]
21
22
  // URIs:
22
23
  :uri-repo: https://github.com/middleman/middleman-asciidoc
24
+ :uri-issues: https://github.com/middleman/middleman-asciidoc/issues
23
25
  :uri-middleman: https://middlemanapp.com
26
+ :uri-middleman-forum: https://forum.middlemanapp.com
24
27
  :uri-asciidoc: http://asciidoc.org
25
28
  :uri-asciidoctor: http://asciidoctor.org
29
+ :uri-asciidoctor-discuss: http://discuss.asciidoctor.org
26
30
  :uri-gem: https://rubygems.org/gems/middleman-asciidoc
31
+ :uri-tilt: https://github.com/rtomayko/tilt
32
+ :uri-yaml: https://en.wikipedia.org/wiki/YAML
33
+ :uri-help-pr: https://help.github.com/articles/using-pull-requests
27
34
  :badge-gem: https://img.shields.io/gem/v/middleman-asciidoc.svg?label=gem
28
- :uri-build: http://travis-ci.org/middleman/middleman-asciidoc
35
+ :uri-build: https://travis-ci.org/middleman/middleman-asciidoc
29
36
  :badge-build: https://img.shields.io/travis/middleman/middleman-asciidoc/master.svg
30
37
  :uri-deps: https://gemnasium.com/middleman/middleman-asciidoc
31
38
  :badge-deps: https://img.shields.io/gemnasium/middleman/middleman-asciidoc.svg
@@ -48,7 +55,7 @@ Prior to Middleman 4, AsciiDoc support was bundled with Middleman.
48
55
 
49
56
  == Installation
50
57
 
51
- If you're just getting started, first install the Middleman gem.
58
+ If you're just getting started, first install the *middleman* gem.
52
59
 
53
60
  $ gem install middleman
54
61
 
@@ -110,7 +117,8 @@ With the exception of `layout`, these option keys map directly to options in the
110
117
 
111
118
  attributes (type: Hash or Array, default: [])::
112
119
  Custom AsciiDoc attributes to pass to the processor.
113
- The following implicit attributes are automatically appended to this collection.
120
+ The following built-in attributes are automatically appended to this collection.
121
+ (You can remove a built-in attribute by passing a custom attribute with the corresponding name prefixed with `-`).
114
122
 
115
123
  * env=site
116
124
  * env-site
@@ -119,9 +127,16 @@ The following implicit attributes are automatically appended to this collection.
119
127
  * builder=middleman
120
128
  * builder-middleman
121
129
  * middleman-version=(value of `Middleman::VERSION` constant)
122
- * imagesdir=(value of http_prefix + images_dir in app config)@
123
- ** skipped if `!imagesdir` is defined as a custom attribute
124
- ** can be overridden in page (hence the trailing @)
130
+ * site-root=(app.root.to_s)
131
+ * site-source=(app.source_dir.to_s)
132
+ * site-destination=(app.root.to_s + / + app.config[:build_dir])
133
+ * site-environment=(app.environment.to_s)
134
+ * relfilesuffix=(path to index file, as configured, if directory indexes are enabled)
135
+ * relfilesuffix=../ if directory indexes are enabled
136
+ * imagesdir=(http_prefix + app.config[:images_dir])@
137
+ ** skipped if `-imagesdir` (soft unset) or `!imagesdir` (hard unset) is defined as a custom attribute
138
+ ** can be overridden by page, hence the trailing @
139
+ * imagesoutdir=(imagesdir relative to site destination)
125
140
 
126
141
  backend (type: Symbol, default: :html5)::
127
142
  The moniker for a converter, which determines the output format to generate.
@@ -146,7 +161,7 @@ Each AsciiDoc file in the source directory (except for files that begin with `+_
146
161
  AsciiDoc files can have the file extension `.adoc` or `.html.adoc`.
147
162
  These extensions are stripped and replaced with the value of the `outfilesuffix` attribute, which defaults to `.html`.
148
163
 
149
- NOTE: For details about how the file extension is substituted, see the discussion in https://github.com/middleman/middleman-asciidoc/issues/7[issue #7].
164
+ NOTE: For details about how the file extension is substituted, see the discussion in {uri-issues}/7[issue #7].
150
165
 
151
166
  To add a page composed in AsciiDoc, simply add an AsciiDoc file that has one of the aforementioned AsciiDoc file extensions to the project source directory.
152
167
 
@@ -170,7 +185,7 @@ puts "Hello, World!"
170
185
 
171
186
  AsciiDoc attributes defined in the document header whose names begin with `page-` are promoted to page data (aka front matter).
172
187
  The part of the name after the `page-` prefix is used as the entry's key (e.g., page-layout becomes layout).
173
- The value is parsed as https://en.wikipedia.org/wiki/YAML[YAML] data (that which can be expressed in a single line).
188
+ The value is parsed as {uri-yaml}[YAML] data (that which can be expressed in a single line).
174
189
 
175
190
  In addition to these explicit page attributes, the following AsciiDoc attributes are also promoted to page data:
176
191
 
@@ -245,6 +260,30 @@ Here are the different ways to specify a layout:
245
260
  .Layout for blog posts
246
261
  WARNING: If you're using the Middleman Blog extension to write blog posts, the `layout` property on the blog configuration overrides the default layout, but you can still override that setting using the `page-layout` attribute in each post.
247
262
 
263
+ ==== Accessing the AsciiDoc Configuration From a Layout
264
+
265
+ You can access the global configuration for the AsciiDoc extension from a layout template using the variable path `app.config.asciidoc` (Hash).
266
+
267
+ For example, let's say you want to reference the location stored in the `imagesoutdir` attribute.
268
+ You can do so in an ERB template using:
269
+
270
+ ----
271
+ <%= app.config.asciidoc[:attributes]['imagesoutdir'] %>
272
+ ----
273
+
274
+ Other processor options, such as `:safe`, are available from the `app.config.asciidoc` variable path.
275
+
276
+ If you want to access the options passed to the AsciiDoc processor for the current page, use the variable path `current_page.options[:renderer_options]` (Hash) instead.
277
+
278
+ For example, let's say you want to access the resolved base directory for the current page.
279
+ You can do so in an ERB template using:
280
+
281
+ ----
282
+ <%= current_page.options[:renderer_options][:base_dir] %>
283
+ ----
284
+
285
+ Other processor options, such as `:attributes`, are available from the `current_page.options[:renderer_options]` variable path.
286
+
248
287
  === Ignoring a Page
249
288
 
250
289
  In addition to the normal ignore filter in Middleman, you can also control whether a page is ignored from AsciiDoc.
@@ -411,18 +450,91 @@ If you're using Bundler, use the following commands instead:
411
450
  $ bundle exec middleman build
412
451
  $ bundle exec middleman serve
413
452
 
453
+ == Customizing the HTML
454
+
455
+ You can use templates to customize the HTML Asciidoctor generates for the pages in your site.
456
+ Each template file corresponds to a node in the AsciiDoc document tree (aka AST).
457
+ Template files can be composed in any templating language supported by {uri-tilt}[Tilt].
458
+
459
+ Follow the steps below to configure Asciidoctor to use custom templates when converting AsciiDoc documents to HTML.
460
+
461
+ === Step {counter:step}: Add Required Gems
462
+
463
+ You'll first need to add the *thread_safe* gem to your [.path]_Gemfile_.
464
+ If you plan to use a template language other than ERB (.erb) or InterpolatedString (.str), you'll also need to add the dependency for the template language.
465
+ We've decided to use Slim for this example, so we need to also add the *slim* gem.
466
+
467
+ [source,ruby]
468
+ ----
469
+ gem 'slim', '~> 3.0.9'
470
+ gem 'thread_safe', '~> 0.3.6'
471
+ ----
472
+
473
+ === Step {counter:step}: Install New Gems
474
+
475
+ Now run the `bundle` command to install the new gems.
476
+
477
+ $ bundle
478
+
479
+ === Step {counter:step}: Create a Templates Folder
480
+
481
+ Next, create a new folder in your site named [.path]_source/_asciidoc_templates_ to store your templates for AsciiDoc.
482
+
483
+ $ mkdir source/_asciidoc_templates
484
+
485
+ We prefix the folder name with an underscore so it doesn't get included in the sitemap (i.e., Middleman won't look for pages in this folder).
486
+
487
+ === Step {counter:step}: Configure Asciidoctor to Load Templates
488
+
489
+ In your site's [.path]_config.rb_ file, configure Asciidoctor to load the templates by setting the `:template_dirs` option when activating the extension:
490
+
491
+ [source,ruby]
492
+ ----
493
+ activate :asciidoc, template_dirs: source/_asciidoc_templates
494
+ ----
495
+
496
+ === Step {counter:step}: Compose a Template
497
+
498
+ The final step is to compose a template.
499
+ We'll be customizing the unordered list node.
500
+ Add a file named [.path]_ulist.html.slim_ to the [.path]_source/_asciidoc_templates_ directory.
501
+ Populate the file with the following contents:
502
+
503
+ .source/_asciidoc_templates/ulist.html.slim
504
+ [source,slim]
505
+ ----
506
+ - if title?
507
+ figure.list.unordered id=id
508
+ figcaption=title
509
+ ul class=[style, role]
510
+ - items.each do |_item|
511
+ li
512
+ span.primary=_item.text
513
+ - if _item.blocks?
514
+ =_item.content
515
+ - else
516
+ ul id=id class=[style, role]
517
+ - items.each do |_item|
518
+ li
519
+ span.primary=_item.text
520
+ - if _item.blocks?
521
+ =_item.content
522
+ ----
523
+
524
+ The next time you build your site, Asciidoctor will use your custom template to generate HTML for all unordered lists converted from AsciiDoc.
525
+
414
526
  == Community
415
527
 
416
- The official community forum for Middleman can be found at http://forum.middlemanapp.com.
417
- For questions related to this extension or general questions about AsciiDoc, please post to the Asciidoctor discussion list at http://discuss.asciidoctor.org.
528
+ The official community forum for Middleman can be found at {uri-middleman-forum}.
529
+ For questions related to this extension or general questions about AsciiDoc, please post to the Asciidoctor discussion list at {uri-asciidoctor-discuss}.
418
530
 
419
531
  == Bug Reports
420
532
 
421
533
  Github Issues are used for managing bug reports and feature requests.
422
- If you run into issues, please search the issues and submit new problems in the project's https://github.com/middleman/middleman-asciidoc/issues[issue tracker].
534
+ If you run into issues, please search the issues and submit new problems in the project's {uri-issues}[issue tracker].
423
535
 
424
536
  The best way to get quick responses to your issues and swift fixes to your bugs is to submit detailed bug reports, include test cases and respond to developer questions in a timely manner.
425
- Even better, if you know Ruby, you can submit https://help.github.com/articles/using-pull-requests[pull requests] containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
537
+ Even better, if you know Ruby, you can submit {uri-help-pr}[pull requests] containing Cucumber Features which describe how your feature should work or exploit the bug you are submitting.
426
538
 
427
539
  == How to Run Tests
428
540
 
@@ -430,9 +542,10 @@ The tests are based on Cucumber.
430
542
  Here's how to clone the project and run the tests.
431
543
 
432
544
  . Clone the repository:
433
-
434
- $ git clone https://github.com/middleman/middleman-asciidoc.git &&
435
- cd middleman-asciidoc
545
+ +
546
+ [subs=attributes+]
547
+ $ git clone {uri-repo} &&
548
+ cd "`basename $_`"
436
549
 
437
550
  . Install Bundler (if not already installed):
438
551
 
data/Rakefile CHANGED
@@ -17,19 +17,6 @@ require 'rake/clean'
17
17
  task :test => ['cucumber']
18
18
  task :default => ['test', 'build']
19
19
 
20
- begin
21
- require 'cane/rake_task'
22
-
23
- desc 'Run cane to check quality metrics'
24
- Cane::RakeTask.new(:quality) do |cane|
25
- cane.no_style = true
26
- cane.no_doc = true
27
- cane.abc_glob = 'lib/middleman-asciidoc/**/*.rb'
28
- end
29
- rescue LoadError
30
- # warn 'cane not available, quality task not provided.'
31
- end
32
-
33
20
  desc 'Build HTML documentation'
34
21
  task :doc do
35
22
  sh 'bundle exec yard'
@@ -226,6 +226,33 @@ Feature: AsciiDoc Support
226
226
  </div>
227
227
  """
228
228
 
229
+ Scenario: Rendering html with layout and layout engine specified
230
+ Given a fixture app "asciidoc-pages-app"
231
+ And a file named "source/layout-engine.adoc" with:
232
+ """
233
+ :page-layout: engine
234
+ :page-layout-engine: str
235
+ = Page Title
236
+
237
+ Hello, AsciiDoc!
238
+ """
239
+ And the Server is running
240
+ When I go to "/layout-engine.html"
241
+ Then I should see:
242
+ """
243
+ <!DOCTYPE html>
244
+ <html>
245
+ <head>
246
+ <title>str :: Page Title</title>
247
+ </head>
248
+ <body>
249
+ <div class="paragraph">
250
+ <p>Hello, AsciiDoc!</p>
251
+ </div>
252
+ </body>
253
+ </html>
254
+ """
255
+
229
256
  Scenario: Rendering html using title and tags from document
230
257
  Given the Server is running at "asciidoc-pages-app"
231
258
  When I go to "/hello-with-title-and-tags.html"
@@ -407,9 +434,10 @@ Feature: AsciiDoc Support
407
434
  <p>Page Title</p>
408
435
  <p>Doc Writer</p>
409
436
  <p>doc.writer@example.com</p>
410
- <p>Doc Writer | Junior Writer</p>
437
+ <p>Doc Writer | Junior Writer | Random Dude</p>
411
438
  <p>https://social.example.com/jrw</p>
412
439
  <p>jrw</p>
440
+ <p>http://example.com</p>
413
441
  <p>This is a sample page.</p>
414
442
  <p>meta, AsciiDoc, Middleman</p>
415
443
  """
@@ -436,6 +464,21 @@ Feature: AsciiDoc Support
436
464
  <html data-date="2017-01-01T16:00:00Z">
437
465
  """
438
466
 
467
+ Scenario: Using a fixed time as local time for pages
468
+ Given a fixture app "asciidoc-pages-app"
469
+ And a file named "config.rb" with:
470
+ """
471
+ set :time_zone, 'America/Los_Angeles'
472
+ set :time, (Time.parse '2017-01-01 09:00:00 MST')
473
+ activate :asciidoc
474
+ """
475
+ And the Server is running
476
+ When I go to "/localtime.html"
477
+ Then I should see:
478
+ """
479
+ 2017-01-01 08:00:00 PST
480
+ """
481
+
439
482
  Scenario: Including a file relative to source root
440
483
  Given the Server is running at "asciidoc-pages-app"
441
484
  When I go to "/master.html"
@@ -571,11 +614,11 @@ Feature: AsciiDoc Support
571
614
  </div>
572
615
  """
573
616
 
574
- Scenario: Restoring imagesdir to default value
617
+ Scenario: Setting imagesdir to blank
575
618
  Given a fixture app "asciidoc-pages-app"
576
619
  And a file named "config.rb" with:
577
620
  """
578
- activate :asciidoc, attributes: %w(imagesdir!)
621
+ activate :asciidoc, attributes: %w(imagesdir=)
579
622
  """
580
623
  And the Server is running
581
624
  When I go to "/custom-imagesdir.html"
@@ -587,6 +630,20 @@ Feature: AsciiDoc Support
587
630
  </div>
588
631
  """
589
632
 
633
+ Scenario: Restoring imagesdir to default value
634
+ Given a fixture app "asciidoc-pages-app"
635
+ And a file named "config.rb" with:
636
+ """
637
+ activate :asciidoc, attributes: %w(-imagesdir)
638
+ """
639
+ And a file named "source/imagesdir.adoc" with:
640
+ """
641
+ imagesdir={imagesdir}
642
+ """
643
+ And the Server is running
644
+ When I go to "/imagesdir.html"
645
+ Then I should see "imagesdir="
646
+
590
647
  Scenario: Overriding imagesdir attribute in page with imagesdir configuration
591
648
  Given a fixture app "asciidoc-pages-app"
592
649
  And a file named "config.rb" with:
@@ -603,6 +660,20 @@ Feature: AsciiDoc Support
603
660
  </div>
604
661
  """
605
662
 
663
+ Scenario: Forcefully unsetting AsciiDoc attributes in document
664
+ Given a fixture app "asciidoc-pages-app"
665
+ And a file named "config.rb" with:
666
+ """
667
+ activate :asciidoc, attributes: %w(!icons sectanchors!)
668
+ """
669
+ And the Server is running
670
+ When I go to "/page-with-attributes.html"
671
+ Then I should see:
672
+ """
673
+ !icons
674
+ !sectanchors
675
+ """
676
+
606
677
  Scenario: Configuring custom AsciiDoc attributes as Array
607
678
  Given a fixture app "asciidoc-pages-app"
608
679
  And a file named "config.rb" with:
@@ -623,6 +694,73 @@ Feature: AsciiDoc Support
623
694
  When I go to "/custom-attribute.html"
624
695
  Then I should see "bar{baz}"
625
696
 
697
+ Scenario: Using non-string attribute values in AsciiDoc attributes Hash
698
+ Given a fixture app "asciidoc-pages-app"
699
+ And a file named "config.rb" with:
700
+ """
701
+ activate :asciidoc, attributes: {
702
+ 'sectnumlevels' => 2,
703
+ 'sectids' => nil,
704
+ 'experimental' => true,
705
+ 'builddate' => (DateTime.parse '2017-01-01T09:00:00-05:00')
706
+ }
707
+ """
708
+ And a file named "source/non-string-attrs.adoc" with:
709
+ """
710
+ {sectnumlevels}
711
+ ifndef::sectids[!sectids]
712
+ ifdef::experimental[experimental]
713
+ {builddate}
714
+ """
715
+ And the Server is running
716
+ When I go to "/non-string-attrs.html"
717
+ Then I should see:
718
+ """
719
+ 2
720
+ !sectids
721
+ experimental
722
+ 2017-01-01T09:00:00-05:00
723
+ """
724
+
725
+ Scenario: Passing invalid type to attributes setting
726
+ Given a fixture app "asciidoc-pages-app"
727
+ And a file named "config.rb" with:
728
+ """
729
+ activate :asciidoc, attributes: 'icons=font'
730
+ """
731
+ Then running the Server should raise an exception
732
+
733
+ Scenario: Setting custom attributes for a specific page
734
+ Given a fixture app "asciidoc-pages-app"
735
+ And app "asciidoc-pages-app" is using config "page-attributes"
736
+ And the Server is running
737
+ When I go to "/with-sections.html"
738
+ Then I should see:
739
+ """
740
+ <h2 id="_section_a"><a class="anchor" href="#_section_a"></a>Section A</h2>
741
+ """
742
+
743
+ Scenario: Using custom templates to convert AsciiDoc document nodes to HTML
744
+ Given a fixture app "asciidoc-pages-app"
745
+ And a file named "config.rb" with:
746
+ """
747
+ activate :asciidoc do |asciidoc|
748
+ asciidoc.template_dirs = 'source/_templates'
749
+ asciidoc.template_engine = :erb
750
+ end
751
+ """
752
+ And a file named "source/rosy-paragraph.adoc" with:
753
+ """
754
+ [.rosy]
755
+ Rosey paragraph.
756
+ """
757
+ And the Server is running
758
+ When I go to "/rosy-paragraph.html"
759
+ Then I should see:
760
+ """
761
+ <p class="rosy">Rosey paragraph.</p>
762
+ """
763
+
626
764
  Scenario: Warn when options are set using `set :asciidoc`
627
765
  Given a fixture app "asciidoc-pages-app"
628
766
  And app "asciidoc-pages-app" is using config "set-asciidoc"
@@ -1,4 +1,6 @@
1
1
  PROJECT_ROOT_PATH = File.expand_path '../../..', __FILE__
2
+ # simplecov loads settings from .simplecov
3
+ require 'simplecov' if ENV['COVERAGE'] == 'true'
2
4
  ENV['TEST'] = 'true'
3
5
  require 'middleman-core'
4
6
  require 'middleman-core/step_definitions'
@@ -0,0 +1,3 @@
1
+ Then(/^running the Server should raise an exception$/) do
2
+ expect{ step 'the Server is running' }.to raise_exception RuntimeError
3
+ end
@@ -0,0 +1,6 @@
1
+ activate :asciidoc
2
+ page 'with-sections', renderer_options: {
3
+ attributes: {
4
+ 'sectanchors' => ''
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ <p<% if role? %> class="<%= role %>"<% end %>><%= content %></p>
@@ -8,5 +8,6 @@ layout: false
8
8
  <p><%= (page_data.authors || []) * ' | ' %></p>
9
9
  <p><%= page_data.authors[1].url %></p>
10
10
  <p><%= page_data.authors[1].username %></p>
11
+ <p><%= page_data.authors[2].url %></p>
11
12
  <p><%= page_data.description %></p>
12
13
  <p><%= page_data.keywords %></p>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>erb :: <%= current_resource.data.title || 'Fallback' %></title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>str :: #{current_resource.data.title || 'Fallback'}</title>
5
+ </head>
6
+ <body>
7
+ #{yield}
8
+ </body>
9
+ </html>
@@ -0,0 +1,3 @@
1
+ = Local Time
2
+
3
+ {localdatetime}
@@ -0,0 +1,11 @@
1
+ = Page Title
2
+ :icons: font
3
+ :sectanchors:
4
+
5
+ [subs=attributes]
6
+ ++++
7
+ ifdef::icons[icons={icons}]
8
+ ifndef::icons[!icons]
9
+ ifdef::sectanchors[sectanchors]
10
+ ifndef::sectanchors[!sectanchors]
11
+ ++++
@@ -1,5 +1,5 @@
1
1
  = Page Title
2
- Doc Writer <doc.writer@example.com>; Junior Writer <https://social.example.com/jrw[@jrw]>
2
+ Doc Writer <doc.writer@example.com>; Junior Writer <https://social.example.com/jrw[@jrw]>; Random Dude <http://example.com>
3
3
  :page-id: std-page-data
4
4
  :showtitle:
5
5
  :description: This is a sample page.
@@ -0,0 +1,11 @@
1
+ = Page Title
2
+
3
+ Preamble content.
4
+
5
+ == Section A
6
+
7
+ Section content.
8
+
9
+ == Section B
10
+
11
+ Section content.
@@ -22,7 +22,10 @@ module Middleman
22
22
  option :backend, :html5, 'Moniker used to select output format for AsciiDoc-based pages. Defaults to :html5. (Symbol)'
23
23
  option :base_dir, :docdir, 'Base directory to use for the current AsciiDoc document. Defaults to :docdir, which resolves to the document directory. (String)'
24
24
  option :safe, :safe, 'Safe mode level for AsciiDoc processor. Defaults to :safe. (Symbol)'
25
- option :layout, nil, 'Name of layout to use for AsciiDoc-based pages (not blog articles) (String or Symbol)'
25
+ option :template_dirs, nil, 'Directories containing custom converter templates for the AsciiDoc processor. (String or Array)'
26
+ option :template_engine, nil, 'Template engine to use for custom converter templates. (String or Symbol)'
27
+ option :template_engine_options, nil, 'Override options to pass to template engines of custom converter templates (indexed by engine). (Hash)'
28
+ option :layout, nil, 'Name of layout to use for AsciiDoc-based pages (not blog articles). (String or Symbol)'
26
29
 
27
30
  def initialize app, options_hash = {}, &block
28
31
  super unless app.mode? :config
@@ -33,7 +36,9 @@ module Middleman
33
36
  app.config[:asciidoc_extensions] = prune_tilt_mapping!
34
37
  set_time_zone app.config[:time_zone]
35
38
  if (app.config.defines_setting? :asciidoc)
39
+ # :nocov:
36
40
  warn 'Using `set :asciidoc` to set options for AsciiDoc is no longer supported. Please use `activate :asciidoc`.'
41
+ # :nocov:
37
42
  end
38
43
  (app.config[:asciidoc] = {}).tap do |cfg|
39
44
  attributes = {
@@ -42,21 +47,13 @@ module Middleman
42
47
  'site-destination' => (dest = (app.root_path.join app.config[:build_dir]).to_s),
43
48
  'site-environment' => app.environment.to_s
44
49
  }.merge IMPLICIT_ATTRIBUTES
45
- if !!app.extensions[:directory_indexes]
46
- if app.config[:strip_index_file]
47
- attributes['relfilesuffix'] = app.config[:trailing_slash] ? '/' : ''
48
- else
49
- attributes['relfilesuffix'] = %(/#{app.config[:index_file]})
50
- end
50
+ if app.extensions[:directory_indexes]
51
+ attributes['relfilesuffix'] = app.config[:strip_index_file] ? (app.config[:trailing_slash] ? '/' : '') : %(/#{app.config[:index_file]})
51
52
  attributes['relfileprefix'] = '../'
52
53
  end
54
+ attributes['imagesdir'] = %(#{[((app.config[:http_prefix] || '').chomp '/'), app.config[:images_dir]] * '/'}@)
53
55
  attributes = merge_attributes options[:attributes], attributes if (options.setting :attributes).value_set?
54
- if attributes.key? 'imagesdir'
55
- imagesdir = attributes['imagesdir']
56
- else
57
- imagesdir = attributes['imagesdir'] = %(#{[((app.config[:http_prefix] || '').chomp '/'), app.config[:images_dir]] * '/'}@)
58
- end
59
- if imagesdir && !(attributes.key? 'imagesoutdir') && (imagesdir.start_with? '/')
56
+ if !(attributes.key? 'imagesoutdir') && (imagesdir = attributes['imagesdir']) && (imagesdir.start_with? '/')
60
57
  attributes['imagesoutdir'] = ::File.join dest, (imagesdir.chomp '@')
61
58
  end
62
59
  cfg[:attributes] = attributes
@@ -72,6 +69,11 @@ module Middleman
72
69
  cfg[:backend] = (cfg[:backend] || :html5).to_sym
73
70
  cfg[:safe] = options[:safe] if (options.setting :safe).value_set?
74
71
  cfg[:safe] = (cfg[:safe] || :safe).to_sym
72
+ if (template_dirs_opt = options.setting :template_dirs).value_set?
73
+ cfg[:template_dirs] = (Array template_dirs_opt.value).map {|dir| (app.root_path.join dir).to_s }
74
+ cfg[:template_engine] = options[:template_engine].to_s if (options.setting :template_engine).value_set?
75
+ cfg[:template_engine_options] = options[:template_engine_options] if (options.setting :template_engine_options).value_set?
76
+ end
75
77
  if (default_layout = options[:layout] || app.config[:layout])
76
78
  # set priority to run after blog extension, which also sets a layout
77
79
  app.sitemap.register_resource_list_manipulator :asciidoc_default_layout, (DefaultLayoutConfigurator.new app, default_layout.to_sym), 60
@@ -80,12 +82,16 @@ module Middleman
80
82
  end
81
83
 
82
84
  def manipulate_resource_list resources
85
+ if (app_time = app.config[:time])
86
+ app_date_time_strs = (app_time.in_time_zone.strftime '%F %T %Z').split ' ', 2
87
+ end
83
88
  header_asciidoc_opts = app.config[:asciidoc].merge parse_header_only: true
84
89
  header_attrs = header_asciidoc_opts[:attributes].merge 'skip-front-matter' => ''
85
90
  use_docdir_as_base_dir = header_asciidoc_opts[:base_dir] == :docdir
86
91
 
87
92
  resources.select {|res| !res.ignored? && (asciidoc_file? res) }.each do |resource|
88
93
  page_attrs = { 'page-id' => %(#{resource.page_id}@) }
94
+ page_attrs['localdate'], page_attrs['localtime'] = app_date_time_strs if app_date_time_strs
89
95
  if (path = resource.source_file)
90
96
  page_attrs['docfile'] = path
91
97
  page_attrs['docdir'] = (dir = ::File.dirname path)
@@ -113,7 +119,7 @@ module Middleman
113
119
  if doc.attr? 'page-layout'
114
120
  if (layout = doc.attr 'page-layout').empty?
115
121
  opts[:layout] = :_auto_layout
116
- opts[:layout_engine] = doc.attr 'page-layout-engine' if doc.attr? 'page-layout-engine'
122
+ opts[:layout_engine] = (doc.attr 'page-layout-engine').to_sym if doc.attr? 'page-layout-engine'
117
123
  else
118
124
  case (layout = layout.to_sym)
119
125
  when :~, :null
@@ -123,7 +129,7 @@ module Middleman
123
129
  page_asciidoc_opts[:header_footer] = true
124
130
  else
125
131
  opts[:layout] = layout
126
- opts[:layout_engine] = doc.attr 'page-layout-engine' if doc.attr? 'page-layout-engine'
132
+ opts[:layout_engine] = (doc.attr 'page-layout-engine').to_sym if doc.attr? 'page-layout-engine'
127
133
  end
128
134
  end
129
135
  else
@@ -182,17 +188,33 @@ module Middleman
182
188
  def merge_attributes attrs, initial = {}
183
189
  if (is_array = ::Array === attrs) || ::Hash === attrs
184
190
  attrs.each_with_object(initial) {|entry, new_attrs|
185
- key, val = is_array ? ((entry.split '=', 2) + ['', ''])[0..1] : entry
191
+ key, val = is_array ? (((entry.split '=', 2) + ['', '']).slice 0, 2) : entry
186
192
  if key.start_with? '!'
187
- new_attrs[key[1..-1]] = nil
193
+ new_attrs[key.slice 1, key.length] = nil
188
194
  elsif key.end_with? '!'
189
195
  new_attrs[key.chop] = nil
196
+ # "-" prefix means to remove key from accumulator
197
+ elsif key.start_with? '-'
198
+ new_attrs.delete (key.slice 1, key.length)
199
+ elsif is_array
200
+ new_attrs[key] = resolve_attribute_refs val, new_attrs
190
201
  else
191
- new_attrs[key] = val ? (resolve_attribute_refs val, new_attrs) : nil
202
+ new_attrs[key] = case val
203
+ when ::String
204
+ resolve_attribute_refs val, new_attrs
205
+ when ::Numeric
206
+ val.to_s
207
+ when true
208
+ ''
209
+ when nil, false
210
+ nil
211
+ else
212
+ val
213
+ end
192
214
  end
193
215
  }
194
216
  else
195
- initial
217
+ raise 'Value of attributes setting on AsciiDoc extension must be a Hash or an Array.'
196
218
  end
197
219
  end
198
220
 
@@ -200,7 +222,7 @@ module Middleman
200
222
  if text.empty?
201
223
  text
202
224
  elsif text.include? '{'
203
- text.gsub(AttributeReferenceRx) { ($&.start_with? '\\') ? $&[1..-1] : ((attrs.fetch $1, $&).to_s.chomp '@') }
225
+ text.gsub(AttributeReferenceRx) { ($&.start_with? '\\') ? ($&.slice 1, $&.length) : ((attrs.fetch $1, $&).to_s.chomp '@') }
204
226
  else
205
227
  text
206
228
  end
@@ -255,7 +277,9 @@ module Middleman
255
277
  %(.#{ext})
256
278
  end
257
279
  else
280
+ # :nocov:
258
281
  ::Tilt.mappings.select {|_, classes| classes.include? ::Tilt::AsciidoctorTemplate }.keys.map {|ext| %(.#{ext}) }
282
+ # :nocov:
259
283
  end
260
284
  end
261
285
 
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module AsciiDoc
3
- VERSION = '1.0.0.rc.6'
3
+ VERSION = '1.0.0.rc.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-asciidoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc.6
4
+ version: 1.0.0.rc.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-08 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -56,6 +56,7 @@ files:
56
56
  - features/asciidoc-blog.feature
57
57
  - features/asciidoc-pages.feature
58
58
  - features/support/env.rb
59
+ - features/support/server_steps.rb
59
60
  - fixtures/asciidoc-blog-app/config-asciidoc-layout.rb
60
61
  - fixtures/asciidoc-blog-app/config-auto-layout.rb
61
62
  - fixtures/asciidoc-blog-app/config-date-in-filename.rb
@@ -74,10 +75,12 @@ files:
74
75
  - fixtures/asciidoc-blog-app/source/layouts/article.erb
75
76
  - fixtures/asciidoc-blog-app/source/layouts/asciidoc_page.erb
76
77
  - fixtures/asciidoc-pages-app/config-global-layout.rb
78
+ - fixtures/asciidoc-pages-app/config-page-attributes.rb
77
79
  - fixtures/asciidoc-pages-app/config-page-layout.rb
78
80
  - fixtures/asciidoc-pages-app/config-set-asciidoc.rb
79
81
  - fixtures/asciidoc-pages-app/config.rb
80
82
  - fixtures/asciidoc-pages-app/source/_include.adoc
83
+ - fixtures/asciidoc-pages-app/source/_templates/paragraph.html.erb
81
84
  - fixtures/asciidoc-pages-app/source/backend.adoc
82
85
  - fixtures/asciidoc-pages-app/source/code.adoc
83
86
  - fixtures/asciidoc-pages-app/source/custom-attribute.adoc
@@ -93,19 +96,24 @@ files:
93
96
  - fixtures/asciidoc-pages-app/source/images/tiger.gif
94
97
  - fixtures/asciidoc-pages-app/source/inspect-standard-page-data.html.erb
95
98
  - fixtures/asciidoc-pages-app/source/layouts/default.erb
99
+ - fixtures/asciidoc-pages-app/source/layouts/engine.erb
100
+ - fixtures/asciidoc-pages-app/source/layouts/engine.str
96
101
  - fixtures/asciidoc-pages-app/source/layouts/inspect-page-data.erb
97
102
  - fixtures/asciidoc-pages-app/source/layouts/showdate.erb
98
103
  - fixtures/asciidoc-pages-app/source/link-to-page.adoc
104
+ - fixtures/asciidoc-pages-app/source/localtime.adoc
99
105
  - fixtures/asciidoc-pages-app/source/manual/_chapters/ch01.adoc
100
106
  - fixtures/asciidoc-pages-app/source/manual/index.adoc
101
107
  - fixtures/asciidoc-pages-app/source/master.adoc
102
108
  - fixtures/asciidoc-pages-app/source/page-data.adoc
109
+ - fixtures/asciidoc-pages-app/source/page-with-attributes.adoc
103
110
  - fixtures/asciidoc-pages-app/source/page-with-date-at-zone.adoc
104
111
  - fixtures/asciidoc-pages-app/source/page-with-date.adoc
105
112
  - fixtures/asciidoc-pages-app/source/safe-mode.adoc
106
113
  - fixtures/asciidoc-pages-app/source/site-information.adoc
107
114
  - fixtures/asciidoc-pages-app/source/standard-page-data.adoc
108
115
  - fixtures/asciidoc-pages-app/source/topic/echo-page-id.adoc
116
+ - fixtures/asciidoc-pages-app/source/with-sections.adoc
109
117
  - lib/middleman-asciidoc.rb
110
118
  - lib/middleman-asciidoc/extension.rb
111
119
  - lib/middleman-asciidoc/middleman_extension.rb
@@ -139,6 +147,7 @@ test_files:
139
147
  - features/asciidoc-blog.feature
140
148
  - features/asciidoc-pages.feature
141
149
  - features/support/env.rb
150
+ - features/support/server_steps.rb
142
151
  - fixtures/asciidoc-blog-app/config-asciidoc-layout.rb
143
152
  - fixtures/asciidoc-blog-app/config-auto-layout.rb
144
153
  - fixtures/asciidoc-blog-app/config-date-in-filename.rb
@@ -157,10 +166,12 @@ test_files:
157
166
  - fixtures/asciidoc-blog-app/source/layouts/article.erb
158
167
  - fixtures/asciidoc-blog-app/source/layouts/asciidoc_page.erb
159
168
  - fixtures/asciidoc-pages-app/config-global-layout.rb
169
+ - fixtures/asciidoc-pages-app/config-page-attributes.rb
160
170
  - fixtures/asciidoc-pages-app/config-page-layout.rb
161
171
  - fixtures/asciidoc-pages-app/config-set-asciidoc.rb
162
172
  - fixtures/asciidoc-pages-app/config.rb
163
173
  - fixtures/asciidoc-pages-app/source/_include.adoc
174
+ - fixtures/asciidoc-pages-app/source/_templates/paragraph.html.erb
164
175
  - fixtures/asciidoc-pages-app/source/backend.adoc
165
176
  - fixtures/asciidoc-pages-app/source/code.adoc
166
177
  - fixtures/asciidoc-pages-app/source/custom-attribute.adoc
@@ -176,16 +187,21 @@ test_files:
176
187
  - fixtures/asciidoc-pages-app/source/images/tiger.gif
177
188
  - fixtures/asciidoc-pages-app/source/inspect-standard-page-data.html.erb
178
189
  - fixtures/asciidoc-pages-app/source/layouts/default.erb
190
+ - fixtures/asciidoc-pages-app/source/layouts/engine.erb
191
+ - fixtures/asciidoc-pages-app/source/layouts/engine.str
179
192
  - fixtures/asciidoc-pages-app/source/layouts/inspect-page-data.erb
180
193
  - fixtures/asciidoc-pages-app/source/layouts/showdate.erb
181
194
  - fixtures/asciidoc-pages-app/source/link-to-page.adoc
195
+ - fixtures/asciidoc-pages-app/source/localtime.adoc
182
196
  - fixtures/asciidoc-pages-app/source/manual/_chapters/ch01.adoc
183
197
  - fixtures/asciidoc-pages-app/source/manual/index.adoc
184
198
  - fixtures/asciidoc-pages-app/source/master.adoc
185
199
  - fixtures/asciidoc-pages-app/source/page-data.adoc
200
+ - fixtures/asciidoc-pages-app/source/page-with-attributes.adoc
186
201
  - fixtures/asciidoc-pages-app/source/page-with-date-at-zone.adoc
187
202
  - fixtures/asciidoc-pages-app/source/page-with-date.adoc
188
203
  - fixtures/asciidoc-pages-app/source/safe-mode.adoc
189
204
  - fixtures/asciidoc-pages-app/source/site-information.adoc
190
205
  - fixtures/asciidoc-pages-app/source/standard-page-data.adoc
191
206
  - fixtures/asciidoc-pages-app/source/topic/echo-page-id.adoc
207
+ - fixtures/asciidoc-pages-app/source/with-sections.adoc