jekyll-asciidoc 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.adoc +146 -0
  4. data/Rakefile +11 -0
  5. data/lib/jekyll-asciidoc.rb +153 -0
  6. metadata +79 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c945c1ab8b0b9f0d1d712dfcb56270a607ce1f60
4
+ data.tar.gz: 6851d397d5074be07773dedfc8d1a68bbc3415e8
5
+ SHA512:
6
+ metadata.gz: cad0f06fa92eb33550ebb956654fbe2201f7e6b89516ea60dab20b0d5585a91c9a6491c06e6e476b297a5be9b8324e487d3892c6093585a86959866c0d910d45
7
+ data.tar.gz: 68041fc55d6688e1684d2a7357c9158d47f34953f637e73335f2278323948a41c4d0d390ea0beb2c5dd431815a2d1ebd8c4845687c7527e9413fed8e58755fdf
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2013 Dan Allen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,146 @@
1
+ = Jekyll AsciiDoc Plugin (powered by Asciidoctor)
2
+ Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
+
4
+ A http://jekyllrb.com[Jekyll] plugin that converts http://asciidoc.org[AsciiDoc] files in your site source to HTML pages using http://asciidoctor.org[Asciidoctor].
5
+
6
+ The plugin consists of three extensions:
7
+
8
+ `Jekyll::Converters::AsciiDocConverter`::
9
+ Converts AsciiDoc files to HTML
10
+ `Jekyll::Generators::AsciiDocPreprocessor`::
11
+ Promotes select AsciiDoc attributes to Jekyll front matter (e.g., title, author, page-layout)
12
+ `Jekyll::Filters.asciidocify`::
13
+ A Liquid filter for converting AsciiDoc content to HTML using the AsciiDocConverter
14
+
15
+ All these extensions are included in the file `lib/asciidoc_plugin.rb`.
16
+
17
+ == Installation
18
+
19
+ The plugin depends on the Asciidoctor gem (named http://rubygems.org/gems/asciidoctor[asciidoctor]).
20
+ You can install the gem using:
21
+
22
+ $ gem install asciidoctor
23
+
24
+ If you are using Bundler to manage the dependencies in your Jekyll project, then add the Asciidoctor gem instead to your `Gemfile` (below the Jekyll gem, named jekyll):
25
+
26
+ [source,ruby]
27
+ source 'https://rubygems.org'
28
+ gem 'jekyll'
29
+ gem 'asciidoctor'
30
+
31
+ Then, run the Bundler install command, `bundle`:
32
+
33
+ $ bundle
34
+
35
+ === Using a release
36
+
37
+ First, install the Jekyll AsciiDoc gem (named `jekyll-asciidoc`):
38
+
39
+ $ gem install jekyll-asciidoc`
40
+
41
+ If you are using Bundler to manage the dependencies, add the `jekyll-asciidoc` gem to your `Gemfile`:
42
+
43
+ [source,ruby]
44
+ gem 'jekyll-asciidoc'
45
+
46
+ Then, run the Bundler command to install it:
47
+
48
+ $ bundle
49
+
50
+ Finally, add the `jekyll-asciidoc` gem to the list of gems for Jekyll to load in your site's `_config.yml` file:
51
+
52
+ [source,yaml]
53
+ gems:
54
+ - jekyll-asciidoc
55
+
56
+ === Using the development version
57
+
58
+ To install the development version of this plugin, copy `lib/asciidoc_plugin.rb` to the `_plugins` directory in the root of your site source.
59
+
60
+ NOTE: If no `_plugins` directory exists, you need to first create it.
61
+
62
+ == Creating Pages
63
+
64
+ To add a page composed in AsciiDoc, simply add an AsciiDoc file to the root of the project with an AsciiDoc file extension.
65
+
66
+ .sample.adoc
67
+ [source,asciidoc]
68
+ ....
69
+ ---
70
+ ---
71
+ = Sample Page
72
+ :layout: page
73
+ :permalink: /page/
74
+
75
+ This is a sample page composed in AsciiDoc.
76
+ Jekyll converts it to HTML using http://asciidoctor.org[Asciidoctor].
77
+
78
+ [source,ruby]
79
+ ----
80
+ puts "Hello, World!"
81
+ ----
82
+ ....
83
+
84
+ IMPORTANT: The AsciiDoc file must have a Markdown-style front matter header or else it won't be recognized as a page.
85
+ 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.
86
+
87
+ You can now build your site using:
88
+
89
+ $ jekyll build
90
+
91
+ and preview it using:
92
+
93
+ $ jekyll serve
94
+
95
+ IMPORTANT: If you use the `--safe` option, the AsciiDoc plugin will not be activated.
96
+ The `--safe` flag disables third-party plugins such as this one.
97
+
98
+ == Configuration (Optional)
99
+
100
+ By default, this plugin uses Asciidoctor to convert AsciiDoc files.
101
+ Since Asciidoctor is the only option, the default setting is equivalent to the following configuration in `_config.yml`:
102
+
103
+ [source,yaml]
104
+ asciidoc: asciidoctor
105
+
106
+ To tell Jekyll which extensions to recognize as AsciiDoc files, add the following line to your `_config.yml`:
107
+
108
+ [source,yaml]
109
+ asciidoc_ext: asciidoc,adoc,ad
110
+
111
+ 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.
112
+
113
+ To pass additional attributes to AsciiDoc, or override the default attributes defined in the plugin, add the following lines to your `_config.yml`:
114
+
115
+ [source,yaml]
116
+ asciidoctor:
117
+ attributes:
118
+ - hardbreaks!
119
+ - source-highlighter=pygments
120
+ - pygments-css=style
121
+
122
+ === Hard line breaks
123
+
124
+ The Jekyll AsciiDoc integration is configured to preserve hard line breaks in paragraph content by default.
125
+ Since many Jekyll users are used to writing in GitHub-flavored Markdown (GFM), this default was selected to ease the transition to AsciiDoc.
126
+ If you want the standard AsciiDoc behavior of collapsing hard line breaks in paragraph content, add the following settings to your site's `_config.yml` file:
127
+
128
+ [source,yaml]
129
+ asciidoctor:
130
+ attributes:
131
+ - hardbreaks!
132
+
133
+ If you already have AsciiDoc attributes defined in the `_config.yml`, the `hardbreaks!` attribute should be added as a sibling entry in the YAML collection.
134
+
135
+ == GitHub Pages
136
+
137
+ GitHub doesn't (yet) whitelist the AsciiDoc plugin, so you can only run it on your own machine.
138
+
139
+ TIP: GitHub needs to hear from enough users that they want to plugin in order to enable it.
140
+ Our recommendation is to keep lobbying for them to enable it.
141
+
142
+ You can automate publishing of the generated site to GitHub Pages using a continuous integration job.
143
+ 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.
144
+ You can also refer to the https://github.com/johncarl81/transfuse/tree/transfuse-jeykll-site[Tranfuse website build^] for an example in practice.
145
+
146
+ 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).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake/clean'
2
+
3
+ default_tasks = []
4
+
5
+ begin
6
+ require 'bundler/gem_tasks'
7
+ default_tasks << :build
8
+ rescue LoadError
9
+ end
10
+
11
+ task :default => default_tasks unless default_tasks.empty?
@@ -0,0 +1,153 @@
1
+ module Jekyll
2
+ module Converters
3
+ class AsciiDocConverter < Converter
4
+ safe true
5
+
6
+ highlighter_prefix "\n"
7
+ highlighter_suffix "\n"
8
+
9
+ def initialize(config)
10
+ @config = config
11
+ @config['asciidoc'] ||= 'asciidoctor'
12
+ @config['asciidoc_ext'] ||= 'asciidoc,adoc,ad'
13
+ @asciidoctor_config = (@config['asciidoctor'] ||= {})
14
+ # convert keys to symbols
15
+ @asciidoctor_config.keys.each do |key|
16
+ @asciidoctor_config[key.to_sym] = @asciidoctor_config.delete(key)
17
+ end
18
+ @asciidoctor_config[:safe] ||= 'safe'
19
+ user_defined_attributes = @asciidoctor_config[:attributes]
20
+ @asciidoctor_config[:attributes] = %w(notitle! hardbreaks idprefix= idseparator=- linkattrs)
21
+ unless user_defined_attributes.nil?
22
+ @asciidoctor_config[:attributes].concat(user_defined_attributes)
23
+ end
24
+ @asciidoctor_config[:attributes].push('env-jekyll')
25
+ end
26
+
27
+ def setup
28
+ return if @setup
29
+ case @config['asciidoc']
30
+ when 'asciidoctor'
31
+ begin
32
+ require 'asciidoctor'
33
+ @setup = true
34
+ rescue LoadError
35
+ STDERR.puts 'You are missing a library required to convert AsciiDoc files. Please run:'
36
+ STDERR.puts ' $ [sudo] gem install asciidoctor'
37
+ raise FatalException.new("Missing dependency: asciidoctor")
38
+ end
39
+ else
40
+ STDERR.puts "Invalid AsciiDoc processor: #{@config['asciidoc']}"
41
+ STDERR.puts " Valid options are [ asciidoctor ]"
42
+ raise FatalException.new("Invalid AsciiDoc process: #{@config['asciidoc']}")
43
+ end
44
+ @setup = true
45
+ end
46
+
47
+ def matches(ext)
48
+ rgx = "\.(#{@config['asciidoc_ext'].tr ',', '|'})$"
49
+ ext =~ Regexp.new(rgx, Regexp::IGNORECASE)
50
+ end
51
+
52
+ def output_ext(ext)
53
+ '.html'
54
+ end
55
+
56
+ def convert(content)
57
+ setup
58
+ case @config['asciidoc']
59
+ when 'asciidoctor'
60
+ Asciidoctor.render(content, @config['asciidoctor'])
61
+ else
62
+ warn 'Unknown AsciiDoc converter. Passing through raw content.'
63
+ content
64
+ end
65
+ end
66
+
67
+ def load(content)
68
+ setup
69
+ case @config['asciidoc']
70
+ when 'asciidoctor'
71
+ Asciidoctor.load(content, :parse_header_only => true)
72
+ else
73
+ warn 'Unknown AsciiDoc converter. Cannot load document header.'
74
+ nil
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ module Generators
81
+ # Promotes select AsciiDoc attributes to Jekyll front matter
82
+ class AsciiDocPreprocessor < Generator
83
+ def generate(site)
84
+ asciidoc_converter = site.getConverterImpl(Jekyll::Converters::AsciiDocConverter)
85
+ asciidoc_converter.setup
86
+ key_prefix = (site.config['asciidoc_key_prefix'] || 'jekyll-')
87
+ key_prefix_len = key_prefix.length
88
+ site.pages.each do |page|
89
+ if asciidoc_converter.matches(page.ext)
90
+ doc = asciidoc_converter.load(page.content)
91
+ next if doc.nil?
92
+
93
+ page.data['title'] ||= doc.doctitle
94
+ page.data['author'] = doc.author unless doc.author.nil?
95
+
96
+ doc.attributes.each do |key, val|
97
+ if key.start_with?(key_prefix)
98
+ page.data[key[key_prefix_len..-1]] ||= val
99
+ end
100
+ end
101
+
102
+ unless page.data.has_key? 'layout'
103
+ if doc.attr? 'page-layout'
104
+ page.data['layout'] ||= doc.attr 'page-layout'
105
+ else
106
+ page.data['layout'] ||= 'default'
107
+ end
108
+ end
109
+ end
110
+ end
111
+ site.posts.each do |post|
112
+ if asciidoc_converter.matches(post.ext)
113
+ doc = asciidoc_converter.load(post.content)
114
+ next if doc.nil?
115
+
116
+ post.data['title'] ||= doc.doctitle
117
+ post.data['author'] = doc.author unless doc.author.nil?
118
+ # TODO carry over date
119
+ # setting categories doesn't work here, we lose the post
120
+ #post.data['categories'] ||= (doc.attr 'categories') if (doc.attr? 'categories')
121
+
122
+ doc.attributes.each do |key, val|
123
+ if key.start_with?(key_prefix)
124
+ post.data[key[key_prefix_len..-1]] ||= val
125
+ end
126
+ end
127
+
128
+ unless post.data.has_key? 'layout'
129
+ if doc.attr? 'page-layout'
130
+ post.data['layout'] ||= doc.attr 'page-layout'
131
+ else
132
+ post.data['layout'] ||= 'post'
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ module Filters
142
+ # Convert an AsciiDoc string into HTML output.
143
+ #
144
+ # input - The AsciiDoc String to convert.
145
+ #
146
+ # Returns the HTML formatted String.
147
+ def asciidocify(input)
148
+ site = @context.registers[:site]
149
+ converter = site.getConverterImpl(Jekyll::Converters::AsciiDocConverter)
150
+ converter.convert(input)
151
+ end
152
+ end
153
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-asciidoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.alpha.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Allen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: asciidoctor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ description: A Jekyll plugin that converts AsciiDoc files in your site source to HTML
42
+ pages using Asciidoctor.
43
+ email:
44
+ - dan.j.allen@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - README.adoc
51
+ - Rakefile
52
+ - lib/jekyll-asciidoc.rb
53
+ homepage: https://github.com/asciidoctor/jekyll-asciidoc
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.1
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: A Jekyll plugin that converts AsciiDoc files in your site source to HTML
77
+ pages using Asciidoctor.
78
+ test_files: []
79
+ has_rdoc: