epub_book 0.1.12 → 0.1.13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f97b7dd57c6d5f908aad4c6ff2e02bd0d850e5e
4
- data.tar.gz: 0b0a7fb475fff417e0412b2758ddcb74d4dd5e25
3
+ metadata.gz: 242f6d9ee15d028f0c72cd604790292af9c9b2d9
4
+ data.tar.gz: 9856509153f5caafd9f2aae760dc4f8013e302a6
5
5
  SHA512:
6
- metadata.gz: 59a3c190c686e0ec7bf42f3c40e142ab3bd699679d489f7c2f93078861fbf6266eea540a02bd73253385b5e53c7318939936ca6eb1d68de7c8287ced27e64c2b
7
- data.tar.gz: 5ef21c42347c49fb71c6282e7820f928bb17be68b5d1ba0cbf55013ce983bbb01d8db165f4c57362ab8cdebf0735d1dcbe8a45ad3a11ceeb6227015db911b24a
6
+ metadata.gz: 088faed36f70d1b635ae0e4eff49648d0f96b985388af0b5fdb319495c62b37662a559a9dc9a06e94564f6cd18173bbbb1238657be56d36f1fffadd3afa3ee27
7
+ data.tar.gz: 516aee02a5ffa3f7b6fee89ff55fd2399ae7564b69510d7ea1d4c70693906784bcc5df88a012be9223d508cc17033f6cb535f59999ddf76f514bb914953c1e44
data/README.md CHANGED
@@ -71,13 +71,21 @@ Or use a ./default_setting.yml file have following content
71
71
  mail_to: 'yourmail@example.com'
72
72
 
73
73
  #special host book setting(the key is book_url's host which replacing the dot with underline)
74
+ #http://www.piaotian.net/html/0/431/index.html
74
75
  www_piaotian_net:
75
- cover_css: '.pic_txt_list .pic img'
76
- description_css: '.box p.description'
77
- title_css: '.pic_txt_list h3 span'
78
- index_item_css: 'ul.list li.c3 a'
79
- body_css: '.wrapper #content'
80
- path: '/'
76
+ cover_css: '#content td>table:not(.grid) img[src$=jpg]'
77
+ description_css: '#content td>table:not(.grid) div:last-child > text()'
78
+ title_css: '#content h1'
79
+ index_item_css: '.centent a'
80
+ body_css: 'body > text()'
81
+
82
+ #http://www.shumilou.co/yitongjiangshan/
83
+ www_shumilou_co:
84
+ cover_css: ".content .list img.sayimg"
85
+ description_css: ".content .list:contains(img) > text()"
86
+ title_css: ".content .list .tit b:first"
87
+ index_item_css: ".content .list ul li a"
88
+ body_css: '#content p'
81
89
  ```
82
90
 
83
91
  if you have setting file , you can create book like following
@@ -49,6 +49,7 @@ module EpubBook
49
49
  end
50
50
 
51
51
  def book
52
+ Dir.mkdir(@book_path) unless test(?d,@book_path)
52
53
  @book ||= test(?s,File.join(@book_path,'index.yml')) ? YAML.load(File.open(File.join(@book_path,'index.yml'))) : ({files: []})
53
54
  end
54
55
 
@@ -61,7 +62,6 @@ module EpubBook
61
62
 
62
63
  #创建书本
63
64
  def generate_book(book_name=nil)
64
- Dir.mkdir(@book_path) unless test(?d,@book_path)
65
65
  #获取epub源数据
66
66
  fetch_book
67
67
  if !@cover_css && @cover
@@ -107,6 +107,8 @@ module EpubBook
107
107
  end
108
108
 
109
109
 
110
+
111
+
110
112
  #得到书目索引
111
113
  def fetch_index(url=nil)
112
114
  url ||= @index_url
@@ -127,14 +129,7 @@ module EpubBook
127
129
  _href = URI.encode(item.attr(@item_attr).to_s)
128
130
  next if _href.start_with?('javascript') || _href.start_with?('#')
129
131
 
130
- if _href.start_with?("http")
131
- _href
132
- elsif _href.start_with?("/")
133
- _href = "#{link_host}#{_href}"
134
- else
135
- @path_name ||= @index_url[/.*\//]
136
- _href = "#{@path_name}#{_href}"
137
- end
132
+ _href = generate_abs_url(_href)
138
133
 
139
134
  book[:files] << {label: item.text, url: _href}
140
135
  end
@@ -142,7 +137,7 @@ module EpubBook
142
137
  #如果有分页
143
138
  if @page_css && @page_attr
144
139
  if next_page = doc.css(@page_css).attr(@page_attr).to_s
145
- fetch_index(next_page)
140
+ fetch_index(generate_abs_url(next_page))
146
141
  else
147
142
  return
148
143
  end
@@ -176,7 +171,7 @@ module EpubBook
176
171
  puts item[:label]
177
172
 
178
173
  rescue Exception => e
179
- puts e.message
174
+ puts "Error:#{e.message}"
180
175
  puts e.backtrace.inspect
181
176
  next
182
177
  end
@@ -197,7 +192,7 @@ module EpubBook
197
192
  book[:title] = doc.css(@title_css).text.strip
198
193
  if @cover_css && !book[:cover]
199
194
  cover_url = doc.css(@cover_css).attr("src").to_s
200
- cover_url = link_host + cover_url unless cover_url.start_with?("http")
195
+ cover_url = generate_abs_url(cover_url) #link_host + cover_url unless cover_url.start_with?("http")
201
196
  cover_path = File.join(@book_path,@cover)
202
197
  system("curl #{cover_url} -o #{cover_path} ")
203
198
  book[:cover] = cover_path
@@ -208,6 +203,18 @@ module EpubBook
208
203
  end
209
204
  end
210
205
 
206
+ def generate_abs_url(url)
207
+ if _href.start_with?("http")
208
+ url
209
+ elsif _href.start_with?("/")
210
+ "#{link_host}#{_href}"
211
+ else
212
+ @path_name ||= @index_url[/.*\//]
213
+ "#{@path_name}#{_href}"
214
+ end
215
+
216
+ end
217
+
211
218
  end
212
219
 
213
220
  end
@@ -1,3 +1,3 @@
1
1
  module EpubBook
2
- VERSION = "0.1.12"
2
+ VERSION = "0.1.13"
3
3
  end
data/lib/epub_book.rb CHANGED
@@ -11,7 +11,7 @@ module EpubBook
11
11
  include Singleton
12
12
  def initialize
13
13
  self.mail_subject = 'epub 电子书'
14
- self.mail_body = "您创建的电子书见附件\n"
14
+ #self.mail_body = "您创建的电子书见附件\n"
15
15
  self.mail_port = 25
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epub_book
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - qmliu