docrails_kindle 0.0.4 → 0.0.5

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.
@@ -5,6 +5,19 @@ require 'fileutils'
5
5
  require 'yaml'
6
6
  require 'date'
7
7
 
8
+ def add_head_section(doc, title)
9
+ head = Nokogiri::XML::Node.new "head", doc
10
+ title_node = Nokogiri::XML::Node.new "title", doc
11
+ title_node.content = title
12
+ title_node.parent = head
13
+ css = Nokogiri::XML::Node.new "link", doc
14
+ css['rel'] = 'stylesheet'
15
+ css['type'] = 'text/css'
16
+ css['href'] = "#{Dir.pwd}/stylesheets/kindle.css"
17
+ css.parent = head
18
+ doc.at("body").before head
19
+ end
20
+
8
21
  # Get html pages in document order
9
22
 
10
23
  html_pages = Nokogiri::XML(File.read("toc.ncx")).search("navMap//content[@src]").map {|c| c[:src]}.uniq
@@ -40,13 +53,8 @@ fdoc.search("h2").each { |h2|
40
53
  h2['id'] = h2.inner_text.gsub(/\s/, '-')
41
54
  }
42
55
 
43
- head = Nokogiri::XML::Node.new "head", fdoc
44
- title_node = Nokogiri::XML::Node.new "title", fdoc
45
- title_node.content = "Frontmatter"
46
- title_node.parent = head
47
- fdoc.at("body").before head
56
+ add_head_section fdoc, "Frontmatter"
48
57
  File.open("frontmatter.html",'w'){|f| f.puts fdoc.to_html}
49
-
50
58
  html_pages.unshift "frontmatter.html"
51
59
 
52
60
  puts "=> Making one section folder per original HTML file"
@@ -66,12 +74,7 @@ html_pages.each_with_index { |page, section_idx|
66
74
  item = Nokogiri::HTML(h3.to_html + content.join("\n"))
67
75
  item_path = "sections/%03d/%03d.html" % [section_idx, item_idx]
68
76
 
69
- # add head node and title node
70
- head = Nokogiri::XML::Node.new "head", item
71
- title_node = Nokogiri::XML::Node.new "title", item
72
- title_node.content = subsection
73
- title_node.parent = head
74
- item.at("body").before head
77
+ add_head_section item, subsection
75
78
 
76
79
  # fix all image links
77
80
  item.search("img").each { |img|
@@ -97,8 +100,8 @@ document = {
97
100
  'author' => x.at("creator").inner_text,
98
101
  'subject' => x.at("subject").inner_text,
99
102
  'date' => x.at("date").inner_text,
100
- 'cover' => x.at("item[@id=cover]")[:href],
101
- 'masthead' => x.at("item[@id=cover]")[:href],
103
+ 'cover' => "#{Dir.pwd}/images/rails_guides_kindle_cover.jpg",
104
+ 'masthead' => nil,
102
105
  'mobi_outfile' => "rails-guide.#{Date.today.to_s}.mobi"
103
106
  }
104
107
  puts document.inspect
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "docrails_kindle"
6
- s.version = '0.0.4'
6
+ s.version = '0.0.5'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.required_ruby_version = '>= 1.9.0'
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docrails_kindle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &15237500 !ruby/object:Gem::Requirement
16
+ requirement: &13065820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15237500
24
+ version_requirements: *13065820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kindlerb
27
- requirement: &15237020 !ruby/object:Gem::Requirement
27
+ requirement: &13065140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15237020
35
+ version_requirements: *13065140
36
36
  description: Read Rails Guides on your Kindle
37
37
  email:
38
38
  - dhchoi@gmail.com