my_ebook_pub 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +2 -0
- data/bin/assets/droid_sans.ttf +0 -0
- data/bin/assets/template.erb +77 -0
- data/bin/pub +29 -0
- data/lib/my_ebook_pub/version.rb +3 -0
- data/lib/my_ebook_pub.rb +128 -0
- data/my_ebook_pub.gemspec +28 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22fe07b34312a7e107ca4debb4c7bd41bb2f0858
|
4
|
+
data.tar.gz: b27b5a62635bd7743b6da0428023ef482f956131
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3445a31a4c4968748fd496a920e505ae3755f4482ae5b76a018a88bd6cf5151c814580df47ac5fd8028b8a69e690f5e3369d729d7c3265e5b2695ffc05b5686
|
7
|
+
data.tar.gz: ff34c3cd90bb97e2803ce31977f22eb4df6e336b16bd900c936f786b0d5cda649233abf5781d7de95d02b81c7d8aaa2c5f8cbbfffc7092ac4a0f180b1f86bad5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Dave Haeffner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# MyEbookPub
|
2
|
+
|
3
|
+
Convert content written in markdown into a polished PDF
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'my_ebook_pub'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install my_ebook_pub
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```sh
|
24
|
+
> pub
|
25
|
+
Usage:
|
26
|
+
pub new
|
27
|
+
pub generate
|
28
|
+
```
|
29
|
+
|
30
|
+
### New
|
31
|
+
|
32
|
+
```sh
|
33
|
+
> pub new
|
34
|
+
Creating new pub directory structure...
|
35
|
+
assets
|
36
|
+
assets/droid_sans.ttf
|
37
|
+
assets/template.erb
|
38
|
+
content
|
39
|
+
content/chapters
|
40
|
+
content/chapters/1.md
|
41
|
+
content/cover.md
|
42
|
+
content/preface.md
|
43
|
+
output
|
44
|
+
Your project is ready for content!
|
45
|
+
```
|
46
|
+
|
47
|
+
### Generate
|
48
|
+
|
49
|
+
```sh
|
50
|
+
> pub generate
|
51
|
+
Generating PDF to output directory...
|
52
|
+
Your file is ready. See ./output/render.pdf
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( https://github.com/[my-github-username]/my_ebook_pub/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,77 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
4
|
+
<style type="text/css">
|
5
|
+
@font-face {
|
6
|
+
font-family: 'Droid Sans';
|
7
|
+
font-style: normal;
|
8
|
+
font-weight: 400;
|
9
|
+
src: url('droid_sans.ttf');
|
10
|
+
-fs-pdf-font-embed: embed;
|
11
|
+
-fs-pdf-font-encoding: Identity-H;
|
12
|
+
}
|
13
|
+
body {
|
14
|
+
font-family: 'Droid Sans';
|
15
|
+
}
|
16
|
+
div.page_footer {
|
17
|
+
}
|
18
|
+
h1 {
|
19
|
+
page-break-before: always;
|
20
|
+
}
|
21
|
+
pre {
|
22
|
+
white-space: pre;
|
23
|
+
white-space: pre-wrap;
|
24
|
+
page-break-inside: avoid;
|
25
|
+
orphans: 0;
|
26
|
+
widows: 0;
|
27
|
+
background-color: #f5f5f5;
|
28
|
+
border: 1px solid #ccc;
|
29
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
30
|
+
border-radius: 4px;
|
31
|
+
display: block;
|
32
|
+
padding: 9.5px;
|
33
|
+
margin: 0 0 10px;
|
34
|
+
font-size: 13px;
|
35
|
+
line-height: 20px;
|
36
|
+
}
|
37
|
+
code {
|
38
|
+
padding: 2px 4px;
|
39
|
+
background-color: #f7f7f9;
|
40
|
+
}
|
41
|
+
img {
|
42
|
+
width: 600px;
|
43
|
+
}
|
44
|
+
table {
|
45
|
+
page-break-inside: avoid;
|
46
|
+
orphans: 0;
|
47
|
+
widows: 0;
|
48
|
+
font-size: 12px;
|
49
|
+
border-collapse:collapse;
|
50
|
+
margin:20px 0 0;
|
51
|
+
padding:0;
|
52
|
+
}
|
53
|
+
table tr {
|
54
|
+
border-top:1px solid #ccc;
|
55
|
+
background-color:#fff;
|
56
|
+
margin:0;
|
57
|
+
padding:0;
|
58
|
+
}
|
59
|
+
table tr:nth-child(2n) {
|
60
|
+
background-color:#f8f8f8;
|
61
|
+
}
|
62
|
+
table tr th[align="center"], table tr td[align="center"] {
|
63
|
+
text-align:center;
|
64
|
+
}
|
65
|
+
table tr th, table tr td {
|
66
|
+
border:1px solid #ccc;
|
67
|
+
text-align:left;
|
68
|
+
margin:0;
|
69
|
+
padding:6px 13px;
|
70
|
+
}
|
71
|
+
<%= Pygments.css %>
|
72
|
+
</style>
|
73
|
+
</head>
|
74
|
+
<body>
|
75
|
+
<%= @content %>
|
76
|
+
</body>
|
77
|
+
</html>
|
data/bin/pub
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
case ARGV[0]
|
6
|
+
when 'new'
|
7
|
+
STDOUT.puts 'Creating new pub directory structure...'
|
8
|
+
FileUtils.mkpath 'content/chapters'
|
9
|
+
FileUtils.touch 'content/cover.md'
|
10
|
+
FileUtils.touch 'content/preface.md'
|
11
|
+
FileUtils.touch 'content/chapters/1.md'
|
12
|
+
FileUtils.mkdir 'output'
|
13
|
+
FileUtils.mkdir 'assets'
|
14
|
+
FileUtils.cp_r(Dir.glob(File.join(File.expand_path(File.dirname(__FILE__)), 'assets', '*')),
|
15
|
+
File.join(Dir.pwd, 'assets'))
|
16
|
+
STDOUT.puts Dir.glob('**/*')
|
17
|
+
STDOUT.puts 'Your project is ready for content!'
|
18
|
+
when 'generate', 'gen'
|
19
|
+
STDOUT.puts 'Generating PDF to output directory...'
|
20
|
+
require 'my_ebook_pub'
|
21
|
+
MyEbookPub.generate
|
22
|
+
STDOUT.puts 'Your file is ready. See ./output/render.pdf'
|
23
|
+
else
|
24
|
+
STDOUT.puts <<-EOF
|
25
|
+
Usage:
|
26
|
+
pub new
|
27
|
+
pub generate
|
28
|
+
EOF
|
29
|
+
end
|
data/lib/my_ebook_pub.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
require "my_ebook_pub/version"
|
2
|
+
require 'redcarpet'
|
3
|
+
require 'redcarpet/render_strip'
|
4
|
+
require 'erb'
|
5
|
+
require 'pygments'
|
6
|
+
require 'docverter'
|
7
|
+
|
8
|
+
module MyEbookPub
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
@template = File.read('assets/template.erb')
|
13
|
+
|
14
|
+
class HighlightedCopyWithChapterNumbering < Redcarpet::Render::HTML
|
15
|
+
def header(text, header_level)
|
16
|
+
if header_level == 1
|
17
|
+
@counter ||= 0
|
18
|
+
@counter += 1
|
19
|
+
"<h1 id=\"chapter#{@counter}\"><small>Chapter #{@counter}</small><br>#{text}</h1>\n"
|
20
|
+
else
|
21
|
+
"<h#{header_level}>#{text}</h#{header_level}>\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def block_code(code, language)
|
26
|
+
Pygments.highlight(code, lexer: language, encoding: 'utf-8')
|
27
|
+
end
|
28
|
+
|
29
|
+
def postprocess(document)
|
30
|
+
document.gsub(''', "'")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class CopyWithNoFrills < Redcarpet::Render::HTML
|
35
|
+
def block_code(code, language)
|
36
|
+
Pygments.highlight(code, :lexer => language)
|
37
|
+
end
|
38
|
+
|
39
|
+
def postprocess(document)
|
40
|
+
document.gsub(''', "'")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class TOCwithChapterNumbering < Redcarpet::Render::StripDown
|
45
|
+
attr_reader :chapters
|
46
|
+
|
47
|
+
def header(text, header_level)
|
48
|
+
return unless header_level == 1
|
49
|
+
@chapters ||= []
|
50
|
+
@chapters << text
|
51
|
+
""
|
52
|
+
end
|
53
|
+
|
54
|
+
def postprocess(document)
|
55
|
+
items = []
|
56
|
+
@chapters.each_with_index do |text, chapter_number|
|
57
|
+
items << "<li><a href=\"#chapter#{chapter_number+1}\">#{text}</a></li>"
|
58
|
+
end
|
59
|
+
return <<HERE
|
60
|
+
<ol>
|
61
|
+
#{items.join("\n")}
|
62
|
+
</ol>
|
63
|
+
HERE
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
@renderer_toc = Redcarpet::Markdown.new(TOCwithChapterNumbering, fenced_code_blocks: true)
|
69
|
+
@renderer_content = Redcarpet::Markdown.new(HighlightedCopyWithChapterNumbering, fenced_code_blocks: true, tables: true)
|
70
|
+
@renderer_no_frills = Redcarpet::Markdown.new(CopyWithNoFrills, fenced_code_blocks: true)
|
71
|
+
|
72
|
+
def vacuum
|
73
|
+
tmp = ""
|
74
|
+
tmp << yield
|
75
|
+
tmp << "\n\n"
|
76
|
+
tmp
|
77
|
+
end
|
78
|
+
|
79
|
+
def cover
|
80
|
+
@renderer_no_frills.render(vacuum { File.read("#{@location}/cover.md") })
|
81
|
+
end
|
82
|
+
|
83
|
+
def acknowledgements
|
84
|
+
@renderer_no_frills.render(vacuum { File.read("#{@location}/acknowledgements.md") })
|
85
|
+
end
|
86
|
+
|
87
|
+
def preface
|
88
|
+
@renderer_no_frills.render(vacuum { File.read("#{@location}/preface.md") })
|
89
|
+
end
|
90
|
+
|
91
|
+
def toc
|
92
|
+
'<h1>Table of Contents</h1>' + @renderer_toc.render(raw_content)
|
93
|
+
end
|
94
|
+
|
95
|
+
def raw_content
|
96
|
+
content = ""
|
97
|
+
number_of_chapters.times do |chapter|
|
98
|
+
content << File.read("#{@location}/chapters/#{chapter + 1}.md")
|
99
|
+
end
|
100
|
+
content
|
101
|
+
end
|
102
|
+
|
103
|
+
def number_of_chapters
|
104
|
+
Dir.glob("#{@location}/chapters/[0-9].md").count + Dir.glob("#{@location}/chapters/[0-9][0-9].md").count
|
105
|
+
end
|
106
|
+
|
107
|
+
def content
|
108
|
+
@renderer_content.render(raw_content)
|
109
|
+
end
|
110
|
+
|
111
|
+
def generate # to PDF
|
112
|
+
@location = 'content'
|
113
|
+
@content = cover + preface + toc + content
|
114
|
+
html = ERB.new(@template).result(binding)
|
115
|
+
product_name = 'render'
|
116
|
+
File.open("output/#{product_name}.pdf", 'w+') do |f|
|
117
|
+
f.write(Docverter::Conversion.run do |c|
|
118
|
+
c.from = 'html'
|
119
|
+
c.to = 'pdf'
|
120
|
+
c.content = html
|
121
|
+
Dir.glob('assets/*') do |asset|
|
122
|
+
c.add_other_file asset
|
123
|
+
end
|
124
|
+
end)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'my_ebook_pub/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "my_ebook_pub"
|
8
|
+
spec.version = MyEbookPub::VERSION
|
9
|
+
spec.authors = ["Dave Haeffner"]
|
10
|
+
spec.email = ["dhaeffner@gmail.com"]
|
11
|
+
spec.summary = %q{A simple ebook creator. Turns Markdown files into PDF, EPUB, and MOBI with a linked table of contents.}
|
12
|
+
spec.description = %q{Based on Pete's Keen approach https://github.com/peterkeen/mmp-builder from his Adventures in Self Publishing https://www.petekeen.net/adventures-in-self-publishing}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
#spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.executables = ["pub"]
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_dependency "gimli", "~> 0.5.7"
|
25
|
+
spec.add_dependency "docverter", "~> 1.0.1"
|
26
|
+
spec.add_dependency "redcarpet", "~> 3.2.2"
|
27
|
+
spec.add_dependency "pygments.rb", "~> 0.6.3"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: my_ebook_pub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Haeffner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gimli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.7
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.7
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: docverter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pygments.rb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.6.3
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.6.3
|
97
|
+
description: Based on Pete's Keen approach https://github.com/peterkeen/mmp-builder
|
98
|
+
from his Adventures in Self Publishing https://www.petekeen.net/adventures-in-self-publishing
|
99
|
+
email:
|
100
|
+
- dhaeffner@gmail.com
|
101
|
+
executables:
|
102
|
+
- pub
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/assets/droid_sans.ttf
|
112
|
+
- bin/assets/template.erb
|
113
|
+
- bin/pub
|
114
|
+
- lib/my_ebook_pub.rb
|
115
|
+
- lib/my_ebook_pub/version.rb
|
116
|
+
- my_ebook_pub.gemspec
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.5
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: A simple ebook creator. Turns Markdown files into PDF, EPUB, and MOBI with
|
141
|
+
a linked table of contents.
|
142
|
+
test_files: []
|