zetaben-Html2Feedbooks 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,23 +4,22 @@ remove:
4
4
  - pagenum
5
5
  - totoi
6
6
  - img
7
+ - pg
7
8
  expr:
8
9
  - 'table'
9
10
  - //pre
10
- between:
11
- -
12
- - "//body"
13
- - "//body/h3[4]"
14
- after:
15
- - '/html/body/h4[3]'
11
+ - hr
12
+
16
13
  select:
17
14
  expr: h3
15
+ fblevel: Chapter
18
16
  select:
19
17
  expr: h4
18
+ fblevel: Section
20
19
 
21
20
  fb:
22
21
  user: #ask#
23
22
  bookid: #ask#
24
- booktype: userbook
23
+ booktype: #ask#
25
24
  pass: #ask#
26
25
  host: 'feedbooks.com'
@@ -3,6 +3,7 @@ module HTML2FB
3
3
  class Section
4
4
  attr_accessor :title
5
5
  attr_accessor :content
6
+ attr_accessor :fblevel
6
7
 
7
8
  def initialize
8
9
  @content=[]
@@ -12,17 +13,25 @@ module HTML2FB
12
13
  content.collect{|e|e.to_html}.join
13
14
  end
14
15
 
16
+ def decorated_title
17
+ unless fblevel.nil?
18
+ "[#{fblevel}] "+title
19
+ else
20
+ title
21
+ end
22
+ end
23
+
15
24
  def titles
16
25
  tit=[]
17
26
  content.each do |f|
18
27
  if f.is_a?Section
19
- tit.push f.title
28
+ tit.push f.decorated_title
20
29
  else
21
30
  tit.push '#text'
22
31
  end
23
32
  end
24
33
 
25
- return [title,tit]
34
+ return [decorated_title,tit]
26
35
  end
27
36
 
28
37
  def to_s
@@ -35,7 +44,7 @@ module HTML2FB
35
44
  #return content
36
45
  return content.collect{|a|a.titles}
37
46
  end
38
-
47
+
39
48
  end
40
49
 
41
50
  class Text
@@ -53,7 +53,7 @@ module HTML2FB
53
53
 
54
54
  class FBPost
55
55
  def self.push(conf,tit,cont,type,path=nil)
56
- puts "Sending to feedbooks #{tit}"
56
+ puts "Sending to feedbooks #{tit} with type #{type}"
57
57
  fb=FBSession.session
58
58
  if path.nil?
59
59
  post=AtomPost.new "http://#{fb.host}/#{fb.booktype}/#{fb.bookid}/contents.atom"
@@ -77,7 +77,11 @@ module HTML2FB
77
77
  @@level=0
78
78
  @@types=['Part','Chapter','Section']
79
79
  def to_feedbooks(conf,path=nil)
80
- fbpath=FBPost.push(conf,title,'',@@types[@@level]||@@types[-1],path)
80
+ type=self.fblevel.to_s.downcase.strip.capitalize
81
+ unless @@types.include?type
82
+ type=@@types[@@level]||@@types[-1]
83
+ end
84
+ fbpath=FBPost.push(conf,title,'',type,path)
81
85
  @@level+=1
82
86
  content.each do |e|
83
87
  e.to_feedbooks(conf,fbpath)
@@ -75,6 +75,7 @@ module HTML2FB
75
75
 
76
76
  tit.each do |a|
77
77
  s=Section.new
78
+ s.fblevel=@conf['select']['fblevel']
78
79
  tmp=doc.between(a.first.xpath,a.last.nil? ? nil : a.last.xpath).collect{|r| r.to_original_html}.join
79
80
  tmp.sub!(a.first.to_original_html,'')
80
81
  s.content =[Text.new(tmp)]
@@ -106,6 +107,7 @@ module HTML2FB
106
107
 
107
108
  tit.each do |a|
108
109
  s=Section.new
110
+ s.fblevel=conf['fblevel']
109
111
  tmp=doc.between(a.first.xpath,a.last.nil? ? nil : a.last.xpath).collect{|r| r.to_original_html}
110
112
 
111
113
  s.content = [Text.new(tmp.join)]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zetaben-Html2Feedbooks
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.3"
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Larroque