middleman-asciidoc 1.0.0.rc.2 → 1.0.0.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +7 -1
- data/LICENSE.adoc +1 -1
- data/README.adoc +222 -32
- data/features/asciidoc.feature +356 -16
- data/fixtures/asciidoc-app/source/ignored.adoc +4 -0
- data/fixtures/asciidoc-app/source/inspect-standard-page-data.html.erb +10 -0
- data/fixtures/asciidoc-app/source/layouts/showdate.erb +9 -0
- data/fixtures/asciidoc-app/source/link-to-page.adoc +5 -0
- data/fixtures/asciidoc-app/source/page-with-date-at-zone.adoc +5 -0
- data/fixtures/asciidoc-app/source/page-with-date.adoc +5 -0
- data/fixtures/asciidoc-app/source/safe-mode.adoc +3 -0
- data/fixtures/asciidoc-app/source/site-information.adoc +6 -0
- data/fixtures/asciidoc-app/source/standard-page-data.adoc +5 -0
- data/lib/middleman-asciidoc/extension.rb +183 -48
- data/lib/middleman-asciidoc/version.rb +1 -1
- data/middleman-asciidoc.gemspec +11 -3
- metadata +25 -14
- data/.bundle/config +0 -4
- data/.gitignore +0 -5
- data/.ruby-version +0 -1
- data/.travis.yml +0 -13
- data/fixtures/asciidoc-app/source/hello-no-layout.adoc +0 -2
- data/fixtures/asciidoc-app/source/hello-with-layout.adoc +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d3d408ad1c5872270863cdc6e626014d24eec8eaa523ee4fee42b52ab910a85c
|
4
|
+
data.tar.gz: 245786b049319ca48ed1fba34e98a50419980c7e0b8eecd6e77556be1b341220
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda2d717b1d551dbc07433b580a6f34a9815725218aa19837515448b7605c1c54d7db41471d8a31a2588e9b8a3f1424588a3b18d4c13c94d60583c2c24a88555
|
7
|
+
data.tar.gz: 780f90f69d6bc617c9be0e52f3d970994eaedd4f28698ca43ab0a260d8e573dd32dd8479afc48ff26ceda6e1e2556df5dfc08c7d767fe66de8fb910de184320c
|
data/Gemfile
CHANGED
@@ -3,6 +3,12 @@ source 'https://rubygems.org'
|
|
3
3
|
# Runtime dependencies are defined in middleman-asciidoc.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
if RUBY_ENGINE == 'jruby'
|
7
|
+
git 'https://github.com/mojavelinux/middleman.git', branch: 'no-fast-blank' do
|
8
|
+
gem 'middleman-core'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
# Build and doc tools
|
7
13
|
gem 'rake', '~> 10.3', require: false
|
8
14
|
gem 'yard', '~> 0.8', require: false
|
@@ -13,7 +19,7 @@ gem 'aruba', '~> 0.7.4', require: false
|
|
13
19
|
gem 'capybara', '~> 2.5.0', require: false
|
14
20
|
|
15
21
|
# Code quality tools
|
16
|
-
gem 'cane', platforms:
|
22
|
+
gem 'cane', platforms: :mri, require: false
|
17
23
|
|
18
24
|
# Middleman itself (use for testing against development version)
|
19
25
|
#gem 'middleman-core', :github => 'middleman/middleman', :branch => 'master'
|
data/LICENSE.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
.MIT License
|
2
2
|
....
|
3
|
-
Copyright (C) 2014-
|
3
|
+
Copyright (C) 2014-2017 Dan Allen and the Asciidoctor Project
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
a copy of this software and associated documentation files (the
|
data/README.adoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= AsciiDoc Extension for Middleman (powered by Asciidoctor)
|
2
2
|
Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
|
3
|
-
v1.0.0.rc.
|
3
|
+
v1.0.0.rc.3, 2017-11-25
|
4
4
|
// Settings:
|
5
5
|
:idprefix:
|
6
6
|
:idseparator: -
|
@@ -48,23 +48,26 @@ Prior to Middleman 4, AsciiDoc support was part of Middleman core.
|
|
48
48
|
|
49
49
|
== Installation
|
50
50
|
|
51
|
-
If you're just getting started, install the Middleman gem
|
51
|
+
If you're just getting started, first install the Middleman gem.
|
52
52
|
|
53
|
-
$
|
53
|
+
$ gem install middleman
|
54
54
|
|
55
|
-
|
55
|
+
Then, generate a new project:
|
56
56
|
|
57
57
|
$ middleman init MY_PROJECT
|
58
58
|
|
59
|
+
The project will be created in the MY_PROJECT directory.
|
60
|
+
|
59
61
|
If you're working with an existing project, you can skip the previous steps.
|
60
62
|
|
61
63
|
Next, add the gem for this extension to your project's [.path]_Gemfile_.
|
62
64
|
|
63
|
-
|
65
|
+
[source,ruby]
|
66
|
+
----
|
64
67
|
gem 'middleman-asciidoc'
|
65
|
-
|
68
|
+
----
|
66
69
|
|
67
|
-
Finally, run Bundler using the `bundle` command:
|
70
|
+
Finally, run Bundler to install the dependencies using the `bundle` command:
|
68
71
|
|
69
72
|
$ bundle
|
70
73
|
|
@@ -72,15 +75,20 @@ You're now ready to activate this extension and begin putting it to work.
|
|
72
75
|
|
73
76
|
== Activation and Configuration
|
74
77
|
|
75
|
-
|
78
|
+
To activate this extension, add the following line to the [.path]_config.rb_ file for your site:
|
79
|
+
|
80
|
+
[source,ruby]
|
81
|
+
----
|
76
82
|
activate :asciidoc
|
77
|
-
|
83
|
+
----
|
78
84
|
|
79
|
-
You can also pass AsciiDoc configuration options to the underlying Asciidoctor processor
|
85
|
+
You can also pass AsciiDoc configuration options to the underlying Asciidoctor processor as a Hash or Array.
|
86
|
+
Here's an example of passing the attribute as an Array:
|
80
87
|
|
81
|
-
|
88
|
+
[source,ruby]
|
89
|
+
----
|
82
90
|
activate :asciidoc, attributes: ['source-highlighter=coderay']
|
83
|
-
|
91
|
+
----
|
84
92
|
|
85
93
|
The following option keys from the Asciidoctor API can be added to the Hash of the second argument to `activate`:
|
86
94
|
|
@@ -94,21 +102,26 @@ The following implicit attributes are automatically appended to this collection.
|
|
94
102
|
* site-gen-middleman
|
95
103
|
* builder=middleman
|
96
104
|
* builder-middleman
|
97
|
-
* middleman-version=(value of
|
105
|
+
* middleman-version=(value of `Middleman::VERSION` constant)
|
98
106
|
* imagesdir=(value of http_prefix + images_dir in app config)@
|
99
|
-
|
100
|
-
|
107
|
+
** skipped if `!imagesdir` is defined as a custom attribute
|
108
|
+
** can be overridden in page (hence the trailing @)
|
101
109
|
|
102
110
|
backend (type: Symbol, default: :html5)::
|
103
111
|
The moniker for a converter, which determines the output format to generate.
|
104
112
|
|
105
|
-
base_dir (type: String, default:
|
106
|
-
The base directory to use for the current AsciiDoc document
|
107
|
-
|
113
|
+
base_dir (type: String, default: :docdir)::
|
114
|
+
The base directory to use for the current AsciiDoc document.
|
115
|
+
If not specified, defaults to the document directory (i.e., `:docdir`).
|
116
|
+
To set the base directory to the source directory, use the keyword `:source` or the expression `app.source_dir`.
|
117
|
+
To leave the base directory undefined, use the value `nil`.
|
108
118
|
|
109
119
|
safe (type: Symbol, default: :safe)::
|
110
120
|
The safe mode level under which to run the AsciiDoc processor.
|
111
121
|
|
122
|
+
layout (type: String or Symbol, default: nil)::
|
123
|
+
The name of the default layout for AsciiDoc-based pages (pages processed by this extension, not including blog articles if a blog layout is specified).
|
124
|
+
|
112
125
|
TIP: The full set of options can be seen on your preview server's config page at the path [.path]_/__middleman/config/_.
|
113
126
|
|
114
127
|
== Creating Pages
|
@@ -122,7 +135,7 @@ NOTE: For details about how the file extension is substituted, see the discussio
|
|
122
135
|
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.
|
123
136
|
|
124
137
|
.sample.adoc
|
125
|
-
[
|
138
|
+
[source,asciidoc]
|
126
139
|
....
|
127
140
|
= Sample Page
|
128
141
|
:page-layout: page
|
@@ -147,35 +160,212 @@ In addition to these explicit page attributes, the following AsciiDoc attributes
|
|
147
160
|
|
148
161
|
* doctitle (i.e., the document title) (becomes title)
|
149
162
|
* author
|
163
|
+
* authors (converted to an Array of String values)
|
150
164
|
* email
|
151
|
-
* revdate (becomes date; value is converted to a
|
165
|
+
* revdate (becomes date; value is converted to a Time object)
|
166
|
+
* keywords (left as a String value)
|
167
|
+
* description
|
152
168
|
|
153
169
|
TIP: You can continue to specify page data using the front matter header.
|
154
170
|
The AsciiDoc `page-` attributes override matching entries in the front matter header.
|
155
171
|
|
172
|
+
NOTE: If you specify a time zone in the value of the `revdate` attribute, that time zone is honored.
|
173
|
+
Otherwise, the date specified is assumed to have the time zone set for the application.
|
174
|
+
You can define the application time zone in [.path]_config.rb_ using `set :time_zone` (a setting shared with the blog extension).
|
175
|
+
If you don't specify a time zone in the page's date or for the application, dates are assumed to be UTC.
|
176
|
+
|
156
177
|
=== Specifying a Layout
|
157
178
|
|
158
179
|
The most important of these page attributes is `page-layout`, which determines the layout that is applied to the page.
|
159
180
|
Middleman will look for the first file that matches this root name under the source directory and use it as the layout.
|
160
|
-
For example, if `page-layout` has the value page
|
161
|
-
You can
|
181
|
+
For example, if `page-layout` has the value `page`, Middleman might resolve a layout named [.path]_page.erb_.
|
182
|
+
You can set the extension of the layout file using the `page-layout-engine` attribute.
|
162
183
|
|
163
184
|
If a layout is not specified, or the value of the `page-layout` attribute is empty, the default layout for the site is used.
|
164
185
|
|
165
|
-
|
186
|
+
You can set a default layout for all pages in [.path]_config.rb_ using:
|
187
|
+
|
188
|
+
[source,ruby]
|
189
|
+
----
|
190
|
+
set :layout, :name_of_layout
|
191
|
+
----
|
192
|
+
|
193
|
+
Alternately, you can set a default layout just for AsciiDoc-based pages (pages processed by this extension) in [.path]_config.rb_ using:
|
194
|
+
|
195
|
+
[source,ruby]
|
196
|
+
----
|
197
|
+
activate :asciidoc, layout: :name_of_layout
|
198
|
+
----
|
199
|
+
|
200
|
+
TIP: When you define the layout in [.path]_config.rb_, you can specify the value either as a String or a Symbol.
|
201
|
+
|
202
|
+
If you don't set the layout in [.path]_config.rb_, the default layout is considered unset.
|
203
|
+
(The one exception to this rule is the layout for blog articles, which is controlled by the configuration for the blog extension).
|
204
|
+
|
205
|
+
AsciiDoc-based pages are configured to use the automatic layout by default (i.e., the `page-layout` attribute is set to blank).
|
206
|
+
If you unset the `page-layout` attribute, the AsciiDoc processor will handle generating a standalone document (`header_footer: true`).
|
166
207
|
In this case, the page will appear like an HTML file that is generated by the AsciiDoc processor directly.
|
167
208
|
|
168
|
-
|
209
|
+
Here are the different ways to specify a layout:
|
169
210
|
|
170
|
-
* `:page-layout:
|
171
|
-
*
|
172
|
-
*
|
173
|
-
*
|
211
|
+
* `:page-layout:`, `:page-layout: _auto_layout`, or _not specified_ -- use the automatic layout (default: layout)
|
212
|
+
* `:page-layout: custom` -- use the page layout named "`custom`" (e.g., [.path]_custom.erb_)
|
213
|
+
* `:!page-layout:` or `:page-layout: false` -- generate a standalone HTML document
|
214
|
+
* `:page-layout: -` -- no layout (don't wrap content in a layout at all)
|
174
215
|
|
175
216
|
.Layout for blog posts
|
176
|
-
WARNING: If you're using the Middleman Blog extension to write blog posts,
|
177
|
-
|
178
|
-
|
217
|
+
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.
|
218
|
+
|
219
|
+
=== Ignoring a Page
|
220
|
+
|
221
|
+
In addition to the normal ignore filter in Middleman, you can also control whether a page is ignored from AsciiDoc.
|
222
|
+
To mark a page as ignored from AsciiDoc, set the `page-ignored` attribute in the AsciiDoc document header to any value other than `false`, as follows:
|
223
|
+
|
224
|
+
[source,asciidoc]
|
225
|
+
----
|
226
|
+
= Ignored Page
|
227
|
+
:page-ignored:
|
228
|
+
----
|
229
|
+
|
230
|
+
Once this page attribute is detected, no further processing is performed on the document by this extension.
|
231
|
+
|
232
|
+
=== Marking an Article as a Draft
|
233
|
+
|
234
|
+
If you're using the Middleman Blog extension, you can mark an article as a draft so it does not get published.
|
235
|
+
To do so, assign the value `false` the page attribute named `page-published` in the AsciiDoc document header, as follows:
|
236
|
+
|
237
|
+
[source,asciidoc]
|
238
|
+
----
|
239
|
+
= Draft Article
|
240
|
+
:page-published: false
|
241
|
+
----
|
242
|
+
|
243
|
+
This effectively sets the `published` key in the page data to `false`.
|
244
|
+
Recall that the AsciiDoc extension converts the value of page attributes as a YAML value, which means the string literal "`false`" becomes the boolean value `false`.
|
245
|
+
Middleman then knows not to publish this article.
|
246
|
+
|
247
|
+
Another option is to set the date of the article way into the future.
|
248
|
+
|
249
|
+
[source,asciidoc]
|
250
|
+
----
|
251
|
+
= Future Post
|
252
|
+
Author Name
|
253
|
+
3001-01-01
|
254
|
+
----
|
255
|
+
|
256
|
+
By default, the blog extension does not publish articles with a future date.
|
257
|
+
|
258
|
+
=== Linking Between Pages
|
259
|
+
|
260
|
+
You can link from one page to another using an {uri-asciidoctor}/docs/user-manual/#inter-document-cross-references[inter-document xref].
|
261
|
+
Let's say you have the following two pages in the source directory:
|
262
|
+
|
263
|
+
* about.adoc
|
264
|
+
* team.adoc
|
265
|
+
|
266
|
+
You can link from the about page to the team page using the following:
|
267
|
+
|
268
|
+
[source,asciidoc]
|
269
|
+
----
|
270
|
+
Meet our <<team.adoc#,team>>.
|
271
|
+
----
|
272
|
+
|
273
|
+
The `.adoc#` suffix indicates the xref targets another page.
|
274
|
+
The target is the path from the current page to the other page (a source-to-source reference).
|
275
|
+
This reference is then converted to the following HTML:
|
276
|
+
|
277
|
+
[source,html]
|
278
|
+
----
|
279
|
+
Meet our <a href="team.html">team</a>.
|
280
|
+
----
|
281
|
+
|
282
|
+
Of course, we're assuming there that the input maps 1-to-1 to the output.
|
283
|
+
That assumption breaks down as soon as you enable directory indexes.
|
284
|
+
|
285
|
+
When directory indexes are enabled, each page is moved into its own folder and renamed to index.html.
|
286
|
+
So how does the xref work in that case?
|
287
|
+
|
288
|
+
This extension provides built-in support for directory indexes.
|
289
|
+
When the directory indexes extension is enabled, this extension automatically defines the `relfileprefix` and `relfilesuffix` attributes on the AsciiDoc document.
|
290
|
+
The `relfilesuffix` attribute honors both the `:trailing_slash` and `:strip_index_file` options in Middleman.
|
291
|
+
However, you have to make one change to your pages for these attributes to work with the xref macro.
|
292
|
+
|
293
|
+
Below the document header (but *not in* the document header), you must assign the `outfilesuffix` attribute to the value of the `relfilesuffix` attribute.
|
294
|
+
Here's an example:
|
295
|
+
|
296
|
+
[source,asciidoc]
|
297
|
+
----
|
298
|
+
= About Us
|
299
|
+
|
300
|
+
// ^ the previous blank line is required!
|
301
|
+
\ifdef::relfilesuffix[:outfilesuffix: {relfilesuffix}]
|
302
|
+
|
303
|
+
...
|
304
|
+
|
305
|
+
Meet our <<team.adoc#,team>>.
|
306
|
+
----
|
307
|
+
|
308
|
+
With the help of the `outfilesuffix` assignment, Asciidoctor automatically produces the correct link to the other page.
|
309
|
+
|
310
|
+
[source,html]
|
311
|
+
----
|
312
|
+
Meet our <a href="../team/">team</a>.
|
313
|
+
----
|
314
|
+
|
315
|
+
Optionally, you can construct the link manually using:
|
316
|
+
|
317
|
+
[source,asciidoc]
|
318
|
+
----
|
319
|
+
Meet our link:{relfileprefix}team{relfilesuffix}[team].
|
320
|
+
----
|
321
|
+
|
322
|
+
I think you'll agree that using the xref macro is simpler.
|
323
|
+
|
324
|
+
=== Controlling the Destination Path
|
325
|
+
|
326
|
+
By default, Middleman does not support controlling the destination path from the page data, often called a permalink.
|
327
|
+
However, with the addition of a simple extension, it's possible to enable this feature.
|
328
|
+
|
329
|
+
Start by adding the following Ruby code to the file [.path]_lib/permalink.rb_.
|
330
|
+
|
331
|
+
.lib/permalink.rb
|
332
|
+
[source,ruby]
|
333
|
+
----
|
334
|
+
class Permalink < Middleman::Extension
|
335
|
+
# Run after front matter extension (priority: 20), after the AsciiDoc extension (priority: 30),
|
336
|
+
# and before other third-party extensions (priority: 50).
|
337
|
+
self.resource_list_manipulator_priority = 35
|
338
|
+
|
339
|
+
def manipulate_resource_list resources
|
340
|
+
resources.each do |resource|
|
341
|
+
if !resource.ignored? && (resource.respond_to? :data) && (permalink = resource.data.permalink)
|
342
|
+
permalink = permalink.slice 1, permalink.length if permalink.start_with? '/'
|
343
|
+
resource.destination_path = %(#{permalink}#{resource.ext})
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
Middleman::Extensions.register :permalink, Permalink
|
350
|
+
----
|
351
|
+
|
352
|
+
Next, require and activate this extension in the [.path]_config.rb_ file for your site:
|
353
|
+
|
354
|
+
[source,ruby]
|
355
|
+
----
|
356
|
+
require_relative 'lib/permalink'
|
357
|
+
activate :permalink
|
358
|
+
----
|
359
|
+
|
360
|
+
You can now customize the destination path for any AsciiDoc-based page by adding the following attribute entry to the document header:
|
361
|
+
|
362
|
+
[source,asciidoc]
|
363
|
+
----
|
364
|
+
:page-permalink: custom-destination-path
|
365
|
+
----
|
366
|
+
|
367
|
+
Customize the destination path to your liking.
|
368
|
+
The leading forward slash (`/`) is optional.
|
179
369
|
|
180
370
|
== Building Your Site
|
181
371
|
|
@@ -229,6 +419,6 @@ Here's how to clone the project and run the tests.
|
|
229
419
|
|
230
420
|
== Copyright
|
231
421
|
|
232
|
-
Copyright (C) 2014-
|
422
|
+
Copyright (C) 2014-2017 Dan Allen and the Asciidoctor Project.
|
233
423
|
Free use of this software is granted under the terms of the MIT License.
|
234
424
|
For the full text of the license, see the <<LICENSE.adoc#,LICENSE>> file.
|