middleman-asciidoc 1.0.0.rc.5 → 1.0.0.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/README.adoc +7 -6
- data/features/asciidoc-blog.feature +0 -1
- data/features/asciidoc-pages.feature +13 -4
- data/fixtures/asciidoc-pages-app/config-set-asciidoc.rb +2 -0
- data/fixtures/asciidoc-pages-app/source/inspect-standard-page-data.html.erb +5 -3
- data/fixtures/asciidoc-pages-app/source/standard-page-data.adoc +2 -1
- data/lib/middleman-asciidoc/extension.rb +69 -46
- data/lib/middleman-asciidoc/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fbada42f7900398ed4146ab4c34415730ff11250e7fe0aeac5fb0a9ab79052f
|
4
|
+
data.tar.gz: 8f8d642ddad76e9543043b12537b8d993e187a488b8441345e6251d868d95b65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08bef99c6140b5dfbfe52cdf0ea75a4fb493cc086b5cd56ba31cd3bf0cdc6bf0b673ad160adf36cb2105e023e6b8363089dab51c895603bf77bfd62aac2a191d
|
7
|
+
data.tar.gz: e205ad469ba66138631ea7cf0040a64df009c7f78129ec658c125e73dcfbd2f49f23edd9a12d73d988463da26c9837a3479395ef123b3f27d727139abb79bb68
|
data/Gemfile
CHANGED
@@ -4,7 +4,9 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
# NOTE when running tests on JRuby, use version of middleman-core that does not depend on fast_blank
|
7
|
-
git 'https://github.com/middleman/middleman.git', ref: '1d13e415e27aa1b30d85fecebf8cc0f91d4023c6' do
|
7
|
+
#git 'https://github.com/middleman/middleman.git', ref: '1d13e415e27aa1b30d85fecebf8cc0f91d4023c6' do
|
8
|
+
# ...and which fixes the misplaced chmod command
|
9
|
+
git 'https://github.com/mojavelinux/middleman.git', branch: 'jruby-compat-fix' do
|
8
10
|
gem 'middleman-core'
|
9
11
|
end if RUBY_ENGINE == 'jruby'
|
10
12
|
|
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.6, 2017-12-07
|
4
4
|
// Settings:
|
5
5
|
:idprefix:
|
6
6
|
:idseparator: -
|
@@ -44,7 +44,7 @@ Specifically, this extension converts AsciiDoc files in your site source to HTML
|
|
44
44
|
This conversion is performed using {uri-asciidoctor}[Asciidoctor] by default.
|
45
45
|
|
46
46
|
IMPORTANT: This extension is designed for Middleman >= 4.0.0.
|
47
|
-
Prior to Middleman 4, AsciiDoc support was
|
47
|
+
Prior to Middleman 4, AsciiDoc support was bundled with Middleman.
|
48
48
|
|
49
49
|
== Installation
|
50
50
|
|
@@ -175,11 +175,12 @@ The value is parsed as https://en.wikipedia.org/wiki/YAML[YAML] data (that which
|
|
175
175
|
In addition to these explicit page attributes, the following AsciiDoc attributes are also promoted to page data:
|
176
176
|
|
177
177
|
* doctitle (i.e., the document title) (becomes title)
|
178
|
-
* author
|
179
|
-
*
|
180
|
-
|
178
|
+
* author (becomes author.name)
|
179
|
+
* email (becomes author.email or author.url)
|
180
|
+
** if value matches the pattern `url[@username]`, author.username is also set
|
181
|
+
* authors (converted to an Array of Author objects)
|
181
182
|
* revdate (becomes date; value is converted to a Time object)
|
182
|
-
* keywords (
|
183
|
+
* keywords (value is kept as a String)
|
183
184
|
* description
|
184
185
|
|
185
186
|
TIP: You can continue to specify page data using the front matter header.
|
@@ -46,7 +46,6 @@ Feature: Blog Integration
|
|
46
46
|
When I go to "/index.html"
|
47
47
|
Then I should not see "/blog/not-published.html"
|
48
48
|
|
49
|
-
@nojava
|
50
49
|
Scenario: A blog article marked as not published should not be published when generating the site
|
51
50
|
Given a fixture app "asciidoc-blog-app"
|
52
51
|
And I run `middleman build`
|
@@ -396,7 +396,7 @@ Feature: AsciiDoc Support
|
|
396
396
|
When I go to "/page-data.html"
|
397
397
|
Then I should see:
|
398
398
|
"""
|
399
|
-
<pre>{"title"=>"Page Data", "v-chrarray"=>["a", "b", "c"], "v-dblquote"=>"\"", "v-empty"=>"", "v-false"=>false, "v-hash"=>{"a"=>"a", "b"=>"b", "c"=>"c"}, "v-null"=>nil, "v-num"=>1, "v-numarray"=>[1, 2, 3], "v-quote"=>"'", "v-true"=>true}</pre>
|
399
|
+
<pre>{"id"=>"page-data", "title"=>"Page Data", "v-chrarray"=>["a", "b", "c"], "v-dblquote"=>"\"", "v-empty"=>"", "v-false"=>false, "v-hash"=>{"a"=>"a", "b"=>"b", "c"=>"c"}, "v-null"=>nil, "v-num"=>1, "v-numarray"=>[1, 2, 3], "v-quote"=>"'", "v-true"=>true}</pre>
|
400
400
|
"""
|
401
401
|
|
402
402
|
Scenario: Promoting standard AsciiDoc attributes to page data
|
@@ -406,8 +406,10 @@ Feature: AsciiDoc Support
|
|
406
406
|
"""
|
407
407
|
<p>Page Title</p>
|
408
408
|
<p>Doc Writer</p>
|
409
|
-
<p>Doc Writer | Junior Writer</p>
|
410
409
|
<p>doc.writer@example.com</p>
|
410
|
+
<p>Doc Writer | Junior Writer</p>
|
411
|
+
<p>https://social.example.com/jrw</p>
|
412
|
+
<p>jrw</p>
|
411
413
|
<p>This is a sample page.</p>
|
412
414
|
<p>meta, AsciiDoc, Middleman</p>
|
413
415
|
"""
|
@@ -471,7 +473,7 @@ Feature: AsciiDoc Support
|
|
471
473
|
When I go to "/manual/index.html"
|
472
474
|
Then I should see:
|
473
475
|
"""
|
474
|
-
<p>Unresolved directive in
|
476
|
+
<p>Unresolved directive in index.adoc - include::_chapters/ch01.adoc[]</p>
|
475
477
|
"""
|
476
478
|
|
477
479
|
Scenario: Including a file relative to document in subdirectory when base_dir is set to app.source_dir
|
@@ -484,7 +486,7 @@ Feature: AsciiDoc Support
|
|
484
486
|
When I go to "/manual/index.html"
|
485
487
|
Then I should see:
|
486
488
|
"""
|
487
|
-
<p>Unresolved directive in
|
489
|
+
<p>Unresolved directive in index.adoc - include::_chapters/ch01.adoc[]</p>
|
488
490
|
"""
|
489
491
|
|
490
492
|
Scenario: Linking to a sibling page with directory indexes activated
|
@@ -621,6 +623,13 @@ Feature: AsciiDoc Support
|
|
621
623
|
When I go to "/custom-attribute.html"
|
622
624
|
Then I should see "bar{baz}"
|
623
625
|
|
626
|
+
Scenario: Warn when options are set using `set :asciidoc`
|
627
|
+
Given a fixture app "asciidoc-pages-app"
|
628
|
+
And app "asciidoc-pages-app" is using config "set-asciidoc"
|
629
|
+
And I run `middleman build`
|
630
|
+
And was successfully built
|
631
|
+
Then the output should contain "Using `set :asciidoc` to set options for AsciiDoc is no longer supported."
|
632
|
+
|
624
633
|
Scenario: Highlighting source code
|
625
634
|
Given a fixture app "asciidoc-pages-app"
|
626
635
|
And a file named "config.rb" with:
|
@@ -1,10 +1,12 @@
|
|
1
1
|
---
|
2
2
|
layout: false
|
3
3
|
---
|
4
|
-
<% page_data = (
|
4
|
+
<% page_data = (sitemap.find_resource_by_page_id 'std-page-data').data %>
|
5
5
|
<p><%= page_data.title %></p>
|
6
|
-
<p><%= page_data.author %></p>
|
6
|
+
<p><%= page_data.author.name %></p>
|
7
|
+
<p><%= page_data.author.email %></p>
|
7
8
|
<p><%= (page_data.authors || []) * ' | ' %></p>
|
8
|
-
<p><%= page_data.
|
9
|
+
<p><%= page_data.authors[1].url %></p>
|
10
|
+
<p><%= page_data.authors[1].username %></p>
|
9
11
|
<p><%= page_data.description %></p>
|
10
12
|
<p><%= page_data.keywords %></p>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
= Page Title
|
2
|
-
Doc Writer <doc.writer@example.com>; Junior Writer
|
2
|
+
Doc Writer <doc.writer@example.com>; Junior Writer <https://social.example.com/jrw[@jrw]>
|
3
|
+
:page-id: std-page-data
|
3
4
|
:showtitle:
|
4
5
|
:description: This is a sample page.
|
5
6
|
:keywords: meta, AsciiDoc, Middleman
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'asciidoctor' unless defined? Asciidoctor
|
2
|
-
require 'active_support/core_ext/time/zones' unless Time.respond_to? :zone
|
3
2
|
|
4
3
|
module Middleman
|
5
4
|
module AsciiDoc
|
@@ -19,40 +18,24 @@ module Middleman
|
|
19
18
|
|
20
19
|
AttributeReferenceRx = /\\?\{(\w+(?:[\-]\w+)*)\}/
|
21
20
|
|
22
|
-
option :attributes, [], '
|
21
|
+
option :attributes, [], 'AsciiDoc attributes passed to all AsciiDoc-based pages. Defaults to empty Array. (Hash or Array)'
|
23
22
|
option :backend, :html5, 'Moniker used to select output format for AsciiDoc-based pages. Defaults to :html5. (Symbol)'
|
24
|
-
option :base_dir, :docdir, 'Base directory to use for the current AsciiDoc document. Defaults to :docdir, which
|
23
|
+
option :base_dir, :docdir, 'Base directory to use for the current AsciiDoc document. Defaults to :docdir, which resolves to the document directory. (String)'
|
25
24
|
option :safe, :safe, 'Safe mode level for AsciiDoc processor. Defaults to :safe. (Symbol)'
|
26
25
|
option :layout, nil, 'Name of layout to use for AsciiDoc-based pages (not blog articles) (String or Symbol)'
|
27
26
|
|
28
27
|
def initialize app, options_hash = {}, &block
|
29
|
-
|
30
|
-
super
|
31
|
-
app.config.define_setting :asciidoc, {}, 'AsciiDoc processor options (Hash)'
|
32
|
-
# NOTE support global :asciidoc_attributes setting for backwards compatibility
|
33
|
-
app.config.define_setting :asciidoc_attributes, [], 'Custom AsciiDoc attributes (Hash or Array)'
|
28
|
+
super unless app.mode? :config
|
34
29
|
end
|
35
30
|
|
36
31
|
# NOTE options passed to activate take precedence (e.g., activate :asciidoc, attributes: ['foo=bar'])
|
37
32
|
def after_configuration
|
38
33
|
app.config[:asciidoc_extensions] = prune_tilt_mapping!
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
# set :time_zone
|
43
|
-
if app.config[:time_zone]
|
44
|
-
::Time.zone = app.config[:time_zone]
|
45
|
-
else
|
46
|
-
::Time.zone ||= 'UTC'
|
47
|
-
end
|
48
|
-
zone_default = ::Time.find_zone! ::Time.zone
|
49
|
-
raise 'Value assigned to time_zone not recognized.' unless zone_default
|
50
|
-
::Time.zone_default = zone_default
|
51
|
-
|
52
|
-
if (app.config.setting :asciidoc).value_set?
|
53
|
-
warn 'Using `set :asciidoc` to define options is deprecated. Please define options on `activate :asciidoc` instead.'
|
34
|
+
set_time_zone app.config[:time_zone]
|
35
|
+
if (app.config.defines_setting? :asciidoc)
|
36
|
+
warn 'Using `set :asciidoc` to set options for AsciiDoc is no longer supported. Please use `activate :asciidoc`.'
|
54
37
|
end
|
55
|
-
app.config[:asciidoc].tap do |cfg|
|
38
|
+
(app.config[:asciidoc] = {}).tap do |cfg|
|
56
39
|
attributes = {
|
57
40
|
'site-root' => app.root.to_s,
|
58
41
|
'site-source' => app.source_dir.to_s,
|
@@ -67,19 +50,11 @@ module Middleman
|
|
67
50
|
end
|
68
51
|
attributes['relfileprefix'] = '../'
|
69
52
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if (options.setting :attributes).value_set?
|
74
|
-
attributes = merge_attributes options[:attributes], attributes
|
75
|
-
# NOTE handles `set :asciidoc_attributes ...`
|
76
|
-
elsif (app.config.setting :asciidoc_attributes).value_set?
|
77
|
-
attributes = merge_attributes options[:asciidoc_attributes], attributes
|
78
|
-
end
|
79
|
-
imagesdir = if attributes.key? 'imagesdir'
|
80
|
-
attributes['imagesdir']
|
53
|
+
attributes = merge_attributes options[:attributes], attributes if (options.setting :attributes).value_set?
|
54
|
+
if attributes.key? 'imagesdir'
|
55
|
+
imagesdir = attributes['imagesdir']
|
81
56
|
else
|
82
|
-
attributes['imagesdir'] = %(#{
|
57
|
+
imagesdir = attributes['imagesdir'] = %(#{[((app.config[:http_prefix] || '').chomp '/'), app.config[:images_dir]] * '/'}@)
|
83
58
|
end
|
84
59
|
if imagesdir && !(attributes.key? 'imagesoutdir') && (imagesdir.start_with? '/')
|
85
60
|
attributes['imagesoutdir'] = ::File.join dest, (imagesdir.chomp '@')
|
@@ -106,23 +81,28 @@ module Middleman
|
|
106
81
|
|
107
82
|
def manipulate_resource_list resources
|
108
83
|
header_asciidoc_opts = app.config[:asciidoc].merge parse_header_only: true
|
109
|
-
|
84
|
+
header_attrs = header_asciidoc_opts[:attributes].merge 'skip-front-matter' => ''
|
110
85
|
use_docdir_as_base_dir = header_asciidoc_opts[:base_dir] == :docdir
|
111
86
|
|
112
87
|
resources.select {|res| !res.ignored? && (asciidoc_file? res) }.each do |resource|
|
113
|
-
|
88
|
+
page_attrs = { 'page-id' => %(#{resource.page_id}@) }
|
89
|
+
if (path = resource.source_file)
|
90
|
+
page_attrs['docfile'] = path
|
91
|
+
page_attrs['docdir'] = (dir = ::File.dirname path)
|
92
|
+
page_attrs['docname'] = ::File.basename path, (page_attrs['docfilesuffix'] = ::File.extname path)
|
93
|
+
end
|
114
94
|
if (page_asciidoc_opts = resource.options.delete :renderer_options)
|
115
|
-
(page_asciidoc_opts[:attributes] ||= {})
|
95
|
+
(page_asciidoc_opts[:attributes] ||= {}).update page_attrs
|
116
96
|
else
|
117
|
-
page_asciidoc_opts = { attributes:
|
97
|
+
page_asciidoc_opts = { attributes: page_attrs }
|
118
98
|
end
|
119
99
|
opts, page = { renderer_options: page_asciidoc_opts }, {}
|
120
100
|
|
121
|
-
|
122
|
-
|
101
|
+
page_header_attrs = { 'page-layout' => %(#{resource.options[:layout]}@) }.merge page_attrs
|
102
|
+
header_asciidoc_opts[:base_dir] = page_asciidoc_opts[:base_dir] = dir if use_docdir_as_base_dir && dir
|
123
103
|
# read AsciiDoc header only to set page options and data
|
124
104
|
# header values can be accessed via app.data.page.<name> in the layout
|
125
|
-
doc = ::Asciidoctor.load_file path, header_asciidoc_opts
|
105
|
+
doc = ::Asciidoctor.load_file path, (header_asciidoc_opts.merge attributes: (header_attrs.merge page_header_attrs))
|
126
106
|
|
127
107
|
if (doc.attr? 'page-ignored') && !(doc.attr? 'page-ignored', 'false')
|
128
108
|
resource.ignore!
|
@@ -153,14 +133,18 @@ module Middleman
|
|
153
133
|
|
154
134
|
page[:title] = doc.doctitle if doc.header?
|
155
135
|
if doc.attr? 'author'
|
156
|
-
page[:author] = (author = doc.attr 'author')
|
136
|
+
page[:author] = (author = AuthorData.new (doc.attr 'author'), (doc.attr 'email'))
|
157
137
|
if (num_authors = (doc.attr 'authorcount').to_i) > 1
|
158
|
-
page[:authors] = num_authors.times.map {|
|
138
|
+
page[:authors] = num_authors.times.map {|i|
|
139
|
+
if doc.attr? %(author_#{idx = i + 1})
|
140
|
+
AuthorData.new (doc.attr %(author_#{idx})), (doc.attr %(email_#{idx}))
|
141
|
+
end
|
142
|
+
}.compact
|
159
143
|
else
|
160
144
|
page[:authors] = [author]
|
161
145
|
end
|
162
146
|
end
|
163
|
-
['
|
147
|
+
['keywords', 'description'].each do |key|
|
164
148
|
page[key.to_sym] = doc.attr key if doc.attr? key
|
165
149
|
end
|
166
150
|
if !(page.key? :date) && (doc.attr? 'revdate')
|
@@ -274,6 +258,23 @@ module Middleman
|
|
274
258
|
::Tilt.mappings.select {|_, classes| classes.include? ::Tilt::AsciidoctorTemplate }.keys.map {|ext| %(.#{ext}) }
|
275
259
|
end
|
276
260
|
end
|
261
|
+
|
262
|
+
# Set Time.zone and Time.zone_default to match behavior of blog extension.
|
263
|
+
#
|
264
|
+
# Make sure ActiveSupport's TimeZone stuff has something to work with,
|
265
|
+
# allowing site owners to set their desired time zone via Time.zone or
|
266
|
+
# `set :time_zone`
|
267
|
+
def set_time_zone tz
|
268
|
+
require 'active_support/core_ext/time/zones' unless ::Time.respond_to? :zone
|
269
|
+
if tz
|
270
|
+
::Time.zone = tz
|
271
|
+
else
|
272
|
+
::Time.zone ||= 'UTC'
|
273
|
+
end
|
274
|
+
zone_default = ::Time.find_zone! ::Time.zone
|
275
|
+
raise 'Value assigned to time_zone not recognized.' unless zone_default
|
276
|
+
::Time.zone_default = zone_default
|
277
|
+
end
|
277
278
|
end
|
278
279
|
|
279
280
|
# Resolves the automatic layout if no layout has been specified and this resource is not a blog article
|
@@ -308,5 +309,27 @@ module Middleman
|
|
308
309
|
resource.respond_to? :blog_data
|
309
310
|
end
|
310
311
|
end
|
312
|
+
|
313
|
+
class AuthorData
|
314
|
+
UrlWithUsernameRx = /^(.+?)\[@([^\]]+)\]$/
|
315
|
+
attr :name, :email, :url, :username
|
316
|
+
|
317
|
+
def initialize name, email_or_url = nil
|
318
|
+
@name = name
|
319
|
+
if email_or_url
|
320
|
+
if email_or_url.start_with? 'https://', 'http://'
|
321
|
+
if (email_or_url.include? '[') && UrlWithUsernameRx =~ email_or_url
|
322
|
+
@url, @username = $1, $2
|
323
|
+
else
|
324
|
+
@url = email_or_url
|
325
|
+
end
|
326
|
+
else
|
327
|
+
@email = email_or_url
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
alias to_s name
|
333
|
+
end
|
311
334
|
end
|
312
335
|
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.
|
4
|
+
version: 1.0.0.rc.6
|
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-
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- fixtures/asciidoc-blog-app/source/layouts/asciidoc_page.erb
|
76
76
|
- fixtures/asciidoc-pages-app/config-global-layout.rb
|
77
77
|
- fixtures/asciidoc-pages-app/config-page-layout.rb
|
78
|
+
- fixtures/asciidoc-pages-app/config-set-asciidoc.rb
|
78
79
|
- fixtures/asciidoc-pages-app/config.rb
|
79
80
|
- fixtures/asciidoc-pages-app/source/_include.adoc
|
80
81
|
- fixtures/asciidoc-pages-app/source/backend.adoc
|
@@ -157,6 +158,7 @@ test_files:
|
|
157
158
|
- fixtures/asciidoc-blog-app/source/layouts/asciidoc_page.erb
|
158
159
|
- fixtures/asciidoc-pages-app/config-global-layout.rb
|
159
160
|
- fixtures/asciidoc-pages-app/config-page-layout.rb
|
161
|
+
- fixtures/asciidoc-pages-app/config-set-asciidoc.rb
|
160
162
|
- fixtures/asciidoc-pages-app/config.rb
|
161
163
|
- fixtures/asciidoc-pages-app/source/_include.adoc
|
162
164
|
- fixtures/asciidoc-pages-app/source/backend.adoc
|