]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
+ (extends) :limit option support in ircify_html()
authorDmitry Kim <dmitry point kim at gmail point com>
Thu, 10 May 2007 23:24:21 +0000 (23:24 +0000)
committerDmitry Kim <dmitry point kim at gmail point com>
Thu, 10 May 2007 23:24:21 +0000 (23:24 +0000)
data/rbot/plugins/rss.rb
lib/rbot/core/utils/extends.rb

index e0d4df01747b4b6ccf77049133c62d9d22f20e0b..faf2604995e058f69adcca8c2a610094880e0b38 100644 (file)
@@ -230,11 +230,11 @@ end
 \r
 class RSSFeedsPlugin < Plugin\r
   BotConfig.register BotConfigIntegerValue.new('rss.head_max',\r
-    :default => 30, :validate => Proc.new{|v| v > 0 && v < 200},\r
+    :default => 100, :validate => Proc.new{|v| v > 0 && v < 200},\r
     :desc => "How many characters to use of a RSS item header")\r
 \r
   BotConfig.register BotConfigIntegerValue.new('rss.text_max',\r
-    :default => 90, :validate => Proc.new{|v| v > 0 && v < 400},\r
+    :default => 200, :validate => Proc.new{|v| v > 0 && v < 400},\r
     :desc => "How many characters to use of a RSS item text")\r
 \r
   BotConfig.register BotConfigIntegerValue.new('rss.thread_sleep',\r
@@ -778,9 +778,9 @@ class RSSFeedsPlugin < Plugin
       end\r
     end\r
 \r
-    title = "#{Bold}#{item.title.ircify_html}#{Bold}" if item.title\r
+    title = "#{Bold}#{item.title.ircify_html :limit => @bot.config['rss.head_max']}#{Bold}" if item.title\r
 \r
-    desc = item.description.ircify_html(:a_href => :link_out) if item.description\r
+    desc = item.description.ircify_html(:limit => @bot.config['rss.text_max'], :a_href => :link_out) if item.description\r
 \r
     link = item.link.chomp if item.link\r
 \r
index 1aa6d457a00e4f48fa7ad464128921cf6c0bfe32..80bad3836b8725b0b6fac45c8f57e4bc49389435 100644 (file)
@@ -85,8 +85,7 @@ end
 
 # Extensions to the String class
 #
-# TODO make ircify_html() accept an Hash of options, and make riphtml() just
-# call ircify_html() with stronger purify options.
+# TODO make riphtml() just call ircify_html() with stronger purify options.
 #
 class ::String
 
@@ -156,9 +155,14 @@ class ::String
 
     # And finally whitespace is squeezed
     txt.gsub!(/\s+/, ' ')
+    txt.strip!
+
+    if opts[:limit] && txt.size > opts[:limit]
+      txt = txt.slice(0, opts[:limit]) + "#{Reverse}...#{Reverse}"
+    end
 
     # Decode entities and strip whitespace
-    return txt.strip
+    return txt
   end
 
   # As above, but modify the receiver