jekyll-asciidoc 1.0.1 → 1.1.1

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
  SHA1:
3
- metadata.gz: 038ace39e983d8f6e710306e70ba7acd02af1c80
4
- data.tar.gz: 81a0bed37126dce92290fb9fc8eb20369e9c27be
3
+ metadata.gz: a32abdc7e23fb224459ef345205b70365abfa35e
4
+ data.tar.gz: 396e273827b48132964fce3a118a155d53417baf
5
5
  SHA512:
6
- metadata.gz: 67b47225a5f907acd69454fe83570c95192ec9b07e968ebeb23b4a192aa912f19a5025ed74cab9e73461c2a1c5d31364a67d988fae00a10ba11f4846a0cf4db1
7
- data.tar.gz: 02bb49e0c9b2a1943ab637fd9e8def0d6e06cf490fc7af444b80feccdfccb1ec9b93463652e52c7428c7cd25812c12c408099d599cc5afaed3e443620ea434b4
6
+ metadata.gz: 5ea1217c030007a8ec10bfb3d8d8ddfcaff910da7918ee9b7f2a30082d8463ae5ef2cd4ba2741d924a9c131f1623382eaf532ee8eb8dedf25c0bc50202dfb28e
7
+ data.tar.gz: fc37dfdb7ed1bbd2c4af2302fae3b6837757cb2bf901b56f8ce8279e1e3cea98388a6b856041c50570e848567403aeef2f875221fda7128dbb82a0f37312df2e
@@ -1,12 +1,30 @@
1
1
  = Jekyll AsciiDoc Plugin (powered by Asciidoctor)
2
2
  Paul Rayner <https://github.com/paulrayner[@paulrayner]>; Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
+ // Settings:
4
+ :idprefix:
5
+ :idseparator: -
6
+ ifndef::env-github[:icons: font]
7
+ ifdef::env-github,env-browser[]
3
8
  :toc: preamble
4
9
  :toclevels: 1
5
-
6
- image:https://badge.fury.io/rb/jekyll-asciidoc.svg["Gem Version", link="https://badge.fury.io/rb/jekyll-asciidoc"]
10
+ endif::[]
11
+ ifdef::env-github[]
12
+ :status:
13
+ :outfilesuffix: .adoc
14
+ :!toc-title:
15
+ :caution-caption: :fire:
16
+ :important-caption: :exclamation:
17
+ :note-caption: :paperclip:
18
+ :tip-caption: :bulb:
19
+ :warning-caption: :warning:
20
+ endif::[]
7
21
 
8
22
  A plugin for http://jekyllrb.com[Jekyll] that converts http://asciidoc.org[AsciiDoc] files in your site source to HTML pages using http://asciidoctor.org[Asciidoctor].
9
23
 
24
+ ifdef::status[]
25
+ image::https://img.shields.io/gem/v/jekyll-asciidoc.svg?label=gem%20version[Gem Version, link=https://rubygems.org/gems/jekyll-asciidoc]
26
+ endif::[]
27
+
10
28
  == Overview
11
29
 
12
30
  The plugin consists of three extensions:
@@ -92,7 +110,7 @@ To add a page composed in AsciiDoc, simply add an AsciiDoc file to the root of t
92
110
  ---
93
111
  ---
94
112
  = Sample Page
95
- :layout: page
113
+ :page-layout: page
96
114
  :permalink: /page/
97
115
 
98
116
  This is a sample page composed in AsciiDoc.
@@ -107,6 +125,9 @@ puts "Hello, World!"
107
125
  IMPORTANT: The AsciiDoc file must have a http://jekyllrb.com/docs/frontmatter/[YAML front matter] header or else it won't be recognized as a page.
108
126
  You can use an empty front matter header, as shown above, or you can define all your document metadata (e.g., document title) in the front matter instead of AsciiDoc attributes.
109
127
 
128
+ NOTE: AsciiDoc attributes defined in the document header whose names begin with `page-` are promoted to Jekyll front matter.
129
+ The part of the name after the `page-` prefix is used as the key (e.g., page-layout becomes layout).
130
+
110
131
  You can now build your site using:
111
132
 
112
133
  $ jekyll build
@@ -138,6 +159,15 @@ asciidoc_ext: asciidoc,adoc,ad
138
159
 
139
160
  The extensions shown in the previous listing are the default values, so you don't need to specify this option if those defaults are sufficient.
140
161
 
162
+ AsciiDoc attributes defined in the document header whose names begin with `page-` are promoted to Jekyll front matter.
163
+ The part of the name after the `page-` prefix is used as the key (e.g., page-layout becomes layout).
164
+ If you want to change this attribute prefix, add the following line to your [path]_{empty}_config.yml_:
165
+
166
+ [source,yaml]
167
+ asciidoc_page_attribute_prefix: jekyll
168
+
169
+ A hyphen is automatically added to the value of this configuration setting if the value is non-empty.
170
+
141
171
  To pass additional attributes to AsciiDoc, or override the default attributes defined in the plugin, add the following lines to your [path]_{empty}_config.yml_:
142
172
 
143
173
  [source,yaml]
@@ -347,7 +377,7 @@ Our recommendation is to keep lobbying for them to enable it.
347
377
 
348
378
  You can automate publishing of the generated site to GitHub Pages using a continuous integration job.
349
379
  Refer to the tutorial http://eshepelyuk.github.io/2014/10/28/automate-github-pages-travisci.html[Automate GitHub Pages publishing with Jekyll and Travis CI^] to find step-by-step instructions to setup this job.
350
- You can also refer to the https://github.com/johncarl81/transfuse/tree/transfuse-jeykll-site[Tranfuse website build^] for an example in practice.
380
+ You can also refer to the https://github.com/johncarl81/transfuse-site[Tranfuse website build^] for an example in practice.
351
381
 
352
382
  Refer to the https://help.github.com/articles/using-jekyll-plugins-with-github-pages[Jekyll Plugins on GitHub Pages] for a list of the plugins currently supported on the server-side (in addition to Markdown, which isn't listed).
353
383
 
@@ -3,6 +3,10 @@ JEKYLL_MIN_VERSION_3 = Gem::Version.new(Jekyll::VERSION) >= Gem::Version.new('3.
3
3
  module Jekyll
4
4
  module Converters
5
5
  class AsciiDocConverter < Converter
6
+ IMPLICIT_ATTRIBUTES = %W(
7
+ env=site env-site site-gen=jekyll site-gen-jekyll builder=jekyll builder-jekyll jekyll-version=#{Jekyll::VERSION}
8
+ )
9
+
6
10
  safe true
7
11
 
8
12
  highlighter_prefix "\n"
@@ -10,45 +14,45 @@ module Jekyll
10
14
 
11
15
  def initialize(config)
12
16
  @config = config
13
- @config['asciidoc'] ||= 'asciidoctor'
14
- @config['asciidoc_ext'] ||= 'asciidoc,adoc,ad'
15
- @asciidoctor_config = (@config['asciidoctor'] ||= {})
16
- # convert keys to symbols
17
- @asciidoctor_config.keys.each do |key|
18
- @asciidoctor_config[key.to_sym] = @asciidoctor_config.delete(key)
19
- end
20
- @asciidoctor_config[:safe] ||= 'safe'
21
- user_defined_attributes = @asciidoctor_config[:attributes]
22
- @asciidoctor_config[:attributes] = %w(notitle hardbreaks idprefix= idseparator=- linkattrs)
23
- unless user_defined_attributes.nil?
24
- @asciidoctor_config[:attributes].concat(user_defined_attributes)
17
+ config['asciidoc'] ||= 'asciidoctor'
18
+ asciidoc_ext = (config['asciidoc_ext'] ||= 'asciidoc,adoc,ad')
19
+ config['asciidoc_ext_re'] = Regexp.new("\.(#{asciidoc_ext.tr ',', '|'})$", Regexp::IGNORECASE)
20
+ config['asciidoc_page_attribute_prefix'] ||= 'page'
21
+ unless (asciidoctor_config = (config['asciidoctor'] ||= {})).frozen?
22
+ # NOTE convert keys to symbols
23
+ asciidoctor_config.keys.each do |key|
24
+ asciidoctor_config[key.to_sym] = asciidoctor_config.delete(key)
25
+ end
26
+ asciidoctor_config[:safe] ||= 'safe'
27
+ (asciidoctor_config[:attributes] ||= []).tap do |attributes|
28
+ attributes.unshift('notitle', 'hardbreaks', 'idprefix', 'idseparator=-', 'linkattrs')
29
+ attributes.concat(IMPLICIT_ATTRIBUTES)
30
+ end
31
+ asciidoctor_config.freeze
25
32
  end
26
- @asciidoctor_config[:attributes].push('env-jekyll')
27
33
  end
28
34
 
29
35
  def setup
30
36
  return if @setup
37
+ @setup = true
31
38
  case @config['asciidoc']
32
- when 'asciidoctor'
33
- begin
34
- require 'asciidoctor'
35
- @setup = true
36
- rescue LoadError
37
- STDERR.puts 'You are missing a library required to convert AsciiDoc files. Please run:'
38
- STDERR.puts ' $ [sudo] gem install asciidoctor'
39
- raise FatalException.new("Missing dependency: asciidoctor")
40
- end
41
- else
42
- STDERR.puts "Invalid AsciiDoc processor: #{@config['asciidoc']}"
43
- STDERR.puts " Valid options are [ asciidoctor ]"
44
- raise FatalException.new("Invalid AsciiDoc process: #{@config['asciidoc']}")
39
+ when 'asciidoctor'
40
+ begin
41
+ require 'asciidoctor' unless defined? ::Asciidoctor
42
+ rescue LoadError
43
+ STDERR.puts 'You are missing a library required to convert AsciiDoc files. Please run:'
44
+ STDERR.puts ' $ [sudo] gem install asciidoctor'
45
+ raise FatalException.new('Missing dependency: asciidoctor')
46
+ end
47
+ else
48
+ STDERR.puts "Invalid AsciiDoc processor: #{@config['asciidoc']}"
49
+ STDERR.puts ' Valid options are [ asciidoctor ]'
50
+ raise FatalException.new("Invalid AsciiDoc processor: #{@config['asciidoc']}")
45
51
  end
46
- @setup = true
47
52
  end
48
53
 
49
54
  def matches(ext)
50
- rgx = "\.(#{@config['asciidoc_ext'].tr ',', '|'})$"
51
- ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
55
+ ext =~ @config['asciidoc_ext_re']
52
56
  end
53
57
 
54
58
  def output_ext(ext)
@@ -59,18 +63,18 @@ module Jekyll
59
63
  setup
60
64
  case @config['asciidoc']
61
65
  when 'asciidoctor'
62
- Asciidoctor.render(content, @config['asciidoctor'])
66
+ Asciidoctor.convert(content, @config['asciidoctor'])
63
67
  else
64
68
  warn 'Unknown AsciiDoc converter. Passing through raw content.'
65
69
  content
66
70
  end
67
71
  end
68
72
 
69
- def load(content)
73
+ def load_header(content)
70
74
  setup
71
75
  case @config['asciidoc']
72
76
  when 'asciidoctor'
73
- Asciidoctor.load(content, :parse_header_only => true)
77
+ Asciidoctor.load(content, parse_header_only: true)
74
78
  else
75
79
  warn 'Unknown AsciiDoc converter. Cannot load document header.'
76
80
  nil
@@ -87,55 +91,45 @@ module Jekyll
87
91
  site.find_converter_instance(Jekyll::Converters::AsciiDocConverter) :
88
92
  site.getConverterImpl(Jekyll::Converters::AsciiDocConverter)
89
93
  asciidoc_converter.setup
90
- key_prefix = (site.config['asciidoc_key_prefix'] || 'jekyll-')
91
- key_prefix_len = key_prefix.length
94
+ unless (page_attr_prefix = site.config['asciidoc_page_attribute_prefix']).empty?
95
+ page_attr_prefix = %(#{page_attr_prefix}-)
96
+ end
97
+ page_attr_prefix_l = page_attr_prefix.length
98
+
92
99
  site.pages.each do |page|
93
100
  if asciidoc_converter.matches(page.ext)
94
- doc = asciidoc_converter.load(page.content)
95
- next if doc.nil?
101
+ next unless (doc = asciidoc_converter.load_header(page.content))
96
102
 
97
- page.data['title'] ||= doc.doctitle
98
- page.data['author'] = doc.author unless doc.author.nil?
103
+ page.data['title'] = doc.doctitle if doc.header?
104
+ page.data['author'] = doc.author if doc.author
99
105
 
100
- doc.attributes.each do |key, val|
101
- if key.start_with?(key_prefix)
102
- page.data[key[key_prefix_len..-1]] ||= val
103
- end
106
+ unless (additional_page_data = SafeYAML.load(doc.attributes
107
+ .select {|name| name.start_with?(page_attr_prefix) }
108
+ .map {|name, val| %(#{name[page_attr_prefix_l..-1]}: #{val}) }
109
+ .join("\n"))).empty?
110
+ page.data.update(additional_page_data)
104
111
  end
105
112
 
106
- unless page.data.has_key? 'layout'
107
- if doc.attr? 'page-layout'
108
- page.data['layout'] ||= doc.attr 'page-layout'
109
- else
110
- page.data['layout'] ||= 'default'
111
- end
112
- end
113
+ page.data['layout'] = 'default' unless page.data.key? 'layout'
113
114
  end
114
115
  end
116
+
115
117
  (JEKYLL_MIN_VERSION_3 ? site.posts.docs : site.posts).each do |post|
116
118
  if asciidoc_converter.matches(JEKYLL_MIN_VERSION_3 ? post.data['ext'] : post.ext)
117
- doc = asciidoc_converter.load(post.content)
118
- next if doc.nil?
119
-
120
- post.data['title'] ||= doc.doctitle
121
- post.data['author'] = doc.author unless doc.author.nil?
122
- # TODO carry over date
123
- # setting categories doesn't work here, we lose the post
124
- #post.data['categories'] ||= (doc.attr 'categories') if (doc.attr? 'categories')
125
-
126
- doc.attributes.each do |key, val|
127
- if key.start_with?(key_prefix)
128
- post.data[key[key_prefix_len..-1]] ||= val
129
- end
130
- end
119
+ next unless (doc = asciidoc_converter.load_header(post.content))
131
120
 
132
- unless post.data.has_key? 'layout'
133
- if doc.attr? 'page-layout'
134
- post.data['layout'] ||= doc.attr 'page-layout'
135
- else
136
- post.data['layout'] ||= 'post'
137
- end
121
+ post.data['title'] = doc.doctitle if doc.header?
122
+ post.data['author'] = doc.author if doc.author
123
+ post.data['date'] = DateTime.parse(doc.revdate).to_time if doc.attr? 'revdate'
124
+
125
+ unless (additional_page_data = SafeYAML.load(doc.attributes
126
+ .select {|name| name.start_with?(page_attr_prefix) }
127
+ .map {|name, val| %(#{name[page_attr_prefix_l..-1]}: #{val}) }
128
+ .join("\n"))).empty?
129
+ post.data.update(additional_page_data)
138
130
  end
131
+
132
+ post.data['layout'] = 'post' unless post.data.key? 'layout'
139
133
  end
140
134
  end
141
135
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module AsciiDoc
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-asciidoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-19 00:00:00.000000000 Z
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor