asciidoctor-kindle 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d247792f28f1a7309807eef9de85f9222ab337a6
4
+ data.tar.gz: 9ce35e28e4dbd484502e5bd351bf9e7aa0abf5ff
5
+ SHA512:
6
+ metadata.gz: b7ca402a67727e2ed7510c535b2fec1b4925407b8a0043afad918d675ca296f8602ccc4ed3e440a579306b20e5002e4d57c907090adc5ae0c6515821dc720e76
7
+ data.tar.gz: 17d63da023d98685deafcc82656473cd1374c49dfa0f47667a8c45c63329e1ad8996a1f71574bf11a4c40125cba17f905ebbd994d8f582464398cbd52780743d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+
9
+ script:
10
+ - rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asciidoctor-kindle.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 midnightSuyama
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # asciidoctor-kindle
2
+
3
+ [![Build Status](https://travis-ci.org/midnightSuyama/asciidoctor-kindle.svg?branch=master)](https://travis-ci.org/midnightSuyama/asciidoctor-kindle)
4
+
5
+ Asciidoctor extension for converting html to mobi
6
+
7
+ * Fix HTML file (ContentType and StyleType)
8
+ * Create TOC file (kindle-toc.html)
9
+ * Create OPF file (kindle-package.opf)
10
+
11
+ ## Installation
12
+
13
+ $ gem install asciidoctor-kindle
14
+
15
+ ## Usage
16
+
17
+ $ asciidoctor-kindle example.adoc
18
+
19
+ or
20
+
21
+ $ asciidoctor -r asciidoctor-kindle example.adoc
22
+ $ kindlegen -o kindle-published.mobi kindle-package.opf
23
+
24
+ ## Document Attributes
25
+
26
+ * `kindle-uid` - unique-identifier in OPF
27
+ * `kindle-description` - dc:description in OPF
28
+ * `kindle-cover` - cover-image in OPF
29
+
30
+ ## Development
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/midnightSuyama/asciidoctor-kindle.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new :test do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/test_*.rb'
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'asciidoctor-kindle/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "asciidoctor-kindle"
7
+ spec.version = Asciidoctor::Kindle::VERSION
8
+ spec.authors = ["midnightSuyama"]
9
+ spec.email = ["midnightSuyama@gmail.com"]
10
+
11
+ spec.summary = "Asciidoctor extension for converting html to mobi"
12
+ spec.description = "Asciidoctor extension for converting html to mobi"
13
+ spec.homepage = "https://github.com/midnightSuyama/asciidoctor-kindle"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "minitest-hooks", "~> 1.5"
26
+
27
+ spec.add_runtime_dependency "asciidoctor"
28
+ spec.add_runtime_dependency "kindlegen"
29
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'asciidoctor'
4
+ require 'asciidoctor/cli'
5
+ require 'kindlegen'
6
+
7
+ options = Asciidoctor::Cli::Options.new
8
+ options[:requires] = ['asciidoctor-kindle']
9
+ options[:output_file] = 'kindle-content.html'
10
+ options.parse! ARGV
11
+
12
+ invoker = Asciidoctor::Cli::Invoker.new options
13
+ GC.start
14
+ invoker.invoke!
15
+
16
+ if invoker.code == 0
17
+ stdout, stderr, status = Kindlegen.run(options[:output_file], '-o', 'kindle-published.mobi')
18
+ if status == 0
19
+ puts stdout
20
+ else
21
+ $stderr.puts stderr
22
+ end
23
+ end
@@ -0,0 +1,94 @@
1
+ require 'asciidoctor/extensions'
2
+
3
+ include Asciidoctor
4
+
5
+ class KindlePostprocessor < Extensions::Postprocessor
6
+ TocName = 'kindle-toc.html'
7
+ OpfName = 'kindle-package.opf'
8
+
9
+ def process(doc, output)
10
+ generate_toc(doc)
11
+ generate_opf(doc)
12
+
13
+ content_type = %(<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">)
14
+ style_type = %(<style type="text/css">)
15
+ output.sub(/<head>(.*)<\/head>/m) do
16
+ "<head>#{content_type}#{$1.gsub(/<style>/m, style_type)}</head>"
17
+ end
18
+ end
19
+
20
+ def generate_toc(doc)
21
+ params = {
22
+ sectnumlevels: doc.attr('sectnumlevels', '3').to_i,
23
+ toclevels: doc.attr('toclevels', '2').to_i,
24
+ outfile: doc.attr('outfile')
25
+ }
26
+
27
+ toc = ['<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body><nav epub:type="toc">']
28
+ toc << orderedlist(doc, params)
29
+ toc << '</nav></body></html>'
30
+ str = toc * LF
31
+
32
+ File.write(File.join(doc.attr('outdir'), TocName), str)
33
+ end
34
+
35
+ def generate_opf(doc)
36
+ uid = doc.attr('kindle-uid', 'asciidoctor-kindle')
37
+ title = doc.attr('doctitle')
38
+ creator = doc.attr('author')
39
+ description = doc.attr('kindle-description')
40
+ publisher = doc.attr('kindle-publisher', doc.attr('author'))
41
+ date = doc.attr('docdate')
42
+ language = doc.attr('lang', 'en')
43
+ content_path = doc.attr('outfile')
44
+ toc_path = File.join(doc.attr('outdir'), TocName)
45
+ cover_path = doc.attr('kindle-cover')
46
+
47
+ str = %(<?xml version="1.0" encoding="utf-8"?>
48
+ <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="#{uid}">
49
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
50
+ <dc:title>#{title}</dc:title>
51
+ <dc:creator>#{creator}</dc:creator>
52
+ <dc:description>#{description}</dc:description>
53
+ <dc:publisher>#{publisher}</dc:publisher>
54
+ <dc:date>#{date}</dc:date>
55
+ <dc:language>#{language}</dc:language>
56
+ </metadata>
57
+ <manifest>
58
+ <item id="content" media-type="text/html" href="#{content_path}" />
59
+ <item id="toc" media-type="text/html" href="#{toc_path}" properties="nav" />
60
+ #{%(<item id="cover" media-type="image/jpeg" href="#{cover_path}" properties="cover-image" />) if cover_path}
61
+ </manifest>
62
+ <spine>
63
+ <itemref idref="content" />
64
+ </spine>
65
+ <guide>
66
+ #{%(<reference type="toc" title="Table of Contents" href="#{content_path}" />) if doc.attr?('toc')}
67
+ </guide>
68
+ </package>)
69
+
70
+ File.write(File.join(doc.attr('outdir'), OpfName), str)
71
+ end
72
+
73
+ def orderedlist(node, params)
74
+ return unless node.sections?
75
+ result = ['<ol>']
76
+ node.sections.each do |section|
77
+ title = section.title
78
+ title = %(#{section.sectnum} #{title}) if section.numbered && section.level <= params[:sectnumlevels]
79
+ if section.level < params[:toclevels] && (children = orderedlist(section, params))
80
+ result << %(<li><a href="#{params[:outfile]}##{section.id}">#{title}</a>)
81
+ result << children
82
+ result << '</li>'
83
+ else
84
+ result << %(<li><a href="#{params[:outfile]}##{section.id}">#{title}</a></li>)
85
+ end
86
+ end
87
+ result << '</ol>'
88
+ result * LF
89
+ end
90
+ end
91
+
92
+ Extensions.register do
93
+ postprocessor KindlePostprocessor
94
+ end
@@ -0,0 +1,5 @@
1
+ module Asciidoctor
2
+ module Kindle
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciidoctor-kindle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - midnightSuyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-hooks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: asciidoctor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: kindlegen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Asciidoctor extension for converting html to mobi
84
+ email:
85
+ - midnightSuyama@gmail.com
86
+ executables:
87
+ - asciidoctor-kindle
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - asciidoctor-kindle.gemspec
98
+ - bin/asciidoctor-kindle
99
+ - lib/asciidoctor-kindle.rb
100
+ - lib/asciidoctor-kindle/version.rb
101
+ homepage: https://github.com/midnightSuyama/asciidoctor-kindle
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.5.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Asciidoctor extension for converting html to mobi
125
+ test_files: []