kindler 0.1.8 → 0.1.9

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/Readme.md CHANGED
@@ -31,9 +31,24 @@ which receive a couple of urls then output one mobi file
31
31
  ```ruby
32
32
  title = 'my_first_mobi_book'
33
33
  book = Kindler::Book.new :title=>title,:author=>'mike'
34
- book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true,:section => 'love'
35
- book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true,:section => 'hate'
36
- book.add_page :title=>'page_with_image',: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,:section=>'hate'
34
+ # add one article
35
+ book.add_article {
36
+ :title => 'page1',
37
+ :author => 'mike1',
38
+ :content => 'this is the page 1',
39
+ :section => 'love' }
40
+ # add another article
41
+ book.add_article {
42
+ :title => 'page2',
43
+ :author => 'mike1',
44
+ :content => 'this is the page 2',
45
+ :section => 'hate' }
46
+ # add an article contains image
47
+ book.add_article {
48
+ :title => 'page_with_image',
49
+ :author => 'mike1',
50
+ :content => '<img src="http://media2.glamour-sales.com.cn/media/catalog/category/Stroili_banner_02.jpg"></img>this is the page 3',
51
+ :section => 'hate' }
37
52
  # you will get my_first_mobi_book.mobi file
38
53
  book.generate
39
54
 
@@ -41,7 +56,6 @@ book.generate
41
56
  book.mobi_type = :flat
42
57
  book.generate
43
58
  ```
44
-
45
- Hope you love it !
59
+ > Keep Reading!
46
60
 
47
61
 
@@ -1,3 +1,3 @@
1
1
  module Kindler
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/kindler.rb CHANGED
@@ -10,10 +10,12 @@ require_relative "kindler/version"
10
10
  module Kindler
11
11
  class Book
12
12
  class KindlerError < StandardError;end
13
+
13
14
  attr_accessor :title,:author,:pages,:pages_by_section,:local_images,:mobi_type
15
+
14
16
  TMP_DIR = 'kindler_generated_mobi'
15
17
  DEFAULT_SECTION = "All Pages"
16
- PAGE_ATTRIBUTES = %w(wrap title author content section)
18
+ PAGE_ATTRIBUTES = %w(wrap title author content section url)
17
19
 
18
20
  # availabel options
19
21
  # @param options [Hash]
@@ -49,6 +51,10 @@ module Kindler
49
51
  debug pages
50
52
  end
51
53
 
54
+ def add_article(options={})
55
+ add_page(options)
56
+ end
57
+
52
58
  def generate
53
59
  make_generated_dirs
54
60
  localize_images if @keep_image
@@ -259,15 +265,16 @@ module Kindler
259
265
  begin
260
266
  image_remote_address = img.attr('src')
261
267
  unless image_remote_address.start_with?('http')
262
- image_remote_address = "http://#{URI(url).host}#{image_remote_address}"
268
+ image_remote_address = "http://#{URI(page[:url]).host}#{image_remote_address}"
263
269
  end
264
270
  image_local_address = File.join(tmp_dir,"#{images_count}#{File.extname(image_remote_address)}")
265
271
  # download images
266
272
  debug "begin fetch image #{image_remote_address}"
267
273
  debug "save to #{image_local_address}"
268
- File.open(image_local_address,'wb') do |f|
269
- f.write open(image_remote_address).read
270
- end
274
+ `curl #{image_remote_address} > #{image_local_address}`
275
+ # File.open(image_local_address,'wb') do |f|
276
+ # f.write open(image_remote_address).read
277
+ # end
271
278
  debug 'Image saved'
272
279
  # replace local url address
273
280
  img.attributes['src'].value = "#{images_count}#{File.extname(image_remote_address)}"
@@ -93,4 +93,24 @@ describe "Mobi book file generator" do
93
93
  book.should be_generated
94
94
  end
95
95
 
96
+ it "can support add_article" do
97
+ title = 'first-book'
98
+ author = 'mike'
99
+ book = Kindler::Book.new :title=>title,:author=>author,:debug=>true
100
+ book.add_article :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
101
+ book.generate
102
+ book.should be_generated
103
+ end
104
+
105
+ it "can generate images with relative src" do
106
+ title = 'book_with_relative_image'
107
+ book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true
108
+ book.add_page :title=>'page1',:author=>'mike1',:content=>'this is the page 1',:wrap=>true
109
+ book.add_page :title=>'page2',:author=>'mike1',:content=>'this is the page 2',:wrap=>true
110
+ 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
+ book.generate
112
+ book.should be_generated
113
+ File.should be_exist("./#{DIR_PREFIX}#{title}/1.jpg")
114
+ end
115
+
96
116
  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.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2160828000 !ruby/object:Gem::Requirement
16
+ requirement: &2154843720 !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: *2160828000
24
+ version_requirements: *2154843720
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