Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Setting FB type on Sections

  • Loading branch information...
commit 7f26f96c5456593f8f60e8f6eba304edb3e29319 1 parent e22ec93
@zetaben authored
View
13 confs/conf.yaml
@@ -4,23 +4,22 @@ remove:
- pagenum
- totoi
- img
+ - pg
expr:
- 'table'
- //pre
- between:
- -
- - "//body"
- - "//body/h3[4]"
- after:
- - '/html/body/h4[3]'
+ - hr
+
select:
expr: h3
+ fblevel: Chapter
select:
expr: h4
+ fblevel: Section
fb:
user: #ask#
bookid: #ask#
- booktype: userbook
+ booktype: #ask#
pass: #ask#
host: 'feedbooks.com'
View
15 lib/document.rb
@@ -3,6 +3,7 @@ module HTML2FB
class Section
attr_accessor :title
attr_accessor :content
+ attr_accessor :fblevel
def initialize
@content=[]
@@ -12,17 +13,25 @@ def to_html
content.collect{|e|e.to_html}.join
end
+ def decorated_title
+ unless fblevel.nil?
+ "[#{fblevel}] "+title
+ else
+ title
+ end
+ end
+
def titles
tit=[]
content.each do |f|
if f.is_a?Section
- tit.push f.title
+ tit.push f.decorated_title
else
tit.push '#text'
end
end
- return [title,tit]
+ return [decorated_title,tit]
end
def to_s
@@ -35,7 +44,7 @@ def toc
#return content
return content.collect{|a|a.titles}
end
-
+
end
class Text
View
8 lib/feedbooks.rb
@@ -53,7 +53,7 @@ def to_feedbooks(conf)
class FBPost
def self.push(conf,tit,cont,type,path=nil)
- puts "Sending to feedbooks #{tit}"
+ puts "Sending to feedbooks #{tit} with type #{type}"
fb=FBSession.session
if path.nil?
post=AtomPost.new "http://#{fb.host}/#{fb.booktype}/#{fb.bookid}/contents.atom"
@@ -77,7 +77,11 @@ class Section
@@level=0
@@types=['Part','Chapter','Section']
def to_feedbooks(conf,path=nil)
- fbpath=FBPost.push(conf,title,'',@@types[@@level]||@@types[-1],path)
+ type=self.fblevel.to_s.downcase.strip.capitalize
+ unless @@types.include?type
+ type=@@types[@@level]||@@types[-1]
+ end
+ fbpath=FBPost.push(conf,title,'',type,path)
@@level+=1
content.each do |e|
e.to_feedbooks(conf,fbpath)
View
2  lib/parser.rb
@@ -75,6 +75,7 @@ def parse_text(doc,ret)
tit.each do |a|
s=Section.new
+ s.fblevel=@conf['select']['fblevel']
tmp=doc.between(a.first.xpath,a.last.nil? ? nil : a.last.xpath).collect{|r| r.to_original_html}.join
tmp.sub!(a.first.to_original_html,'')
s.content =[Text.new(tmp)]
@@ -106,6 +107,7 @@ def parse_rec(el,conf)
tit.each do |a|
s=Section.new
+ s.fblevel=conf['fblevel']
tmp=doc.between(a.first.xpath,a.last.nil? ? nil : a.last.xpath).collect{|r| r.to_original_html}
s.content = [Text.new(tmp.join)]
Please sign in to comment.
Something went wrong with that request. Please try again.