kindler 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54b86a48ecb6126e28883da0626a65d822ecc303
4
+ data.tar.gz: 97904a93c1a6cf8e9a66f5d2146ed20aede7eb2b
5
+ SHA512:
6
+ metadata.gz: 4a25d4827e83efe983235188582b419ede58e065a5a82d0764f2a1acd623b4cd082b2a366895071ccd35f3dcba9e28d55600c63f47acf85374642b2835689e53
7
+ data.tar.gz: 55bfc5fa474e9f1c2dfbf720bf1fab88deb83334be3249d1caf86e6716132633ccfae1859f971af650d8872988744d78aee5cd225121dc5d11203cc186eec78a
data/Gemfile CHANGED
@@ -6,12 +6,6 @@ group :development, :test do
6
6
  # Testing infrastructure
7
7
  gem 'guard'
8
8
  gem 'guard-rspec'
9
-
10
- if RUBY_PLATFORM =~ /darwin/
11
- # OS X integration
12
- gem "ruby_gntp"
13
- gem "rb-fsevent", "~> 0.4.3.1"
14
- end
15
9
  end
16
10
 
17
11
  gem "nokogiri"
data/Readme.md CHANGED
@@ -1,11 +1,13 @@
1
1
  ## Todo
2
2
  * support inner reference, inner link can take to that article
3
+ * refactor templates
4
+ * fix image download
3
5
 
4
6
  ## Is this gem is what you want?
5
- There is a alternative gem called [kindlerb](https://github.com/danchoi/kindlerb) can generate mobi books, the gem is also used
7
+ There is a alternative gem called [kindlerb](https://github.com/danchoi/kindlerb) can generate mobi books, the gem is also used
6
8
  for the website [KindleFeeder](http://kindlefeeder.com/) which is build by [Daniel Choi](http://danielchoi.com/software).
7
9
 
8
- If you like to generate mobi book by some html files, you have to conform to the structure which author provide. But if you just
10
+ If you like to generate mobi book by some html files, you have to conform to the structure which author provide. But if you just
9
11
  want to generate mobi book in the fly, then you should try this gem.
10
12
 
11
13
  BTW, we share the same internal way to generating mobi book by [KindleGen 2](http://www.amazon.com/gp/feature.html?ie=UTF8&docId=1000234621).
@@ -50,7 +52,7 @@ book.add_article {
50
52
  :content => '<img src="http://media2.glamour-sales.com.cn/media/catalog/category/Stroili_banner_02.jpg"></img>this is the page 3',
51
53
  :section => 'hate' }
52
54
  # you will get my_first_mobi_book.mobi file
53
- book.generate
55
+ book.generate
54
56
 
55
57
  #or you can just generate simple mobi book
56
58
  book.mobi_type = :flat
@@ -1,3 +1,3 @@
1
1
  module Kindler
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/kindler.rb CHANGED
@@ -3,6 +3,9 @@ require 'rubygems'
3
3
  require "open-uri"
4
4
  require "nokogiri"
5
5
  require "cgi"
6
+ require "erb"
7
+ require "shellwords"
8
+ require "fileutils"
6
9
  # require 'mini_magick'
7
10
  require_relative 'kindler/railtie' if defined?(Rails)
8
11
  require_relative "kindler/version"
@@ -11,7 +14,7 @@ module Kindler
11
14
  class Book
12
15
  class KindlerError < StandardError;end
13
16
 
14
- attr_accessor :title,:author,:pages,:pages_by_section,:local_images,:mobi_type
17
+ attr_accessor :title,:author,:pages,:pages_by_section,:local_images,:mobi_type,:style
15
18
 
16
19
  TMP_DIR_PREFIX = '__km_'
17
20
  DEFAULT_SECTION = "All Pages"
@@ -30,9 +33,11 @@ module Kindler
30
33
  @title = options[:title] || ''
31
34
  @author = options[:author] || 'unknown'
32
35
  @mobi_type = options[:mobi_type] || :magzine
36
+ @cover = options[:cover] || ""
33
37
  @pages = []
34
38
  @local_images = []
35
39
  @pages_by_section = {}
40
+ @style = options[:style] || ''
36
41
  raise KindlerError.new("must provide the book title ") unless title
37
42
  end
38
43
 
@@ -46,6 +51,7 @@ module Kindler
46
51
  page[:author] = 'unknown' if (page[:author]==nil or page[:author]=='')
47
52
  # escape special chars
48
53
  page[:title] = CGI::escapeHTML(page[:title])
54
+ page[:title] = title if(page[:title] == "")
49
55
  page[:author] = CGI::escapeHTML(page[:author])
50
56
  pages << page
51
57
  debug pages
@@ -66,6 +72,7 @@ module Kindler
66
72
  generate_opf
67
73
  generate_ncx
68
74
  write_to_disk
75
+ prepare_conver_img
69
76
  kindlegen
70
77
  end
71
78
 
@@ -87,7 +94,7 @@ module Kindler
87
94
  end
88
95
 
89
96
  def book_path
90
- "#{tmp_dir}/#{valid_title}.mobi"
97
+ "#{tmp_dir}/#{title}.mobi"
91
98
  end
92
99
 
93
100
  private
@@ -95,125 +102,21 @@ module Kindler
95
102
  # you can use "sudo brew install " to install it
96
103
  def kindlegen
97
104
  debug 'begin generate mobi'
98
- system("kindlegen #{tmp_dir}/#{valid_title}.opf ")
105
+ cmd = "kindleGen #{Shellwords.escape(tmp_dir)}/#{Shellwords.escape(title)}.opf "
106
+ system(cmd)
99
107
  end
100
108
 
101
109
  # generate contents.html
102
110
  def generate_toc
103
- contents = <<-CODE
104
- <html>
105
- <head>
106
- <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
107
- <title>Table of Contents</title>
108
- </head>
109
- <body>
110
- <h1>Contents</h1>
111
- <h4>Main section</h4>
112
- <ul>
113
- CODE
114
- files_count = 1
115
- pages.each do |page|
116
- contents << "<li><a href='#{files_count.to_s.rjust(3,'0')}.html'>#{page[:title]}</a></li>"
117
- files_count += 1
118
- end
119
- # append footer
120
- contents << "</ul></body></html>"
121
-
122
- @toc = contents
111
+ template = ERB.new(open(File.join(File.dirname(__FILE__),"templates/book.toc.erb")).read)
112
+ @toc = template.result(binding)
123
113
  end
124
114
 
125
115
  # generate ncx , which is navigation
126
116
  def generate_ncx
127
- contents = <<-NCX
128
- <?xml version="1.0" encoding="UTF-8"?>
129
- <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
130
- <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
131
- <head>
132
- <meta name="dtb:uid" content="#{title}"/>
133
- <meta name="dtb:depth" content="1"/>
134
- <meta name="dtb:totalPageCount" content="0"/>
135
- <meta name="dtb:maxPageNumber" content="0"/>
136
- </head>
137
- <docTitle>
138
- <text>#{title}</text>
139
- </docTitle>
140
- <docAuthor>
141
- <text>#{author}</text>
142
- </docAuthor>
143
- <navMap>
144
- NCX
145
- contents << (magzine? ? magzine_ncx : flat_ncx)
146
- contents << "</navMap></ncx>"
147
- @ncx = contents
148
- end
149
-
150
- def flat_ncx
151
- contents = ''
152
- files_count = 2
153
- pages.each do |page|
154
- nav_point = <<-NAV
155
- <navPoint id="navpoint-#{files_count}" playOrder="#{files_count}">
156
- <navLabel><text>#{page[:title]}</text></navLabel>
157
- <content src="#{(files_count-1).to_s.rjust(3,'0')}.html"/>
158
- </navPoint>
159
- NAV
160
- contents << nav_point
161
- files_count += 1
162
- end
163
- contents
164
- end
165
-
166
- def magzine_ncx
167
- contents = ''
168
-
169
- contents << <<-MAG
170
- <navPoint playOrder="0" class="periodical" id="periodical">
171
- <navLabel>
172
- <text>Table of Contents</text>
173
- </navLabel>
174
- <content src="contents.html"/>
175
-
176
- MAG
177
-
178
117
  play_order = 1
179
- @pages_by_section.each do |section,pages|
180
- next if pages.count==0
181
- # add section header
182
- contents << <<-SECHEADER
183
- <navPoint playOrder="#{play_order}" class="section" id="#{section}">
184
- <navLabel>
185
- <text>#{section}</text>
186
- </navLabel>
187
- <content src="#{pages.first[:file_name]}"/>
188
- SECHEADER
189
-
190
- play_order += 1
191
- # add pages nav
192
- pages.each do |page|
193
- contents << <<-PAGE
194
- <navPoint playOrder="#{play_order}" class="article" id="item-#{page[:count].to_s.rjust(3,'0')}">
195
- <navLabel>
196
- <text>#{page[:title]}</text>
197
- </navLabel>
198
- <content src="#{page[:file_name]}"/>
199
- <mbp:meta name="description">#{page[:title]}</mbp:meta>
200
- <mbp:meta name="author">#{page[:author]}</mbp:meta>
201
- </navPoint>
202
- PAGE
203
- play_order += 1
204
- end
205
- # add section footer
206
- contents << "</navPoint>"
207
- end
208
- contents << "</navPoint>"
209
- end
210
-
211
- def magzine_meta
212
- <<-META
213
- <x-metadata>
214
- <output content-type="application/x-mobipocket-subscription-magazine" encoding="utf-8"/>
215
- </x-metadata>
216
- META
118
+ template = ERB.new(open(File.join(File.dirname(__FILE__),"templates/book.ncx.erb")).read)
119
+ @ncx = template.result(binding)
217
120
  end
218
121
 
219
122
  def magzine?
@@ -222,43 +125,12 @@ module Kindler
222
125
 
223
126
  # generate the opf, manifest of book,including all articles and images and css
224
127
  def generate_opf
225
- contents = <<-HTML
226
- <?xml version='1.0' encoding='utf-8'?>
227
- <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="#{title}">
228
- <metadata>
229
- <dc-metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
230
- <dc:title>#{title}</dc:title>
231
- <dc:language>en-gb</dc:language>
232
- <meta content="cover-image" name="cover"/>
233
- <dc:creator>Kindler- 29decibel</dc:creator>
234
- <dc:publisher>Kindler- 29decibel</dc:publisher>
235
- <dc:subject>News</dc:subject>
236
- <dc:identifier id="#{title}">#{title}</dc:identifier>
237
- <dc:date>#{Time.now.to_date}</dc:date>
238
- <dc:description>Kindler generated book</dc:description>
239
- </dc-metadata>
240
- #{magzine? ? magzine_meta : ''}
241
- </metadata>
242
- <manifest>
243
- HTML
244
- files_count = 1
245
- pages.each do |page|
246
- doc_id = files_count.to_s.rjust(3,'0')
247
- contents << "<item href='#{doc_id}.html' media-type='application/xhtml+xml' id='#{doc_id}'/>"
248
- files_count += 1
249
- end
250
- contents << "<item href='contents.html' media-type='application/xhtml+xml' id='contents'/>"
251
- contents << "<item href='nav-contents.ncx' media-type='application/x-dtbncx+xml' id='nav-contents'/>"
252
- contents << "</manifest>"
253
- contents << "<spine toc='nav-contents'>"
254
- contents << "<itemref idref='contents'/>"
255
- files_count = 1
256
- pages.each do |page|
257
- contents << "<itemref idref='#{files_count.to_s.rjust(3,'0')}'/>"
258
- files_count += 1
259
- end
260
- contents << "</spine><guide><reference href='contents.html' type='toc' title='Table of Contents'/></guide></package>"
261
- @opf = contents
128
+ template = ERB.new(open(File.join(File.dirname(__FILE__),"templates/book.opf.erb")).read)
129
+ @opf = template.result(binding)
130
+ end
131
+
132
+ def meta_info
133
+ {}
262
134
  end
263
135
 
264
136
  def get_image_extname(image_data,url)
@@ -306,7 +178,7 @@ module Kindler
306
178
  page[:content] = article.inner_html
307
179
  # add to manifest
308
180
  local_images << "#{image_local_address}"
309
- images_count += 1
181
+ images_count += 1
310
182
  rescue Exception => e
311
183
  debug "got error when fetch and save image: #{e}"
312
184
  end
@@ -320,23 +192,24 @@ module Kindler
320
192
  end
321
193
 
322
194
  # wrap readable contents with in html format
323
- def html_wrap(title,content)
324
- result = ''
325
- result << '<html><head>'
326
- result << "<meta content='text/html; charset=utf-8' http-equiv='Content-Type'/>"
327
- result << '</head><body>'
328
- result << "<h3>#{title}</h3>"
329
- result << content
330
- result << '</body></html>'
195
+ def html_wrap(page)
196
+ template = ERB.new(open(File.join(File.dirname(__FILE__),"templates/page.html.erb")).read)
197
+ template.result(binding)
331
198
  end
332
199
 
333
200
  # the dir path to generated files
334
201
  def tmp_dir
335
- File.expand_path (@output_dir == '' ? "#{TMP_DIR_PREFIX}#{valid_title}" : @output_dir)
202
+ File.expand_path (@output_dir == '' ? "#{TMP_DIR_PREFIX}#{title}" : @output_dir)
336
203
  end
337
204
 
338
- def valid_title
339
- @v_title ||= @title.gsub(' ','_')
205
+ def prepare_conver_img
206
+ return unless @cover != ""
207
+ if @cover.start_with?("http")
208
+ # download conver to conver
209
+ # TODO find out a elegant way to do this
210
+ else
211
+ `cp #{@cover} #{tmp_dir}/` if File.exist?(@cover)
212
+ end
340
213
  end
341
214
 
342
215
  # create dirs of generated files
@@ -348,12 +221,12 @@ module Kindler
348
221
  def write_to_disk
349
222
  File.open("#{tmp_dir}/nav-contents.ncx",'wb') { |f| f.write @ncx }
350
223
  File.open(file_path('contents.html'),'wb') {|f| f.write @toc }
351
- File.open("#{tmp_dir}/#{valid_title}.opf",'wb') {|f| f.write @opf}
224
+ File.open("#{tmp_dir}/#{title}.opf",'wb') {|f| f.write @opf}
352
225
  # make html files
353
226
  files_count = 1
354
227
  pages.each do |page|
355
228
  File.open(file_path(page[:file_name]),'wb') do |f|
356
- content_to_write = page[:wrap] ? html_wrap(page[:title],page[:content]) : page[:content]
229
+ content_to_write = page[:wrap] ? html_wrap(page) : page[:content]
357
230
  debug "here is the page #{page[:title]} need to write"
358
231
  debug content_to_write
359
232
  f.write content_to_write
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
3
+ <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
4
+ <head>
5
+ <meta name="dtb:uid" content="<%= title %>"/>
6
+ <meta name="dtb:depth" content="1"/>
7
+ <meta name="dtb:totalPageCount" content="0"/>
8
+ <meta name="dtb:maxPageNumber" content="0"/>
9
+ </head>
10
+ <docTitle>
11
+ <text><%= title %></text>
12
+ </docTitle>
13
+ <docAuthor>
14
+ <text><%= author %></text>
15
+ </docAuthor>
16
+ <navMap>
17
+ <% if magzine? %>
18
+ <navPoint playOrder="0" class="periodical" id="periodical">
19
+ <navLabel>
20
+ <text>Table of Contents</text>
21
+ </navLabel>
22
+ <content src="contents.html"/>
23
+
24
+ <% @pages_by_section.each do |section,pages| %>
25
+ <% next if pages.count==0 %>
26
+ <navPoint playOrder="<%= play_order %>" class="section" id="<%= section %>">
27
+ <navLabel>
28
+ <text><%= section %></text>
29
+ </navLabel>
30
+ <content src="<%= pages.first[:file_name] %>"/>
31
+ <% play_order += 1%>
32
+ <% pages.each do |page| %>
33
+ <navPoint playOrder="<%= play_order %>" class="article" id="item-<%= page[:count].to_s.rjust(3,'0') %>">
34
+ <navLabel>
35
+ <text><%= page[:title] %></text>
36
+ </navLabel>
37
+ <content src="<%= page[:file_name] %>"/>
38
+ <mbp:meta name="description"><%= page[:title] %></mbp:meta>
39
+ <mbp:meta name="author"><%= page[:author] %></mbp:meta>
40
+ </navPoint>
41
+ <% end %>
42
+ </navPoint>
43
+ <% end %>
44
+ </navPoint>
45
+ <% else %>
46
+ <% pages.each_with_index do |page,index| %>
47
+ <navPoint id="navpoint-<%= index +2 %>" playOrder="<%= index +2 %>">
48
+ <navLabel><text><%= page[:title] %></text></navLabel>
49
+ <content src="<%= (index+1).to_s.rjust(3,'0') %>.html"/>
50
+ </navPoint>
51
+ <% end %>
52
+ <% end %>
53
+ </navMap>
54
+ </ncx>
@@ -0,0 +1,37 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="#{title}">
3
+ <metadata>
4
+ <dc-metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
5
+ <dc:title><%= title %></dc:title>
6
+ <dc:language>en-gb</dc:language>
7
+ <meta content="cover-image" name="cover"/>
8
+ <dc:creator><%= author %></dc:creator>
9
+ <dc:publisher><%= author %></dc:publisher>
10
+ <dc:subject><%= title %></dc:subject>
11
+ <dc:identifier id="<%= title %>"><%= title %></dc:identifier>
12
+ <dc:date><%= Time.now.to_date %></dc:date>
13
+ <dc:description><%= title %></dc:description>
14
+ </dc-metadata>
15
+ <% if magzine? %>
16
+ <x-metadata>
17
+ <output content-type="application/x-mobipocket-subscription-magazine" encoding="utf-8"/>
18
+ </x-metadata>
19
+ <% end %>
20
+ </metadata>
21
+ <manifest>
22
+ <% pages.each_with_index do |page,index|%>
23
+ <item href='<%= (index+1).to_s.rjust(3,'0') %>.html' media-type='application/xhtml+xml' id='<%= (index+1).to_s.rjust(3,'0') %>'/>
24
+ <% end %>
25
+ <item href='contents.html' media-type='application/xhtml+xml' id='contents'/>
26
+ <item href='nav-contents.ncx' media-type='application/x-dtbncx+xml' id='nav-contents'/>
27
+ </manifest>
28
+ <spine toc='nav-contents'>
29
+ <itemref idref='contents'/>
30
+ <% pages.each_with_index do |page,index| %>
31
+ <itemref idref='<%= (index+1).to_s.rjust(3,'0') %>'/>
32
+ <% end %>
33
+ </spine>
34
+ <guide>
35
+ <reference href='contents.html' type='toc' title='Table of Contents'/>
36
+ </guide>
37
+ </package>
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4
+ <title>Table of Contents</title>
5
+ </head>
6
+ <body>
7
+ <h1>Contents</h1>
8
+ <h4>Main section</h4>
9
+ <ul>
10
+ <% pages.each_with_index do |page,index| %>
11
+ <li><a href='<%= (index+1).to_s.rjust(3,'0') %>.html'><%= page[:title] %></a></li>
12
+ <% end %>
13
+ </ul>
14
+ </body>
15
+ </html>
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <meta content='text/html; charset=utf-8' http-equiv='Content-Type'/>
4
+ <style type="text/css"><%= style %></style>
5
+ </head>
6
+ <body>
7
+ <h2>
8
+ <%= page[:title] %>
9
+ </h2>
10
+ <p><em><%= page[:author] %></em><p>
11
+ <div><%= page[:content] %></div>
12
+ </body>
13
+ </html>
@@ -49,7 +49,7 @@ describe "Mobi book file generator" do
49
49
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
50
50
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
51
51
  book.add_page :title=>'page3',:author=>'mike1',:content=>'this is the page 3',:wrap=>true
52
- book.generate
52
+ book.generate
53
53
  book.should be_generated
54
54
  end
55
55
 
@@ -59,7 +59,7 @@ describe "Mobi book file generator" do
59
59
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
60
60
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
61
61
  book.add_page :title=>'page3',:author=>'mike1',:content=>'<img src="http://media2.glamour-sales.com.cn/media/catalog/category/Stroili_banner_02.jpg"/>this is the page 3',:wrap=>true
62
- book.generate
62
+ book.generate
63
63
  book.should be_generated
64
64
  File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/1.jpg")
65
65
  end
@@ -82,19 +82,11 @@ describe "Mobi book file generator" do
82
82
  book.add_page :title=>'love page2',:author=>'mike1',:content=>'this is the love page2',:section => 'love'
83
83
  book.add_page :title=>'hate page1',:author=>'mike1',:content=>'this is the hate page1',:section => 'hate'
84
84
  book.add_page :title=>'love page3',:author=>'mike1',:content=>'this is the love page3',:section => 'love'
85
- book.generate
85
+ book.generate
86
86
  book.should be_generated
87
87
  book.pages_by_section.count.should == 2
88
88
  end
89
89
 
90
- it "should generate books given title contains space" do
91
- title = 'title with space'
92
- book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true
93
- book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
94
- book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
95
- book.generate
96
- book.should be_generated
97
- end
98
90
 
99
91
  it "can support add_article" do
100
92
  title = 'first-book'
@@ -111,7 +103,7 @@ describe "Mobi book file generator" do
111
103
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
112
104
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
113
105
  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"/>this is the page 3',:wrap=>true
114
- book.generate
106
+ book.generate
115
107
  book.should be_generated
116
108
  File.should be_exist("./#{Kindler::Book::TMP_DIR_PREFIX}#{title}/1.jpg")
117
109
  end
@@ -122,7 +114,7 @@ describe "Mobi book file generator" do
122
114
  book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true, :output_dir => custom_dir
123
115
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
124
116
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
125
- book.generate
117
+ book.generate
126
118
  book.should be_generated
127
119
  File.should be_exist(custom_dir)
128
120
  end
@@ -133,7 +125,7 @@ describe "Mobi book file generator" do
133
125
  book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true, :output_dir => custom_dir
134
126
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
135
127
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
136
- book.generate
128
+ book.generate
137
129
  book.should be_generated
138
130
  File.should be_exist(File.expand_path(custom_dir))
139
131
  end
@@ -145,8 +137,9 @@ describe "Mobi book file generator" do
145
137
  book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
146
138
  book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
147
139
  book.add_page :title=>'page3',:author=>'mike1',:content=>"<img src='#{image_url}'/>this is the page 3",:wrap=>true
148
- book.generate
140
+ book.generate
149
141
  book.should be_generated
150
142
  end
151
143
 
144
+
152
145
  end
@@ -0,0 +1,23 @@
1
+
2
+ require 'spec_helper'
3
+ describe "Mobi book file generator" do
4
+
5
+ after :all do
6
+ puts '==== clear tmp files ==='
7
+ #`rm -rf ./__*`
8
+ end
9
+
10
+ it "should have the title,author property" do
11
+ title = 'simple-book'
12
+ author = 'mike'
13
+ book = Kindler::Book.new :title=>title,:author=>author,:debug=>true,:mobi_type => :simple
14
+ book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
15
+ book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
16
+ book.add_page :title=>'page3',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
17
+ book.add_page :title=>'page4',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
18
+ book.title.should == title
19
+ book.author.should == author
20
+ book.generate
21
+ book.should be_generated
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ describe "Mobi book file generator" do
3
+
4
+ after :all do
5
+ puts '==== clear tmp files ==='
6
+ #`rm -rf ./__*`
7
+ end
8
+
9
+ it "should generate books given title contains space" do
10
+ title = 'title with space'
11
+ book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true
12
+ book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
13
+ book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
14
+ book.generate
15
+ book.should be_generated
16
+ end
17
+ end
metadata CHANGED
@@ -1,27 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - dongbin.li
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-15 00:00:00.000000000Z
11
+ date: 2013-03-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
- requirement: &2153362980 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *2153362980
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  description: kindler is a rubygem allow you to generate kindle mobi book very easily
26
28
  email:
27
29
  - mike.d.1984@gmail.com
@@ -42,31 +44,36 @@ files:
42
44
  - lib/kindler.rb
43
45
  - lib/kindler/railtie.rb
44
46
  - lib/kindler/version.rb
47
+ - lib/templates/book.ncx.erb
48
+ - lib/templates/book.opf.erb
49
+ - lib/templates/book.toc.erb
50
+ - lib/templates/page.html.erb
45
51
  - spec/cases/generator_spec.rb
52
+ - spec/cases/simple_book_spec.rb
53
+ - spec/cases/title_space_spec.rb
46
54
  - spec/spec_helper.rb
47
55
  homepage: https://github.com/29decibel/kindler
48
56
  licenses: []
57
+ metadata: {}
49
58
  post_install_message:
50
59
  rdoc_options: []
51
60
  require_paths:
52
61
  - lib
53
62
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
63
  requirements:
56
- - - ! '>='
64
+ - - '>='
57
65
  - !ruby/object:Gem::Version
58
66
  version: '0'
59
67
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
68
  requirements:
62
- - - ! '>='
69
+ - - '>='
63
70
  - !ruby/object:Gem::Version
64
71
  version: '0'
65
72
  requirements: []
66
73
  rubyforge_project: kindler
67
- rubygems_version: 1.8.11
74
+ rubygems_version: 2.0.0
68
75
  signing_key:
69
- specification_version: 3
76
+ specification_version: 4
70
77
  summary: kindler is a rubygem allow you to generate kindle mobi book very easily
71
78
  test_files:
72
79
  - features/basic.feature
@@ -74,5 +81,6 @@ test_files:
74
81
  - features/step_definitions/basic_step.rb
75
82
  - features/step_definitions/dsl_step.rb
76
83
  - spec/cases/generator_spec.rb
84
+ - spec/cases/simple_book_spec.rb
85
+ - spec/cases/title_space_spec.rb
77
86
  - spec/spec_helper.rb
78
- has_rdoc: