kindler 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +13 -4
- data/kindler.gemspec +2 -2
- data/lib/kindler/version.rb +1 -1
- data/lib/kindler.rb +12 -32
- data/spec/cases/generator_spec.rb +68 -27
- metadata +10 -8
data/Readme.md
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
### Todo
|
2
|
-
|
3
|
-
2.support magzine like format
|
2
|
+
support magzine like format
|
4
3
|
|
4
|
+
### Installation
|
5
|
+
```ruby
|
6
|
+
gem 'kindler'
|
7
|
+
```
|
8
|
+
|
9
|
+
or
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'kindler',:git=>'git@github.com:29decibel/kindler.git'
|
13
|
+
```
|
5
14
|
### A kindle mobi book generator
|
6
15
|
which receive a couple of urls then output one mobi file
|
7
16
|
|
8
17
|
### Command Line Use [Todo]
|
9
|
-
kindler url1 url2 url3 url4 -
|
18
|
+
kindler url1 url2 url3 url4 -t my_book
|
10
19
|
|
11
|
-
outputs :
|
20
|
+
outputs : my_book.mobi
|
12
21
|
|
13
22
|
### Api use
|
14
23
|
```ruby
|
data/kindler.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/kindler/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["dongbin.li"]
|
6
6
|
gem.email = ["mike.d.1984@gmail.com"]
|
7
|
-
gem.description = %q{a
|
8
|
-
gem.summary = %q{a
|
7
|
+
gem.description = %q{kindler is a rubygem allow you to generate kindle mobi book from urls very easily}
|
8
|
+
gem.summary = %q{kindler is a rubygem allow you to generate kindle mobi book from urls very easily}
|
9
9
|
gem.homepage = "https://github.com/29decibel/kindler"
|
10
10
|
|
11
11
|
gem.rubyforge_project = "kindler"
|
data/lib/kindler/version.rb
CHANGED
data/lib/kindler.rb
CHANGED
@@ -112,34 +112,6 @@ module Kindler
|
|
112
112
|
</docAuthor>
|
113
113
|
<navMap>
|
114
114
|
NCX
|
115
|
-
# this navPoint seems not useful
|
116
|
-
# contents << <<-NAV
|
117
|
-
# <navPoint id="navpoint-1" playOrder="1">
|
118
|
-
# <navLabel><text>Table Of Contents</text></navLabel>
|
119
|
-
# <content src="contents.html"/>
|
120
|
-
# </navPoint>
|
121
|
-
# NAV
|
122
|
-
####################### periodocal , magzine like format #########################
|
123
|
-
# <navPoint playOrder="0" class="periodical" id="periodical">
|
124
|
-
# <mbp:meta-img src="masthead.gif" name="mastheadImage"/>
|
125
|
-
# <navLabel>
|
126
|
-
# <text>Table of Contents</text>
|
127
|
-
# </navLabel>
|
128
|
-
# <content src="contents.html"/>
|
129
|
-
# <navPoint playOrder="1" class="section" id="Main-section">
|
130
|
-
# <navLabel>
|
131
|
-
# <text>Main section</text>
|
132
|
-
# </navLabel>
|
133
|
-
# <content src="001.html"/>
|
134
|
-
# <navPoint playOrder="2" class="article" id="item-001">
|
135
|
-
# <navLabel>
|
136
|
-
# <text>Nick Clegg and David Cameron agree key changes on NHS plans</text>
|
137
|
-
# </navLabel>
|
138
|
-
# <content src="001.html"/>
|
139
|
-
# <mbp:meta name="description">Deputy PM tells Andrew Marr show that GPs should not be forced to sign up to new commissioning consortiums</mbp:meta>
|
140
|
-
# <mbp:meta name="author">Nicholas Watt and Denis Campbell</mbp:meta>
|
141
|
-
# </navPoint>
|
142
|
-
# ####################################################################################
|
143
115
|
files_count = 2
|
144
116
|
@doc_infos.each do |url,infos|
|
145
117
|
nav_point = <<-NAV
|
@@ -203,10 +175,13 @@ module Kindler
|
|
203
175
|
def generate_html
|
204
176
|
@doc_infos.each do |url,infos|
|
205
177
|
article = readable_article(url)
|
206
|
-
|
207
|
-
|
208
|
-
|
178
|
+
if article
|
179
|
+
# puts article.images
|
180
|
+
infos[:content] = html_wrap(article.title,article.content)
|
181
|
+
infos[:title] = article.title
|
182
|
+
end
|
209
183
|
end
|
184
|
+
@doc_infos = @doc_infos.reject{|url,infos| infos[:content]==nil or infos[:title]==nil }
|
210
185
|
end
|
211
186
|
|
212
187
|
def localize_images
|
@@ -255,7 +230,12 @@ module Kindler
|
|
255
230
|
# get readable document by url, using ruby-readability here
|
256
231
|
def readable_article(url)
|
257
232
|
debug "begin fetch url : #{url}"
|
258
|
-
|
233
|
+
begin
|
234
|
+
source = open(url).read
|
235
|
+
rescue Exception => e
|
236
|
+
debug "got some erros,#{e}"
|
237
|
+
return nil
|
238
|
+
end
|
259
239
|
if @keep_image
|
260
240
|
Readability::Document.new(source,:tags=>%w(div p img a),:attributes => %w[src href],:remove_empty_nodes => false)
|
261
241
|
else
|
@@ -1,43 +1,84 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe "Mobi html file generator" do
|
3
3
|
|
4
|
-
it "should generate html files by urls" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
4
|
+
# it "should generate html files by urls" do
|
5
|
+
# title = "Test_book"
|
6
|
+
# book = Kindler::Book.new ({:urls=>["http://blog.farmostwood.net/643.html",
|
7
|
+
# "http://www.ifanr.com/69878","http://www.oneplus.info/archives/455"],
|
8
|
+
# :title=>title,:author=>'mike',:debug=>true})
|
9
|
+
# book.generate
|
10
|
+
# File.exist?(mobi_book_path(title)).should == true
|
11
|
+
# end
|
12
12
|
|
13
13
|
|
14
|
-
it "should generate hacker news book" do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
14
|
+
# it "should generate hacker news book" do
|
15
|
+
# title = 'haker_news'
|
16
|
+
# urls = []
|
17
|
+
# urls << "http://jseliger.com/2010/09/26/how-universities-work-or-what-i-wish-i%E2%80%99d-known-freshman-year-a-guide-to-american-university-life-for-the-uninitiated/"
|
18
|
+
# urls << "http://randykepple.com/photoblog/2010/10/8-bad-habits-that-crush-your-creativity-and-stifle-your-success/"
|
19
|
+
# urls << "http://nathanmarz.com/blog/how-to-get-a-job-at-a-kick-ass-startup-for-programmers.html"
|
20
|
+
# urls << "http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux"
|
21
|
+
# urls << "http://antirez.com/post/what-is-wrong-with-2006-programming.html"
|
22
|
+
# urls << "http://fak3r.com/2009/09/14/howto-build-your-own-open-source-dropbox-clone/"
|
23
|
+
# book = Kindler::Book.new :urls=>urls,:title=>title,:author=>'mike',:debug=>true
|
24
|
+
# book.generate
|
25
|
+
# File.exist?(mobi_book_path(title)).should == true
|
26
|
+
# end
|
27
27
|
|
28
|
-
it "should generate book and infos on output_dir" do
|
29
|
-
|
28
|
+
# it "should generate book and infos on output_dir" do
|
29
|
+
# title = 'my_dir_book'
|
30
|
+
# urls = []
|
31
|
+
# urls << "http://www.wowsai.com/home/space.php?uid=1&do=blog&id=4362&classid=2"
|
32
|
+
# urls << "http://www.honeykennedy.com/2012/01/miss-moss-love-letters/"
|
33
|
+
# urls << "http://www.mysenz.com/?p=3692"
|
34
|
+
# book = Kindler::Book.new :urls=>urls,:title=>title,:author=>'mike',:output_dir=>'/Users/lidongbin/projects',:debug=>true
|
35
|
+
# book.generate
|
36
|
+
# File.exist?(mobi_book_path(title,'/Users/lidongbin/projects')).should == true
|
37
|
+
# end
|
38
|
+
|
39
|
+
it "should not say error when got redirect page" do
|
40
|
+
title = 'good_book'
|
30
41
|
urls = []
|
31
|
-
urls << "http://
|
32
|
-
urls << "http://www.honeykennedy.com/2012/01/miss-moss-love-letters/"
|
42
|
+
urls << "http://droplr.com"
|
33
43
|
urls << "http://www.mysenz.com/?p=3692"
|
34
|
-
book = Kindler::Book.new :urls=>urls,:title=>title,:author=>'mike',:
|
44
|
+
book = Kindler::Book.new :urls=>urls,:title=>title,:author=>'mike',:debug=>true
|
35
45
|
book.generate
|
36
|
-
File.exist?(mobi_book_path(title
|
46
|
+
File.exist?(mobi_book_path(title)).should == true
|
37
47
|
end
|
38
48
|
|
39
49
|
def mobi_book_path(title,output_dir='.')
|
40
50
|
File.join(output_dir,"kindler_generated_mobi_#{title}/#{title}.mobi")
|
41
51
|
end
|
42
52
|
|
53
|
+
|
54
|
+
# this navPoint seems not useful
|
55
|
+
# contents << <<-NAV
|
56
|
+
# <navPoint id="navpoint-1" playOrder="1">
|
57
|
+
# <navLabel><text>Table Of Contents</text></navLabel>
|
58
|
+
# <content src="contents.html"/>
|
59
|
+
# </navPoint>
|
60
|
+
# NAV
|
61
|
+
####################### periodocal , magzine like format #########################
|
62
|
+
# <navPoint playOrder="0" class="periodical" id="periodical">
|
63
|
+
# <mbp:meta-img src="masthead.gif" name="mastheadImage"/>
|
64
|
+
# <navLabel>
|
65
|
+
# <text>Table of Contents</text>
|
66
|
+
# </navLabel>
|
67
|
+
# <content src="contents.html"/>
|
68
|
+
# <navPoint playOrder="1" class="section" id="Main-section">
|
69
|
+
# <navLabel>
|
70
|
+
# <text>Main section</text>
|
71
|
+
# </navLabel>
|
72
|
+
# <content src="001.html"/>
|
73
|
+
# <navPoint playOrder="2" class="article" id="item-001">
|
74
|
+
# <navLabel>
|
75
|
+
# <text>Nick Clegg and David Cameron agree key changes on NHS plans</text>
|
76
|
+
# </navLabel>
|
77
|
+
# <content src="001.html"/>
|
78
|
+
# <mbp:meta name="description">Deputy PM tells Andrew Marr show that GPs should not be forced to sign up to new commissioning consortiums</mbp:meta>
|
79
|
+
# <mbp:meta name="author">Nicholas Watt and Denis Campbell</mbp:meta>
|
80
|
+
# </navPoint>
|
81
|
+
# ####################################################################################
|
82
|
+
|
83
|
+
|
43
84
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mini_magick
|
16
|
-
requirement: &
|
16
|
+
requirement: &2161043520 !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: *2161043520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-readability
|
27
|
-
requirement: &
|
27
|
+
requirement: &2161042240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,8 +32,9 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
description: a
|
35
|
+
version_requirements: *2161042240
|
36
|
+
description: kindler is a rubygem allow you to generate kindle mobi book from urls
|
37
|
+
very easily
|
37
38
|
email:
|
38
39
|
- mike.d.1984@gmail.com
|
39
40
|
executables:
|
@@ -76,7 +77,8 @@ rubyforge_project: kindler
|
|
76
77
|
rubygems_version: 1.8.11
|
77
78
|
signing_key:
|
78
79
|
specification_version: 3
|
79
|
-
summary: a
|
80
|
+
summary: kindler is a rubygem allow you to generate kindle mobi book from urls very
|
81
|
+
easily
|
80
82
|
test_files:
|
81
83
|
- spec/cases/generator_spec.rb
|
82
84
|
- spec/spec_helper.rb
|