kindler 0.1.9 → 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/lib/kindler/version.rb +1 -1
- data/lib/kindler.rb +8 -4
- data/spec/cases/generator_spec.rb +31 -6
- metadata +4 -4
data/lib/kindler/version.rb
CHANGED
data/lib/kindler.rb
CHANGED
@@ -13,7 +13,7 @@ module Kindler
|
|
13
13
|
|
14
14
|
attr_accessor :title,:author,:pages,:pages_by_section,:local_images,:mobi_type
|
15
15
|
|
16
|
-
|
16
|
+
TMP_DIR_PREFIX = '__km_'
|
17
17
|
DEFAULT_SECTION = "All Pages"
|
18
18
|
PAGE_ATTRIBUTES = %w(wrap title author content section url)
|
19
19
|
|
@@ -24,7 +24,7 @@ module Kindler
|
|
24
24
|
# @option debug [Boolean] whether puts debug infos
|
25
25
|
# @option keep_image [Boolean] whether keep images, default to true
|
26
26
|
def initialize(options={})
|
27
|
-
@output_dir = options[:output_dir] || '
|
27
|
+
@output_dir = options[:output_dir] || ''
|
28
28
|
@keep_image = options[:keep_image] || true
|
29
29
|
@debug = options[:debug]
|
30
30
|
@title = options[:title] || ''
|
@@ -83,7 +83,11 @@ module Kindler
|
|
83
83
|
|
84
84
|
# check mobi file is generated already
|
85
85
|
def generated?
|
86
|
-
File.exist?
|
86
|
+
File.exist? book_path
|
87
|
+
end
|
88
|
+
|
89
|
+
def book_path
|
90
|
+
"#{tmp_dir}/#{valid_title}.mobi"
|
87
91
|
end
|
88
92
|
|
89
93
|
private
|
@@ -307,7 +311,7 @@ module Kindler
|
|
307
311
|
|
308
312
|
# the dir path to generated files
|
309
313
|
def tmp_dir
|
310
|
-
File.
|
314
|
+
File.expand_path (@output_dir == '' ? "#{TMP_DIR_PREFIX}#{valid_title}" : @output_dir)
|
311
315
|
end
|
312
316
|
|
313
317
|
def valid_title
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe "Mobi book file generator" do
|
3
3
|
|
4
|
-
|
4
|
+
after :all do
|
5
|
+
puts '==== clear tmp files ==='
|
6
|
+
`rm -rf ./__*`
|
7
|
+
end
|
5
8
|
|
6
9
|
it "should have the title,author property" do
|
7
10
|
title = 'first-book'
|
@@ -24,8 +27,8 @@ describe "Mobi book file generator" do
|
|
24
27
|
author = 'mike'
|
25
28
|
book = Kindler::Book.new :title=>title,:author=>author,:debug=>true
|
26
29
|
book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
|
27
|
-
File.should be_exist("./#{
|
28
|
-
File.should be_exist("./#{
|
30
|
+
File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/contents.html")
|
31
|
+
File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/nav-contents.ncx")
|
29
32
|
end
|
30
33
|
|
31
34
|
it "contents file should include the page" do
|
@@ -34,7 +37,7 @@ describe "Mobi book file generator" do
|
|
34
37
|
book = Kindler::Book.new :title=>title,:author=>author,:debug=>true
|
35
38
|
book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
|
36
39
|
book.generate
|
37
|
-
contents = File.open("./#{
|
40
|
+
contents = File.open("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/contents.html").readlines
|
38
41
|
contents.count.should > 0
|
39
42
|
contents.select {|a| a.include?("001.html")}.count.should > 0
|
40
43
|
book.should be_generated
|
@@ -58,7 +61,7 @@ describe "Mobi book file generator" do
|
|
58
61
|
book.add_page :title=>'page3',:author=>'mike1',:content=>'<img src="http://media2.glamour-sales.com.cn/media/catalog/category/Stroili_banner_02.jpg"></img>this is the page 3',:wrap=>true
|
59
62
|
book.generate
|
60
63
|
book.should be_generated
|
61
|
-
File.should be_exist("./#{
|
64
|
+
File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/1.jpg")
|
62
65
|
end
|
63
66
|
|
64
67
|
it "can access pages information before generate" do
|
@@ -110,7 +113,29 @@ describe "Mobi book file generator" do
|
|
110
113
|
book.add_page :title=>'page3',:author=>'mike1',:url => 'http://media2.glamour-sales.com.cn/media/some_url',:content=>'<img src="/media/catalog/category/Stroili_banner_02.jpg"></img>this is the page 3',:wrap=>true
|
111
114
|
book.generate
|
112
115
|
book.should be_generated
|
113
|
-
File.should be_exist("./#{
|
116
|
+
File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/1.jpg")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should generate mobi books on specify output_dir " do
|
120
|
+
title = 'specify_dir'
|
121
|
+
custom_dir = '__custom_gen_dir'
|
122
|
+
book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true, :output_dir => custom_dir
|
123
|
+
book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
|
124
|
+
book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
|
125
|
+
book.generate
|
126
|
+
book.should be_generated
|
127
|
+
File.should be_exist(custom_dir)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can generate mobi books on absolute dir" do
|
131
|
+
title = 'specify_dir'
|
132
|
+
custom_dir = '~/__custom_gen_dir'
|
133
|
+
book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true, :output_dir => custom_dir
|
134
|
+
book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
|
135
|
+
book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
|
136
|
+
book.generate
|
137
|
+
book.should be_generated
|
138
|
+
File.should be_exist(File.expand_path(custom_dir))
|
114
139
|
end
|
115
140
|
|
116
141
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kindler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-08 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2154641200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2154641200
|
25
25
|
description: kindler is a rubygem allow you to generate kindle mobi book very easily
|
26
26
|
email:
|
27
27
|
- mike.d.1984@gmail.com
|