bookit 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bookit.gemspec +1 -1
- data/examples/test.rb +5 -3
- data/lib/bookit.rb +1 -0
- data/lib/bookit/emitter/epub.rb +1 -1
- data/lib/bookit/emitter/mobi.rb +51 -0
- metadata +3 -2
data/bookit.gemspec
CHANGED
data/examples/test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
$: << '
|
1
|
+
$: << '../lib/'
|
2
2
|
require 'bookit'
|
3
3
|
|
4
4
|
base = {
|
5
|
-
content: File.read('
|
5
|
+
content: File.read('article2.html'),
|
6
6
|
author: "What?",
|
7
7
|
title: "Who?",
|
8
8
|
date_published: Time.now.to_s,
|
@@ -11,4 +11,6 @@ base = {
|
|
11
11
|
|
12
12
|
a = Bookit::Article.new(base, Bookit::Parser::Html)
|
13
13
|
|
14
|
-
a.to_print(Bookit::Emitter::
|
14
|
+
content = a.to_print(Bookit::Emitter::Mobi).render
|
15
|
+
puts content
|
16
|
+
|
data/lib/bookit.rb
CHANGED
data/lib/bookit/emitter/epub.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Bookit
|
4
|
+
class Emitter
|
5
|
+
class Mobi < Abstract
|
6
|
+
def generate
|
7
|
+
tfile = Tempfile.new(["temp", ".html"])
|
8
|
+
tfile.write %{
|
9
|
+
<!DOCTYPE html>
|
10
|
+
<html>
|
11
|
+
<metadata>
|
12
|
+
<dc:Title>#{@article.title}</dc:Title>
|
13
|
+
</metadata>
|
14
|
+
<body>
|
15
|
+
<h1>#{@article.title}</h1>
|
16
|
+
<b>#{@article.author}</b>
|
17
|
+
<br/>
|
18
|
+
<i>
|
19
|
+
#{@article.date_published}
|
20
|
+
<br/>
|
21
|
+
#{@article.url}
|
22
|
+
</i>
|
23
|
+
<br/>
|
24
|
+
#{@article.content.raw_content}
|
25
|
+
</body>
|
26
|
+
</html>
|
27
|
+
}
|
28
|
+
|
29
|
+
tfile.close
|
30
|
+
@path = tfile.path
|
31
|
+
|
32
|
+
`kindlegen -c2 #{@path} -o out.mobi`
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def filepath
|
37
|
+
File.join(File.dirname(@path), 'out.mobi')
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
IO.binread(filepath)
|
42
|
+
end
|
43
|
+
|
44
|
+
def save(filename)
|
45
|
+
File.open(filename, 'w') do |f|
|
46
|
+
f << File.read(filepath)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bookit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Luke van der Hoeven
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05-
|
13
|
+
date: 2011-05-11 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/bookit/emitter/abstract.rb
|
93
93
|
- lib/bookit/emitter/base.rb
|
94
94
|
- lib/bookit/emitter/epub.rb
|
95
|
+
- lib/bookit/emitter/mobi.rb
|
95
96
|
- lib/bookit/emitter/pdf.rb
|
96
97
|
- lib/bookit/parser.rb
|
97
98
|
- lib/bookit/parser/html.rb
|