zetaben-Html2Feedbooks 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/conf.rb +1 -0
  2. data/lib/parser.rb +30 -6
  3. metadata +1 -1
data/lib/conf.rb CHANGED
@@ -8,6 +8,7 @@ module HTML2FB
8
8
  begin
9
9
  if File.readable?(f) && File.exists?(f)
10
10
  @conf=File.open(f,'r'){|txt| YAML::load(txt)}
11
+ puts "loaded config file : "+f
11
12
  return
12
13
  end
13
14
  rescue Exception => e
data/lib/parser.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'hpricot'
2
2
  require 'document.rb'
3
3
  require 'progressbar'
4
+ #require 'ruby-prof'
4
5
  #require 'term/ansicolor'
5
6
  #include Term::ANSIColor
6
7
 
@@ -63,6 +64,9 @@ module HTML2FB
63
64
  end
64
65
 
65
66
  def parse_text(doc,ret)
67
+ # RubyProf.start
68
+
69
+
66
70
  aut=build_autom(@conf['select'],ret)
67
71
 
68
72
  pbar = ProgressBar.new("Parsing", doc.search('//').size)
@@ -72,6 +76,16 @@ module HTML2FB
72
76
  end
73
77
  pbar.finish
74
78
  aut.finish(doc)
79
+ =begin
80
+ result = RubyProf.stop
81
+ printer = RubyProf::FlatPrinter.new(result)
82
+ printer.print(STDOUT, 0)
83
+ printer.print(File.new('/versatile/prof','w'),0)
84
+ printer = RubyProf::GraphHtmlPrinter.new(result)
85
+ printer.print(File.new('/versatile/profgraph.html','w'), :min_percent=>0)
86
+ printer = RubyProf::CallTreePrinter.new(result)
87
+ printer.print(File.new('/versatile/profgraph.tree','w'), :min_percent=>0)
88
+ =end
75
89
  end
76
90
 
77
91
  protected
@@ -143,10 +157,14 @@ module HTML2FB
143
157
  end
144
158
 
145
159
  def open_section(obj,lvl,el)
146
- # if @current_level < lvl
147
- t=create_textNode((el.root.search(@content...(el.xpath))[1..-1].to_html))
148
- @starts[@current_level].content.push(t)
149
- # end
160
+ tmp=el.root.search(@content...(el.xpath))[1..-1]
161
+ unless tmp.blank?
162
+ tmph=tmp.to_html
163
+ unless tmph.blank?
164
+ t=create_textNode(tmph)
165
+ @starts[@current_level].content.push(t)
166
+ end
167
+ end
150
168
  (lvl..@max_level).to_a.reverse.each do |l|
151
169
  close_section(l)
152
170
  end
@@ -172,6 +190,7 @@ module HTML2FB
172
190
 
173
191
 
174
192
  open_section({:xpath => el.xpath, :fblevel => expr['fblevel']},i+1,el)
193
+ break
175
194
  end
176
195
  end
177
196
  end
@@ -183,7 +202,7 @@ end
183
202
 
184
203
  class String
185
204
  def blank?
186
- self==""
205
+ self !~ /\S/
187
206
  end
188
207
  end
189
208
 
@@ -197,7 +216,7 @@ module Hpricot::Traverse
197
216
  def in_search?(expr)
198
217
  se_in=self.parent
199
218
  if expr[0..1]=='/'
200
- se_in=se_in.parent until se_in.parent.nil?
219
+ se_in=self.root
201
220
  end
202
221
  se_in.search(expr).each do |el|
203
222
  return true if el==self
@@ -207,8 +226,10 @@ module Hpricot::Traverse
207
226
  end
208
227
 
209
228
  def root
229
+ return @root unless @root.nil?
210
230
  se_in=self
211
231
  se_in=se_in.parent until se_in.parent.nil?
232
+ @root=se_in
212
233
  se_in
213
234
  end
214
235
 
@@ -221,3 +242,6 @@ module Hpricot::Traverse
221
242
  end
222
243
  end
223
244
 
245
+ class Hpricot::Elements
246
+ alias_method :blank?, :empty?
247
+ end
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Larroque