bookit 0.1.0 → 0.2.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.
data/bookit.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "bookit"
4
- s.version = "0.1.0"
4
+ s.version = "0.2.0"
5
5
  s.platform = Gem::Platform::RUBY
6
6
 
7
7
  s.authors = ["Luke van der Hoeven"]
data/examples/test.rb CHANGED
@@ -1,8 +1,8 @@
1
- $: << './lib/'
1
+ $: << '../lib/'
2
2
  require 'bookit'
3
3
 
4
4
  base = {
5
- content: File.read('./examples/article3.html'),
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::Epub)
14
+ content = a.to_print(Bookit::Emitter::Mobi).render
15
+ puts content
16
+
data/lib/bookit.rb CHANGED
@@ -20,6 +20,7 @@ module Bookit
20
20
  autoload :Abstract, 'bookit/emitter/abstract'
21
21
  autoload :Pdf, 'bookit/emitter/pdf'
22
22
  autoload :Epub, 'bookit/emitter/epub'
23
+ autoload :Mobi, 'bookit/emitter/mobi'
23
24
  end
24
25
  end
25
26
 
@@ -13,7 +13,7 @@ module Bookit
13
13
  <b>#{@article.author}</b>
14
14
  <br/>
15
15
  <i>
16
- #{Time.parse(@article.date_published).strftime("%d/%m/%Y")}
16
+ #{@article.date_published}
17
17
  <br/>
18
18
  #{@article.url}
19
19
  </i>
@@ -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.1.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-07 00:00:00 -04:00
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