asciidoctor-htmlbook 0.0.1 → 0.0.2

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: a9f279f879d6126ddd879119caa51fa6fc0906f0
4
- data.tar.gz: 1d55866eaf1bdcfe687d5b7a5dbac4575adf194b
3
+ metadata.gz: 698b27b3f58ab674d66a92098ccfff53d860e451
4
+ data.tar.gz: f23c83a00cd575f20102a1c46a06005b86e53649
5
5
  SHA512:
6
- metadata.gz: 72f2d188d20858d64864bd6c8fe6fbdc62a3b730504ec56a551cc26b3099dd73eb848176085a291fc8c7f3b8524561dadf1784c5b3e5d54601dd162f993bb4c5
7
- data.tar.gz: '08e9f93a2b96e650fc25eb0bbc33270203137fec33673ad63e366b05b115369dd7dc78a9bad725927f9f79b814b2d00b29e93bbd3a03ac5930a8bc9713b2a1b1'
6
+ metadata.gz: a646db7a4e9701ffefb81acff7fcbdd41e7853407690da7dbe13a35642f8fcc0ce0fe1c659dfb30bce679896a7f3e2952a6f2e10e08a2e8f4383e8b58a5d437c
7
+ data.tar.gz: 187c948b262edf7ecc2b10cdf03ee84ac966445311211e4994817595eb91c65c65032e8c9bd77904cbf988a95832102096ae0ef3bc9bb0b0f381378a0e654f46
@@ -0,0 +1,132 @@
1
+ = Asciidoctor HTMLBook
2
+
3
+ Asciidoctor HTMLBook is an link:http://asciidoctor.org/[Asciidoctor] backend for converting AsciiDoc documents to link:http://oreillymedia.github.io/HTMLBook/[HTMLBook] documents.
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ [source, ruby]
10
+ ----
11
+ gem 'asciidoctor-htmlbook'
12
+ ----
13
+
14
+ And then execute:
15
+
16
+ [source, console]
17
+ ----
18
+ $ bundle
19
+ ----
20
+
21
+ Or install it yourself as:
22
+
23
+ [source, console]
24
+ ----
25
+ $ gem install asciidoctor-htmlbook
26
+ ----
27
+
28
+ == Usage
29
+
30
+ === CLI
31
+
32
+ [source, console]
33
+ ----
34
+ $ asciidoctor-htmlbook basic-example.adoc
35
+ ----
36
+
37
+ or
38
+
39
+ [source, console]
40
+ ----
41
+ $ asciidoctor -r asciidoctor-htmlbook basic-example.adoc
42
+ ----
43
+
44
+ For more options:
45
+
46
+ [source, console]
47
+ ----
48
+ $ asciidoctor-htmlbook -h
49
+ ----
50
+
51
+ === API
52
+
53
+ To use Asciidoctor in your application, you first need to require the gem:
54
+
55
+ [source, ruby]
56
+ ----
57
+ require 'asciidoctor/htmlbook'
58
+ ----
59
+
60
+ ==== Load and Convert a File Using the API
61
+
62
+ Load from file:
63
+
64
+ [source, ruby]
65
+ ----
66
+ doc = Asciidoctor.load_file 'mysample.adoc', backend: 'htmlbook'
67
+ puts doc.convert
68
+ ----
69
+
70
+ Convert file:
71
+
72
+ [source, ruby]
73
+ ----
74
+ Asciidoctor.convert_file 'mysample.adoc', backend: 'htmlbook'
75
+ ----
76
+
77
+ ==== Load and Convert Strings Using the API
78
+
79
+ Load from string:
80
+
81
+ [source, ruby]
82
+ ----
83
+ doc = Asciidoctor.load '*This* is Asciidoctor.', backend: 'htmlbook'
84
+ puts doc.convert
85
+ ----
86
+
87
+ Render string:
88
+
89
+ [source, ruby]
90
+ ----
91
+ Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook'
92
+ ----
93
+
94
+ When rendering a string, the header and footer are excluded by default to make Asciidoctor consistent with other lightweight markup engines like Markdown. If you want the header and footer, just enable it using the `:header_footer` option:
95
+
96
+ [source, ruby]
97
+ ----
98
+ Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', header_footer: true
99
+ ----
100
+
101
+ == Provide Custom Templates
102
+
103
+ You can overwrite default templates by adding `:template_dir` option:
104
+
105
+ [source, console]
106
+ ----
107
+ $ asciidoctor-htmlbook -T path/to/templates basic-example.adoc
108
+ ----
109
+
110
+ [source, ruby]
111
+ ----
112
+ Asciidoctor.convert '*This* is Asciidoctor.', backend: 'htmlbook', template_dir: 'path/to/templates'
113
+ ----
114
+
115
+ [NOTE]
116
+ --
117
+ asciidoctor-htmlbook template do not compatible with asciidoctor built-in template backend.
118
+
119
+ View link:./templates[] for more info.
120
+ --
121
+
122
+ == Development
123
+
124
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
125
+
126
+ == Contributing
127
+
128
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chloerei/asciidoctor-htmlbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the link:http://contributor-covenant.org[Contributor Covenant] code of conduct.
129
+
130
+ == License
131
+
132
+ The gem is available as open source under the terms of the link:http://opensource.org/licenses/MIT[MIT License].
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Rei"]
10
10
  spec.email = ["chloerei@gmail.com"]
11
11
 
12
- spec.summary = %q{}
13
- spec.description = %q{}
14
- spec.homepage = ""
12
+ spec.summary = %q{Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents to HTMLBook documents.}
13
+ spec.description = %q{Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents to HTMLBook documents.}
14
+ spec.homepage = "https://github.com/chloerei/asciidoctor-htmlbook"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if File.exist?(asciidoctor_htmlbook = (File.expand_path '../../lib/asciidoctor-htmlbook', __FILE__))
4
+ require asciidoctor_htmlbook
5
+ else
6
+ require 'asciidoctor-htmlbook'
7
+ end
8
+ require 'asciidoctor/cli'
9
+
10
+ options = Asciidoctor::Cli::Options.new backend: 'htmlbook', header_footer: true
11
+
12
+ # FIXME provide an API in Asciidoctor for sub-components to print version information
13
+ unless ARGV != ['-v'] && (ARGV & ['-V', '--version']).empty?
14
+ $stdout.write %(Asciidoctor HTMLbook #{Asciidoctor::Htmlbook::VERSION} using )
15
+ # NOTE the print_version method was added in Asciidoctor 1.5.2
16
+ if options.respond_to? :print_version
17
+ options.print_version
18
+ else
19
+ puts %(Asciidoctor #{::Asciidoctor::VERSION} [http://asciidoctor.org])
20
+ end
21
+ exit 0
22
+ end
23
+
24
+ # FIXME This is a really bizarre API. Please make me simpler.
25
+ case (result = options.parse! ARGV)
26
+ when Integer
27
+ exit result
28
+ else
29
+ invoker = Asciidoctor::Cli::Invoker.new options
30
+ GC.start
31
+ invoker.invoke!
32
+ exit invoker.code
33
+ end
@@ -0,0 +1 @@
1
+ require "asciidoctor/htmlbook"
@@ -7,26 +7,38 @@ module Asciidoctor
7
7
 
8
8
  def initialize(backend, options = {})
9
9
  super
10
+ @template_dirs = (options[:template_dirs] || []).push(DEFAULT_TEMPLATE_PATH)
10
11
  @templates = {}
11
12
  end
12
13
 
13
- def get_template(node_name)
14
- return @templates[node_name] if @templates[node_name]
15
-
16
- path = File.join DEFAULT_TEMPLATE_PATH, "#{node_name}.html"
17
- if File.exist?(path)
18
- @templates[node_name] = Liquid::Template.parse(File.read(path))
14
+ def convert(node, transform = nil, options = {})
15
+ template = if (node.node_name == 'document' && transform == 'embedded')
16
+ get_template('embedded')
17
+ else
18
+ get_template(node.node_name)
19
19
  end
20
+
21
+ template.render 'node' => node_to_liquid(node)
20
22
  end
21
23
 
22
- def convert(node, transform = nil, options = {})
23
- template = get_template(node.node_name)
24
+ private
25
+
26
+ def get_template(name)
27
+ return @templates[name] if @templates[name]
24
28
 
25
- unless template
26
- raise "Template not found #{node.node_name} #{node} #{node.attributes}"
29
+ @template_dirs.each do |template_dir|
30
+ path = File.join template_dir, "#{name}.html"
31
+ if File.exist?(path)
32
+ @templates[name] = Liquid::Template.parse(File.read(path))
33
+ break
34
+ end
27
35
  end
28
36
 
29
- template.render 'node' => node_to_liquid(node)
37
+ unless @templates[name]
38
+ raise "Template not found #{name}"
39
+ end
40
+
41
+ @templates[name]
30
42
  end
31
43
 
32
44
  def node_to_liquid(node)
@@ -67,8 +79,9 @@ module Asciidoctor
67
79
  abstract_node_to_liquid(node).merge({
68
80
  'level' => node.level,
69
81
  'title' => node.title,
70
- 'style' => node.style,
71
82
  'caption' => node.caption,
83
+ 'captioned_title' => node.captioned_title,
84
+ 'style' => node.style,
72
85
  'content' => node.content
73
86
  })
74
87
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Htmlbook
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ {{ node.content }}
@@ -1,4 +1,4 @@
1
1
  <div data-type="example">
2
- {% if node.title %}<h5>{{ node.title }}</h5>{% endif %}
2
+ {% if node.title %}<h5>{{ node.captioned_title }}</h5>{% endif %}
3
3
  {{ node.content }}
4
4
  </div>
@@ -5,7 +5,7 @@
5
5
  {% if node.attributes.width %}width="{{ node.attributes.width }}"{% endif %}
6
6
  {% if node.attributes.height %}height="{{ node.attributes.height }}"{% endif %} />
7
7
  {% if node.attributes.link %}</a>{% endif %}
8
- {% if node.attributes.title %}
9
- <figcaption>{{ node.attributes.title }}</figcaption>
8
+ {% if node.title %}
9
+ <figcaption>{{ node.captioned_title }}</figcaption>
10
10
  {% endif %}
11
11
  </figure>
@@ -36,7 +36,7 @@
36
36
  </section>
37
37
  {% else %}
38
38
  <section id="{{node.id}}" data-type="{{ node.sectname }}">
39
- <h1>{% if node.numbered %}{{ node.sectnum }} {% endif %}{{ node.title }}</h1>
39
+ <h1>{{ node.caption }}{{ node.title }}</h1>
40
40
  {{ node.content }}
41
41
  </section>
42
42
  {% endcase %}
@@ -1,6 +1,6 @@
1
1
  <table>
2
2
  {% if node.title %}
3
- <caption>{{ node.title }}</caption>
3
+ <caption>{{ node.captioned_title }}</caption>
4
4
  {% endif %}
5
5
  {% if node.rows.head.size > 0 %}
6
6
  <thead>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-htmlbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rei
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -94,10 +94,12 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.0'
97
- description: ''
97
+ description: Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc
98
+ documents to HTMLBook documents.
98
99
  email:
99
100
  - chloerei@gmail.com
100
- executables: []
101
+ executables:
102
+ - asciidoctor-htmlbook
101
103
  extensions: []
102
104
  extra_rdoc_files: []
103
105
  files:
@@ -106,12 +108,14 @@ files:
106
108
  - CODE_OF_CONDUCT.md
107
109
  - Gemfile
108
110
  - LICENSE.txt
109
- - README.md
111
+ - README.adoc
110
112
  - Rakefile
111
113
  - asciidoctor-htmlbook.gemspec
112
114
  - bin/console
113
115
  - bin/rake
114
116
  - bin/setup
117
+ - exe/asciidoctor-htmlbook
118
+ - lib/asciidoctor-htmlbook.rb
115
119
  - lib/asciidoctor/htmlbook.rb
116
120
  - lib/asciidoctor/htmlbook/converter.rb
117
121
  - lib/asciidoctor/htmlbook/version.rb
@@ -120,6 +124,7 @@ files:
120
124
  - templates/colist.html
121
125
  - templates/dlist.html
122
126
  - templates/document.html
127
+ - templates/embedded.html
123
128
  - templates/example.html
124
129
  - templates/image.html
125
130
  - templates/inline_anchor.html
@@ -145,7 +150,7 @@ files:
145
150
  - templates/ulist.html
146
151
  - templates/verse.html
147
152
  - templates/video.html
148
- homepage: ''
153
+ homepage: https://github.com/chloerei/asciidoctor-htmlbook
149
154
  licenses:
150
155
  - MIT
151
156
  metadata: {}
@@ -168,5 +173,6 @@ rubyforge_project:
168
173
  rubygems_version: 2.5.2
169
174
  signing_key:
170
175
  specification_version: 4
171
- summary: ''
176
+ summary: Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents
177
+ to HTMLBook documents.
172
178
  test_files: []
data/README.md DELETED
@@ -1,41 +0,0 @@
1
- # Asciidoctor::Htmlbook
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/asciidoctor/htmlbook`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'asciidoctor-htmlbook'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install asciidoctor-htmlbook
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/asciidoctor-htmlbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-