docrails_kindle 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/docrails_kindle +17 -14
- data/docrails_kindle.gemspec +1 -1
- metadata +5 -5
data/bin/docrails_kindle
CHANGED
@@ -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
|
-
|
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
|
-
|
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' =>
|
101
|
-
'masthead' =>
|
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
|
data/docrails_kindle.gemspec
CHANGED
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
|
+
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: &
|
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: *
|
24
|
+
version_requirements: *13065820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: kindlerb
|
27
|
-
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: *
|
35
|
+
version_requirements: *13065140
|
36
36
|
description: Read Rails Guides on your Kindle
|
37
37
|
email:
|
38
38
|
- dhchoi@gmail.com
|