rfeedreader 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 1.0.2 2007-11-14
2
+
3
+ * Add Rfeedreader.set_truncate_length(title = 45, description = 200) to manage tuncation size. No truncation: -1
4
+ * Correct text size truncation, taking care of html entity size
5
+ * Correct html entity truncation
6
+
1
7
  == 1.0.1 2007-11-14
2
8
 
3
9
  * Change user-agent signature
@@ -2,7 +2,7 @@ module Rfeedreader #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/rfeedreader.rb CHANGED
@@ -13,7 +13,7 @@ module Rfeedreader
13
13
  module_function
14
14
 
15
15
  class TextyHelper
16
- def TextyHelper.clean(text, length = 45)
16
+ def TextyHelper.clean(text, length)
17
17
  return text if text.empty?
18
18
 
19
19
  if text.index("<")
@@ -27,15 +27,16 @@ module Rfeedreader
27
27
  truncate(HTMLEntities.encode_entities(text, :named, :decimal), length)
28
28
  end
29
29
 
30
- def TextyHelper.truncate(text="", length = 45, truncate_string = "...")
31
- return if text.empty?
30
+ def TextyHelper.truncate(text="", length = 0, truncate_string = "...")
31
+ return text if text.empty? or length < 1
32
32
 
33
- l = length - truncate_string.length
33
+ # Remove size of truncate string
34
+ # and add space added by html entities
35
+ l = length - truncate_string.length + (text.size - text.gsub(/(?:&.[^;]*;)/, " ").size)
34
36
  truncated_text = text[0...l]
35
37
 
36
38
  # Avoid html entity truncation
37
- truncated_text.gsub!(/(&\S+[^;])$/, '')
38
-
39
+ truncated_text.gsub!(/(&\S[^;]+)$/, '')
39
40
  truncated_text << truncate_string if text.length > length
40
41
 
41
42
  return truncated_text
@@ -230,7 +231,9 @@ module Rfeedreader
230
231
  preformatted_title.gsub!(/<\!\[CDATA\[/, '')
231
232
  preformatted_title.gsub!(/\]\]>/, '')
232
233
  end
233
- @title = TextyHelper.convertEncoding(TextyHelper.clean(preformatted_title), @charset)
234
+ truncate_length = 45
235
+ truncate_length = Rfeedreader::TITLE_LENGTH if Rfeedreader.const_defined? "TITLE_LENGTH"
236
+ @title = TextyHelper.convertEncoding(TextyHelper.clean(preformatted_title, truncate_length), @charset)
234
237
  end
235
238
 
236
239
  def read_description
@@ -245,7 +248,9 @@ module Rfeedreader
245
248
  end
246
249
 
247
250
  unless @description.empty?
248
- @description = TextyHelper.clean(@description, 200)
251
+ truncate_length = 200
252
+ truncate_length = Rfeedreader::DESCRIPTION_LENGTH if Rfeedreader.const_defined? "DESCRIPTION_LENGTH"
253
+ @description = TextyHelper.clean(@description, truncate_length)
249
254
  @description = TextyHelper.convertEncoding(@description, @charset)
250
255
 
251
256
  @description.gsub!("&#10;", "")
@@ -338,6 +343,11 @@ module Rfeedreader
338
343
  def read_feed_header(uri)
339
344
  return read_feed(uri, parse_entries=false)
340
345
  end
346
+
347
+ def set_truncate_length(title = -1, description = -1)
348
+ const_set("TITLE_LENGTH", title)
349
+ const_set("DESCRIPTION_LENGTH", description)
350
+ end
341
351
 
342
352
  def open_doc(link)
343
353
  data = nil
@@ -206,6 +206,12 @@ class TestRfeedreader < Test::Unit::TestCase
206
206
 
207
207
  def test_title_truncate
208
208
  read_first "http://corankeando.zoomblog.com/rss.xml"
209
+ #Rfeedreader.set_truncate_length(-1, 45)
210
+ #Rfeedreader.read_first("http://corankeando.zoomblog.com/rss.xml").display_entries
211
+ end
212
+
213
+ def test_binema
214
+ read_first "http://binema.com/?feed=rss2"
209
215
  end
210
216
 
211
217
  def test_bad_title_encoding
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>rfeedreader</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rfeedreader"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/rfeedreader" class="numbers">1.0.1</a>
36
+ <a href="http://rubyforge.org/projects/rfeedreader" class="numbers">1.0.2</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rfeedreader
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2007-11-14 00:00:00 +01:00
6
+ version: 1.0.2
7
+ date: 2007-11-20 00:00:00 +01:00
8
8
  summary: Feed parser to read feed and return first posts of this feed. Special parsing from sources like Flickr, Jumcut, Google video, ...
9
9
  require_paths:
10
10
  - lib