kindler 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kindler/version.rb +1 -1
- data/lib/kindler.rb +22 -9
- metadata +3 -3
data/lib/kindler/version.rb
CHANGED
data/lib/kindler.rb
CHANGED
@@ -47,6 +47,10 @@ module Kindler
|
|
47
47
|
def generate
|
48
48
|
make_generated_dirs
|
49
49
|
localize_images if @keep_image
|
50
|
+
# reorder count index
|
51
|
+
if magzine?
|
52
|
+
sectionize_pages
|
53
|
+
end
|
50
54
|
generate_toc
|
51
55
|
generate_opf
|
52
56
|
generate_ncx
|
@@ -54,6 +58,19 @@ module Kindler
|
|
54
58
|
kindlegen
|
55
59
|
end
|
56
60
|
|
61
|
+
def sectionize_pages
|
62
|
+
@pages_by_section = {}
|
63
|
+
page_count = 1
|
64
|
+
pages.each do |page|
|
65
|
+
page[:count] = page_count
|
66
|
+
page[:file_name] = "#{page[:count].to_s.rjust(3,'0')}.html"
|
67
|
+
page_count += 1
|
68
|
+
@pages_by_section[page[:section]] ||= []
|
69
|
+
@pages_by_section[page[:section]] << page
|
70
|
+
end
|
71
|
+
pages = @pages_by_section.values.flatten
|
72
|
+
end
|
73
|
+
|
57
74
|
# check mobi file is generated already
|
58
75
|
def mobi_generated?
|
59
76
|
File.exist? "#{tmp_dir}/#{@title}.mobi"
|
@@ -133,11 +150,7 @@ module Kindler
|
|
133
150
|
|
134
151
|
def magzine_ncx
|
135
152
|
contents = ''
|
136
|
-
|
137
|
-
pages.each do |page|
|
138
|
-
pages_by_section[page[:section]] ||= []
|
139
|
-
pages_by_section[page[:section]] << page
|
140
|
-
end
|
153
|
+
|
141
154
|
contents << <<-MAG
|
142
155
|
<navPoint playOrder="0" class="periodical" id="periodical">
|
143
156
|
<navLabel>
|
@@ -148,7 +161,7 @@ module Kindler
|
|
148
161
|
MAG
|
149
162
|
|
150
163
|
play_order = 1
|
151
|
-
pages_by_section.each do |section,pages|
|
164
|
+
@pages_by_section.each do |section,pages|
|
152
165
|
next if pages.count==0
|
153
166
|
# add section header
|
154
167
|
contents << <<-SECHEADER
|
@@ -266,7 +279,7 @@ module Kindler
|
|
266
279
|
|
267
280
|
# html file path
|
268
281
|
def file_path(file_name)
|
269
|
-
"#{tmp_dir}/#{file_name}
|
282
|
+
"#{tmp_dir}/#{file_name}"
|
270
283
|
end
|
271
284
|
|
272
285
|
# wrap readable contents with in html format
|
@@ -293,12 +306,12 @@ module Kindler
|
|
293
306
|
|
294
307
|
def write_to_disk
|
295
308
|
File.open("#{tmp_dir}/nav-contents.ncx",'wb') { |f| f.write @ncx }
|
296
|
-
File.open(file_path('contents'),'wb') {|f| f.write @toc }
|
309
|
+
File.open(file_path('contents.html'),'wb') {|f| f.write @toc }
|
297
310
|
File.open("#{tmp_dir}/#{title}.opf",'wb') {|f| f.write @opf}
|
298
311
|
# make html files
|
299
312
|
files_count = 1
|
300
313
|
pages.each do |page|
|
301
|
-
File.open(file_path(
|
314
|
+
File.open(file_path(page[:file_name]),'wb') do |f|
|
302
315
|
content_to_write = page[:wrap] ? html_wrap(page[:title],page[:content]) : page[:content]
|
303
316
|
debug "here is the page #{page[:title]} need to write"
|
304
317
|
debug content_to_write
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-04 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &2154237100 !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: *2154237100
|
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
|