diff --git a/app/models/user.rb b/app/models/user.rb index 7fc88a0b6fe..7ac2fbc6815 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -2,7 +2,6 @@ require_dependency 'email' require_dependency 'email_token' require_dependency 'trust_level' require_dependency 'pbkdf2' -require_dependency 'summarize' require_dependency 'discourse' require_dependency 'post_destroyer' require_dependency 'user_name_suggester' diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb index 06be18d41c1..023d86504c8 100644 --- a/app/models/user_profile.rb +++ b/app/models/user_profile.rb @@ -10,8 +10,8 @@ class UserProfile < ActiveRecord::Base BAKED_VERSION = 1 - def bio_excerpt - excerpt = PrettyText.excerpt(bio_cooked, 350) + def bio_excerpt(length=350) + excerpt = PrettyText.excerpt(bio_cooked, length) return excerpt if excerpt.blank? || (user.has_trust_level?(TrustLevel[1]) && !user.suspended?) PrettyText.strip_links(excerpt) end @@ -23,7 +23,7 @@ class UserProfile < ActiveRecord::Base def bio_summary return nil unless bio_cooked.present? - Summarize.new(bio_cooked).summary + bio_excerpt(500) end def recook_bio diff --git a/lib/summarize.rb b/lib/summarize.rb deleted file mode 100644 index d6e23595f46..00000000000 --- a/lib/summarize.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Summarize a HTML field into regular text. Used currently -# for meta tags - -require 'sanitize' - -class Summarize - - def initialize(text) - @text = text - end - - def self.max_length - 500 - end - - def summary - return nil if @text.blank? - - result = Sanitize.clean(@text) - result.gsub!(/\n/, ' ') - result.strip! - - return result if result.length <= Summarize.max_length - "#{result[0..Summarize.max_length]}..." - end - -end diff --git a/lib/topic_view.rb b/lib/topic_view.rb index a0f6b072b66..83b59047b9e 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -1,7 +1,6 @@ require_dependency 'guardian' require_dependency 'topic_query' require_dependency 'filter_best_posts' -require_dependency 'summarize' require_dependency 'gaps' class TopicView @@ -115,7 +114,7 @@ class TopicView def summary return nil if desired_post.blank? # TODO, this is actually quite slow, should be cached in the post table - Summarize.new(desired_post.cooked).summary + desired_post.excerpt(500) end def image_url diff --git a/spec/components/summarize_spec.rb b/spec/components/summarize_spec.rb deleted file mode 100644 index d0f502dde1d..00000000000 --- a/spec/components/summarize_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' -require 'summarize' - -describe Summarize do - - it "is blank when the input is nil" do - Summarize.new(nil).summary.should be_blank - end - - it "is blank when the input is an empty string" do - Summarize.new("").summary.should be_blank - end - - it "removes html tags" do - Summarize.new("hello robin").summary.should == "hello robin" - end - - it "removes doctype entries" do - # this is not valid html but this is just testing DOCTYPE entries - Summarize.new("Discourse").summary.should == "Discourse" - end - - it "strips leading and trailing space" do - Summarize.new("\t \t hello \t ").summary.should == "hello" - end - - it "trims long strings and adds an ellipsis" do - Summarize.stubs(:max_length).returns(11) - Summarize.new("discourse is a cool forum").summary.should == "discourse is..." - end - -end