kindler 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Kindler
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/kindler.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "kindler/version"
10
10
  module Kindler
11
11
  class Book
12
12
  class KindlerError < StandardError;end
13
- attr_accessor :title,:author,:pages,:local_images,:mobi_type
13
+ attr_accessor :title,:author,:pages,:pages_by_section,:local_images,:mobi_type
14
14
  TMP_DIR = 'kindler_generated_mobi'
15
15
  DEFAULT_SECTION = "All Pages"
16
16
  PAGE_ATTRIBUTES = %w(wrap title author content section)
@@ -30,6 +30,7 @@ module Kindler
30
30
  @mobi_type = options[:mobi_type] || :magzine
31
31
  @pages = []
32
32
  @local_images = []
33
+ @pages_by_section = {}
33
34
  raise KindlerError.new("must provide the book title ") unless title
34
35
  end
35
36
 
@@ -63,13 +64,12 @@ module Kindler
63
64
  end
64
65
 
65
66
  def sectionize_pages
66
- @pages_by_section = {}
67
- pages.each do |page|
68
- @pages_by_section[page[:section]] ||= []
69
- @pages_by_section[page[:section]] << page
67
+ self.pages.each do |page|
68
+ pages_by_section[page[:section]] ||= []
69
+ pages_by_section[page[:section]] << page
70
70
  end
71
- pages = @pages_by_section.values.flatten
72
- pages.each_with_index do |page,index|
71
+ self.pages = pages_by_section.values.flatten
72
+ self.pages.each_with_index do |page,index|
73
73
  page[:count] = index + 1
74
74
  page[:file_name] = "#{page[:count].to_s.rjust(3,'0')}.html"
75
75
  end
@@ -88,6 +88,7 @@ module Kindler
88
88
  system("kindlegen #{tmp_dir}/#{@title}.opf ")
89
89
  end
90
90
 
91
+ # generate contents.html
91
92
  def generate_toc
92
93
  contents = <<-CODE
93
94
  <html>
@@ -31,6 +31,26 @@ describe "Mobi html file generator" do
31
31
  File.exist?(mobi_book_path(title)).should == true
32
32
  end
33
33
 
34
+ it "should contains right info at contents html" do
35
+ title = 'test_contents'
36
+ book = Kindler::Book.new :title=>title,:author=>'mike',:debug=>true
37
+ book.add_page :title=>'love page1',:author=>'mike1',:content=>'this is the love page1',:section => 'love'
38
+ book.add_page :title=>'love page2',:author=>'mike1',:content=>'this is the love page2',:section => 'love'
39
+ book.add_page :title=>'hate page1',:author=>'mike1',:content=>'this is the hate page1',:section => 'hate'
40
+ book.add_page :title=>'love page3',:author=>'mike1',:content=>'this is the love page3',:section => 'love'
41
+ book.add_page :title=>'hate page2',:author=>'mike1',:content=>'<img src="http://media2.glamour-sales.com.cn/media/catalog/category/Stroili_banner_02.jpg"></img>this is the hate page2',:section=>'hate'
42
+ book.generate
43
+ book.pages[2][:title].should == 'love page3'
44
+ end
45
+
46
+ it "should contains right info at ncx file" do
47
+
48
+ end
49
+
50
+ it "should contains right info at opf file" do
51
+
52
+ end
53
+
34
54
  def mobi_book_path(title,output_dir='.')
35
55
  File.join(output_dir,"kindler_generated_mobi_#{title}/#{title}.mobi")
36
56
  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.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2165462940 !ruby/object:Gem::Requirement
16
+ requirement: &2161120240 !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: *2165462940
24
+ version_requirements: *2161120240
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
@@ -67,3 +67,4 @@ summary: kindler is a rubygem allow you to generate kindle mobi book very easily
67
67
  test_files:
68
68
  - spec/cases/generator_spec.rb
69
69
  - spec/spec_helper.rb
70
+ has_rdoc: