kitabu 1.0.0.rc1 → 1.0.0.rc2
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.
- data/Gemfile.lock +14 -20
- data/README.rdoc +54 -23
- data/kitabu.gemspec +1 -1
- data/lib/kitabu.rb +11 -4
- data/lib/kitabu/cli.rb +49 -6
- data/lib/kitabu/dependency.rb +19 -0
- data/lib/kitabu/exporter.rb +4 -5
- data/lib/kitabu/generator.rb +12 -15
- data/lib/kitabu/parser.rb +27 -2
- data/lib/kitabu/parser/epub.rb +96 -83
- data/lib/kitabu/parser/html.rb +51 -16
- data/lib/kitabu/parser/mobi.rb +1 -4
- data/lib/kitabu/parser/pdf.rb +23 -20
- data/lib/kitabu/parser/txt.rb +1 -5
- data/lib/kitabu/syntax.rb +5 -3
- data/lib/kitabu/syntax/highlight.rb +22 -0
- data/lib/kitabu/toc.rb +4 -78
- data/lib/kitabu/toc/epub.rb +41 -0
- data/lib/kitabu/toc/html.rb +78 -0
- data/lib/kitabu/version.rb +1 -1
- data/spec/kitabu/cli/export_spec.rb +2 -2
- data/spec/kitabu/cli/new_spec.rb +1 -1
- data/spec/kitabu/cli/permalinks_spec.rb +1 -1
- data/spec/kitabu/cli/version_spec.rb +1 -1
- data/spec/kitabu/extensions/redcloth_spec.rb +6 -6
- data/spec/kitabu/extensions/string_spec.rb +1 -1
- data/spec/kitabu/parser/epub_spec.rb +5 -1
- data/spec/kitabu/parser/html_spec.rb +15 -15
- data/spec/kitabu/parser/pdf_spec.rb +4 -4
- data/spec/kitabu/syntax_spec.rb +78 -74
- data/spec/kitabu/{toc_spec.rb → toc/html_spec.rb} +5 -5
- data/spec/spec_helper.rb +3 -1
- data/spec/support/mybook/output/mybook.pdf.html +83 -0
- data/spec/support/mybook/templates/{cover.erb → epub/cover.erb} +1 -1
- data/spec/support/mybook/templates/{epub.erb → epub/page.erb} +1 -1
- data/spec/support/mybook/templates/epub/style.css +0 -0
- data/spec/support/mybook/templates/html/layout.css +353 -0
- data/spec/support/mybook/templates/html/layout.erb +50 -0
- data/spec/support/mybook/templates/html/syntax.css +58 -0
- data/spec/support/mybook/templates/html/user.css +1 -0
- data/spec/support/shared.rb +48 -15
- data/templates/cover.erb +1 -1
- data/templates/cover.png +0 -0
- data/templates/epub.css +1 -0
- data/templates/epub.erb +1 -1
- data/templates/sample.md +6 -0
- data/templates/syntax.css +58 -0
- metadata +32 -44
- data/spec/support/mybook/templates/epub.css +0 -1
- data/spec/support/mybook/templates/layout.css +0 -137
- data/spec/support/mybook/templates/layout.erb +0 -46
- data/spec/support/mybook/templates/syntax.css +0 -186
- data/spec/support/mybook/templates/user.css +0 -1
- data/templates/styles/active4d.css +0 -114
- data/templates/styles/all_hallows_eve.css +0 -72
- data/templates/styles/amy.css +0 -147
- data/templates/styles/blackboard.css +0 -88
- data/templates/styles/brilliance_black.css +0 -605
- data/templates/styles/brilliance_dull.css +0 -599
- data/templates/styles/cobalt.css +0 -149
- data/templates/styles/dawn.css +0 -121
- data/templates/styles/eiffel.css +0 -121
- data/templates/styles/espresso_libre.css +0 -109
- data/templates/styles/idle.css +0 -62
- data/templates/styles/iplastic.css +0 -80
- data/templates/styles/lazy.css +0 -73
- data/templates/styles/mac_classic.css +0 -123
- data/templates/styles/magicwb_amiga.css +0 -104
- data/templates/styles/pastels_on_dark.css +0 -188
- data/templates/styles/slush_poppies.css +0 -85
- data/templates/styles/spacecadet.css +0 -51
- data/templates/styles/sunburst.css +0 -180
- data/templates/styles/twilight.css +0 -137
- data/templates/styles/zenburnesque.css +0 -91
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
kitabu (1.0.0.
|
|
4
|
+
kitabu (1.0.0.rc2)
|
|
5
5
|
RedCloth (~> 4.2)
|
|
6
6
|
activesupport (~> 3.0)
|
|
7
|
+
coderay
|
|
7
8
|
eeepub-with-cover-support (~> 0.8)
|
|
8
9
|
i18n (~> 0.5)
|
|
9
10
|
nokogiri (~> 1.5)
|
|
10
11
|
notifier (~> 0.1)
|
|
11
|
-
pygments.rb (~> 0.2)
|
|
12
12
|
rdiscount (~> 1.6)
|
|
13
13
|
thor (~> 0.14)
|
|
14
14
|
watchr (~> 0.7)
|
|
@@ -20,36 +20,30 @@ GEM
|
|
|
20
20
|
activesupport (3.2.3)
|
|
21
21
|
i18n (~> 0.6)
|
|
22
22
|
multi_json (~> 1.0)
|
|
23
|
-
blankslate (2.1.2.4)
|
|
24
23
|
builder (3.0.0)
|
|
24
|
+
coderay (1.0.6)
|
|
25
25
|
diff-lcs (1.1.3)
|
|
26
26
|
eeepub-with-cover-support (0.8.7)
|
|
27
27
|
builder
|
|
28
28
|
rubyzip
|
|
29
|
-
ffi (1.0.11)
|
|
30
29
|
i18n (0.6.0)
|
|
31
|
-
multi_json (1.3.
|
|
30
|
+
multi_json (1.3.5)
|
|
32
31
|
nokogiri (1.5.2)
|
|
33
|
-
notifier (0.1
|
|
34
|
-
pygments.rb (0.2.12)
|
|
35
|
-
rubypython (~> 0.5.3)
|
|
32
|
+
notifier (0.2.1)
|
|
36
33
|
rake (0.9.2.2)
|
|
37
34
|
rdiscount (1.6.8)
|
|
38
|
-
rspec (2.
|
|
39
|
-
rspec-core (~> 2.
|
|
40
|
-
rspec-expectations (~> 2.
|
|
41
|
-
rspec-mocks (~> 2.
|
|
42
|
-
rspec-core (2.
|
|
43
|
-
rspec-expectations (2.
|
|
35
|
+
rspec (2.10.0)
|
|
36
|
+
rspec-core (~> 2.10.0)
|
|
37
|
+
rspec-expectations (~> 2.10.0)
|
|
38
|
+
rspec-mocks (~> 2.10.0)
|
|
39
|
+
rspec-core (2.10.1)
|
|
40
|
+
rspec-expectations (2.10.0)
|
|
44
41
|
diff-lcs (~> 1.1.3)
|
|
45
|
-
rspec-mocks (2.
|
|
46
|
-
|
|
47
|
-
blankslate (>= 2.1.2.3)
|
|
48
|
-
ffi (~> 1.0.7)
|
|
49
|
-
rubyzip (0.9.7)
|
|
42
|
+
rspec-mocks (2.10.1)
|
|
43
|
+
rubyzip (0.9.8)
|
|
50
44
|
test_notifier (1.0.0)
|
|
51
45
|
notifier
|
|
52
|
-
thor (0.
|
|
46
|
+
thor (0.15.2)
|
|
53
47
|
watchr (0.7)
|
|
54
48
|
|
|
55
49
|
PLATFORMS
|
data/README.rdoc
CHANGED
|
@@ -1,22 +1,42 @@
|
|
|
1
1
|
= kitabu
|
|
2
2
|
|
|
3
|
-
While Prince is too expensive (495USD for a single user license), the free version available at http://www.princexml.com/download
|
|
3
|
+
While Prince is too expensive (495USD for a single user license), the free version available at http://www.princexml.com/download generates a PDF with a small logo on the first page, which is removed when sent to a printer.
|
|
4
4
|
|
|
5
5
|
== Features
|
|
6
6
|
|
|
7
|
-
* Write
|
|
7
|
+
* Write using Markdown, Textile or plain HTML
|
|
8
8
|
* Book layout support
|
|
9
9
|
* Syntax highlight
|
|
10
|
-
* Generate
|
|
10
|
+
* Generate HTML, PDF, e-Pub, Mobi and Text files
|
|
11
11
|
* Table of Contents automatically generated from chapter titles
|
|
12
12
|
|
|
13
13
|
== Installation
|
|
14
14
|
|
|
15
|
-
To install Kitabu, you’ll need a working Ruby installation
|
|
15
|
+
To install Kitabu, you’ll need a working Ruby 1.9+ installation.
|
|
16
16
|
If you’re cool with it, just run the following command to install it.
|
|
17
17
|
|
|
18
18
|
gem install kitabu --pre
|
|
19
19
|
|
|
20
|
+
After installing Kitabu, run the following command to check your external
|
|
21
|
+
dependencies.
|
|
22
|
+
|
|
23
|
+
$ kitabu check
|
|
24
|
+
|
|
25
|
+
Prince XML: Converts HTML files into PDF files.
|
|
26
|
+
Installed.
|
|
27
|
+
|
|
28
|
+
KindleGen: Converts ePub e-books into .mobi files.
|
|
29
|
+
Installed.
|
|
30
|
+
|
|
31
|
+
html2text: Converts HTML documents into plain text.
|
|
32
|
+
Not installed.
|
|
33
|
+
|
|
34
|
+
pygments.rb: A generic syntax highlight. If installed, replaces CodeRay.
|
|
35
|
+
Not installed.
|
|
36
|
+
|
|
37
|
+
There's no requirements here; just make sure you cleared the correct dependency based
|
|
38
|
+
on the formats you want to export to.
|
|
39
|
+
|
|
20
40
|
== Usage
|
|
21
41
|
|
|
22
42
|
To create a new e-book, just run
|
|
@@ -25,20 +45,26 @@ To create a new e-book, just run
|
|
|
25
45
|
|
|
26
46
|
This command creates a directory <tt>mybook</tt> with the following structure:
|
|
27
47
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
mybook
|
|
49
|
+
├── code
|
|
50
|
+
├── config
|
|
51
|
+
│ ├── helper.rb
|
|
52
|
+
│ └── kitabu.yml
|
|
53
|
+
├── images
|
|
54
|
+
├── output
|
|
55
|
+
├── templates
|
|
56
|
+
│ ├── epub
|
|
57
|
+
│ │ ├── cover.erb
|
|
58
|
+
│ │ ├── cover.png
|
|
59
|
+
│ │ ├── page.erb
|
|
60
|
+
│ │ └── user.css
|
|
61
|
+
│ └── html
|
|
62
|
+
│ ├── layout.css
|
|
63
|
+
│ ├── layout.erb
|
|
64
|
+
│ ├── syntax.css
|
|
65
|
+
│ └── user.css
|
|
66
|
+
└── text
|
|
67
|
+
└── 01_Welcome.md
|
|
42
68
|
|
|
43
69
|
The <tt>config/kitabu.yml</tt> file holds some information about your book; so you'll always change it.
|
|
44
70
|
|
|
@@ -76,7 +102,7 @@ To print the TOC, you need to print a variable called +toc+, using the eRb tag.
|
|
|
76
102
|
|
|
77
103
|
=== Syntax Highlighting
|
|
78
104
|
|
|
79
|
-
We use
|
|
105
|
+
We use CodeRay[http://rubygems.org/gems/coderay] for syntax highlighting. To highlight a given code snippet, just do something like
|
|
80
106
|
|
|
81
107
|
@@@ ruby
|
|
82
108
|
class User < ActiveRecord::Base
|
|
@@ -85,7 +111,7 @@ We use Ultraviolet[http://rubygems.org/gems/ultraviolet] for syntax highlighting
|
|
|
85
111
|
end
|
|
86
112
|
@@@
|
|
87
113
|
|
|
88
|
-
|
|
114
|
+
If can replace CodeRay by Pygments; just install the gem pygments.rb[http://rubygems.org/pygments.rb].
|
|
89
115
|
|
|
90
116
|
<b>Don't indent</b> the source block or will end up with unexpected results.
|
|
91
117
|
|
|
@@ -121,18 +147,23 @@ By default, RDiscount[http://github.com/rtomayko/rdiscount/tree/master] is the M
|
|
|
121
147
|
* Maruku: https://rubygems.org/gems/maruku
|
|
122
148
|
* PEGMarkdown: https://rubygems.org/gems/rpeg-markdown
|
|
123
149
|
* BlueCloth: https://rubygems.org/gems/bluecloth
|
|
150
|
+
* Redcarpet: https://rubygems.org/gems/redcarpet
|
|
151
|
+
|
|
152
|
+
Note: RDiscount will always be installed as Kitabu's dependency but only used when no
|
|
153
|
+
alternative library is available.
|
|
124
154
|
|
|
125
155
|
=== References
|
|
126
156
|
|
|
127
|
-
* Textile: http://hobix.com/textile
|
|
157
|
+
* Textile: http://hobix.com/textile
|
|
128
158
|
* Markdown: http://daringfireball.net/projects/markdown/syntax
|
|
129
159
|
|
|
130
160
|
== Samples
|
|
131
161
|
|
|
132
162
|
I published two PDFs (portuguese only) exploring lots of features. Check it out:
|
|
133
163
|
|
|
134
|
-
* http://
|
|
135
|
-
* http://
|
|
164
|
+
* http://cl.ly/3j1s2g1O1b1c0S3M0n20
|
|
165
|
+
* http://cl.ly/1L1o123L3Z0p3P0L1Q3t
|
|
166
|
+
* http://cl.ly/0a2W3s3u2T2P1V0C0c3g
|
|
136
167
|
|
|
137
168
|
There's also an (probably) outdated Rails Guide section in the <tt>examples</tt> directory.
|
|
138
169
|
|
data/kitabu.gemspec
CHANGED
|
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
|
28
28
|
s.add_dependency "eeepub-with-cover-support", "~> 0.8"
|
|
29
29
|
s.add_dependency "watchr", "~> 0.7"
|
|
30
30
|
s.add_dependency "notifier", "~> 0.1"
|
|
31
|
-
s.add_dependency "
|
|
31
|
+
s.add_dependency "coderay"
|
|
32
32
|
|
|
33
33
|
s.add_development_dependency "rspec"
|
|
34
34
|
s.add_development_dependency "test_notifier"
|
data/lib/kitabu.rb
CHANGED
|
@@ -16,6 +16,14 @@ require "watchr"
|
|
|
16
16
|
require "yaml"
|
|
17
17
|
require "cgi"
|
|
18
18
|
|
|
19
|
+
%w[pygments.rb coderay].each do |lib|
|
|
20
|
+
begin
|
|
21
|
+
require lib
|
|
22
|
+
rescue LoadError => e
|
|
23
|
+
next
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
19
27
|
%w[maruku peg_markdown bluecloth redcarpet rdiscount].each do |lib|
|
|
20
28
|
begin
|
|
21
29
|
require lib
|
|
@@ -28,8 +36,6 @@ end
|
|
|
28
36
|
Encoding.default_internal = "utf-8"
|
|
29
37
|
Encoding.default_external = "utf-8"
|
|
30
38
|
|
|
31
|
-
require 'pygments.rb'
|
|
32
|
-
|
|
33
39
|
module Kitabu
|
|
34
40
|
require "kitabu/extensions/string"
|
|
35
41
|
require "kitabu/extensions/redcloth"
|
|
@@ -39,12 +45,13 @@ module Kitabu
|
|
|
39
45
|
|
|
40
46
|
autoload :Version, "kitabu/version"
|
|
41
47
|
autoload :Generator, "kitabu/generator"
|
|
42
|
-
autoload :
|
|
48
|
+
autoload :TOC, "kitabu/toc"
|
|
43
49
|
autoload :Cli, "kitabu/cli"
|
|
44
50
|
autoload :Parser, "kitabu/parser"
|
|
45
51
|
autoload :Exporter, "kitabu/exporter"
|
|
46
52
|
autoload :Syntax, "kitabu/syntax"
|
|
47
53
|
autoload :Stream, "kitabu/stream"
|
|
54
|
+
autoload :Dependency, "kitabu/dependency"
|
|
48
55
|
|
|
49
56
|
def self.config(root_dir = nil)
|
|
50
57
|
root_dir ||= Pathname.new(Dir.pwd)
|
|
@@ -57,6 +64,6 @@ module Kitabu
|
|
|
57
64
|
end
|
|
58
65
|
|
|
59
66
|
def self.logger
|
|
60
|
-
@logger ||= Logger.new(File.open("/tmp/kitabu.log", "a
|
|
67
|
+
@logger ||= Logger.new(File.open("/tmp/kitabu.log", "a"))
|
|
61
68
|
end
|
|
62
69
|
end
|
data/lib/kitabu/cli.rb
CHANGED
|
@@ -46,13 +46,48 @@ module Kitabu
|
|
|
46
46
|
say "Kitabu version #{Version::STRING}"
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
desc "check", "Check if all external dependencies are installed"
|
|
50
|
+
|
|
51
|
+
def check
|
|
52
|
+
result = []
|
|
53
|
+
|
|
54
|
+
result << {
|
|
55
|
+
:description => "Prince XML: Converts HTML files into PDF files.",
|
|
56
|
+
:installed => Kitabu::Dependency.prince?
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
result << {
|
|
60
|
+
:description => "KindleGen: Converts ePub e-books into .mobi files.",
|
|
61
|
+
:installed => Kitabu::Dependency.kindlegen?
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
result << {
|
|
65
|
+
:description => "html2text: Converts HTML documents into plain text.",
|
|
66
|
+
:installed => Kitabu::Dependency.html2text?
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
result << {
|
|
70
|
+
:description => "pygments.rb: A generic syntax highlight. If installed, replaces CodeRay.",
|
|
71
|
+
:installed => Kitabu::Dependency.pygments_rb?
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
result.each do |result|
|
|
75
|
+
text = color(result[:name], :blue)
|
|
76
|
+
text << "\n" << result[:description]
|
|
77
|
+
text << "\n" << (result[:installed] ? color("Installed.", :green) : color("Not installed.", :red))
|
|
78
|
+
text << "\n"
|
|
79
|
+
|
|
80
|
+
say(text)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
49
84
|
desc "permalinks", "List title permalinks"
|
|
50
85
|
|
|
51
86
|
def permalinks
|
|
52
|
-
|
|
53
|
-
toc = Kitabu::Toc.generate(html)
|
|
87
|
+
inside_ebook!
|
|
54
88
|
|
|
55
|
-
|
|
89
|
+
html = Kitabu::Parser::HTML.new(root_dir).content
|
|
90
|
+
toc = Kitabu::TOC::HTML.generate(html)
|
|
56
91
|
|
|
57
92
|
toc.toc.each do |options|
|
|
58
93
|
level = options[:level] - 1
|
|
@@ -60,8 +95,8 @@ module Kitabu
|
|
|
60
95
|
permalink = "##{options[:permalink]}"
|
|
61
96
|
|
|
62
97
|
text = "*" * level
|
|
63
|
-
text << (
|
|
64
|
-
text <<
|
|
98
|
+
text << color(title, :blue)
|
|
99
|
+
text << color(permalink, :yellow)
|
|
65
100
|
say(text)
|
|
66
101
|
end
|
|
67
102
|
end
|
|
@@ -69,7 +104,7 @@ module Kitabu
|
|
|
69
104
|
private
|
|
70
105
|
def inside_ebook!
|
|
71
106
|
unless File.exist?(config_path)
|
|
72
|
-
raise Error, "You
|
|
107
|
+
raise Error, "You have to run this command from inside an e-book directory."
|
|
73
108
|
end
|
|
74
109
|
end
|
|
75
110
|
|
|
@@ -84,5 +119,13 @@ module Kitabu
|
|
|
84
119
|
def root_dir
|
|
85
120
|
@root ||= Pathname.new(Dir.pwd)
|
|
86
121
|
end
|
|
122
|
+
|
|
123
|
+
def color(text, color)
|
|
124
|
+
color? ? shell.set_color(text, color) : text
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def color?
|
|
128
|
+
shell.instance_of?(Thor::Shell::Color)
|
|
129
|
+
end
|
|
87
130
|
end
|
|
88
131
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Kitabu
|
|
2
|
+
class Dependency
|
|
3
|
+
def self.kindlegen?
|
|
4
|
+
@kindlegen ||= `which kindlegen` && $?.success?
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.prince?
|
|
8
|
+
@prince ||= `which prince` && $?.success?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.html2text?
|
|
12
|
+
@html2text ||= `which html2text` && $?.success?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.pygments_rb?
|
|
16
|
+
@pygments_rb ||= defined?(Pygments)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/kitabu/exporter.rb
CHANGED
|
@@ -27,18 +27,17 @@ module Kitabu
|
|
|
27
27
|
helper = root_dir.join("config/helper.rb")
|
|
28
28
|
load(helper) if helper.exist?
|
|
29
29
|
|
|
30
|
-
export_html = [nil, "pdf", "txt", "html"].include?(options[:only])
|
|
31
30
|
export_pdf = [nil, "pdf"].include?(options[:only])
|
|
32
31
|
export_epub = [nil, "mobi", "epub"].include?(options[:only])
|
|
33
32
|
export_mobi = [nil, "mobi"].include?(options[:only])
|
|
34
33
|
export_txt = [nil, "txt"].include?(options[:only])
|
|
35
34
|
|
|
36
35
|
exported = []
|
|
37
|
-
exported << Parser::
|
|
38
|
-
exported << Parser::
|
|
36
|
+
exported << Parser::HTML.parse(root_dir)
|
|
37
|
+
exported << Parser::PDF.parse(root_dir) if export_pdf && Dependency.prince?
|
|
39
38
|
exported << Parser::Epub.parse(root_dir) if export_epub
|
|
40
|
-
exported << Parser::Mobi.parse(root_dir) if export_mobi
|
|
41
|
-
exported << Parser::Txt.parse(root_dir) if export_txt
|
|
39
|
+
exported << Parser::Mobi.parse(root_dir) if export_mobi && Dependency.kindlegen?
|
|
40
|
+
exported << Parser::Txt.parse(root_dir) if export_txt && Dependency.html2text?
|
|
42
41
|
|
|
43
42
|
if exported.all?
|
|
44
43
|
color = :green
|
data/lib/kitabu/generator.rb
CHANGED
|
@@ -14,23 +14,22 @@ module Kitabu
|
|
|
14
14
|
File.dirname(__FILE__) + "/../../templates"
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def
|
|
17
|
+
def copy_html_templates
|
|
18
18
|
copy_file "layout.erb" , "templates/html/layout.erb"
|
|
19
19
|
copy_file "layout.css" , "templates/html/layout.css"
|
|
20
20
|
copy_file "user.css" , "templates/html/user.css"
|
|
21
|
+
copy_file "syntax.css" , "templates/html/syntax.css"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def copy_epub_templates
|
|
21
25
|
copy_file "cover.erb" , "templates/epub/cover.erb"
|
|
22
|
-
copy_file "epub.css" , "templates/epub/
|
|
26
|
+
copy_file "epub.css" , "templates/epub/user.css"
|
|
23
27
|
copy_file "epub.erb" , "templates/epub/page.erb"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
s << File.read(file)
|
|
30
|
-
s << "\n\n"
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
28
|
+
copy_file "cover.png" , "templates/epub/cover.png"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def copy_sample_page
|
|
32
|
+
copy_file "sample.md" , "text/01_Welcome.md"
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
def copy_config_file
|
|
@@ -47,18 +46,16 @@ module Kitabu
|
|
|
47
46
|
def create_directories
|
|
48
47
|
empty_directory "output"
|
|
49
48
|
empty_directory "images"
|
|
50
|
-
empty_directory "text"
|
|
51
49
|
empty_directory "code"
|
|
52
50
|
end
|
|
53
51
|
|
|
54
52
|
def create_git_files
|
|
55
53
|
create_file ".gitignore" do
|
|
56
|
-
"output/*.{html,epub,pdf}\
|
|
54
|
+
"output/*.{html,epub,pdf}\noutput/tmp"
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
create_file "output/.gitkeep"
|
|
60
58
|
create_file "images/.gitkeep"
|
|
61
|
-
create_file "text/.gitkeep"
|
|
62
59
|
create_file "code/.gitkeep"
|
|
63
60
|
end
|
|
64
61
|
|
data/lib/kitabu/parser.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
require 'open3'
|
|
2
|
+
|
|
1
3
|
module Kitabu
|
|
2
4
|
module Parser
|
|
3
|
-
autoload :
|
|
4
|
-
autoload :
|
|
5
|
+
autoload :HTML , "kitabu/parser/html"
|
|
6
|
+
autoload :PDF , "kitabu/parser/pdf"
|
|
5
7
|
autoload :Epub , "kitabu/parser/epub"
|
|
6
8
|
autoload :Mobi , "kitabu/parser/mobi"
|
|
7
9
|
autoload :Txt , "kitabu/parser/txt"
|
|
@@ -29,6 +31,29 @@ module Kitabu
|
|
|
29
31
|
def name
|
|
30
32
|
File.basename(root_dir)
|
|
31
33
|
end
|
|
34
|
+
|
|
35
|
+
# Return the configuration file.
|
|
36
|
+
#
|
|
37
|
+
def config
|
|
38
|
+
Kitabu.config(root_dir)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Render a eRb template using +locals+ as data seed.
|
|
42
|
+
#
|
|
43
|
+
def render_template(file, locals = {})
|
|
44
|
+
ERB.new(File.read(file)).result OpenStruct.new(locals).instance_eval{ binding }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def spawn_command(cmd)
|
|
48
|
+
begin
|
|
49
|
+
stdout_and_stderr, status = Open3.capture2e(*cmd)
|
|
50
|
+
rescue Errno::ENOENT => e
|
|
51
|
+
puts e.message
|
|
52
|
+
else
|
|
53
|
+
puts stdout_and_stderr unless status.success?
|
|
54
|
+
status.success?
|
|
55
|
+
end
|
|
56
|
+
end
|
|
32
57
|
end
|
|
33
58
|
end
|
|
34
59
|
end
|