FIX: use excerpt instead of the summary

This commit is contained in:
Régis Hanol 2014-12-06 18:48:39 +01:00
parent dec881ac9d
commit 929ff00741
5 changed files with 4 additions and 65 deletions

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <b>robin</b>").summary.should == "hello robin"
end
it "removes doctype entries" do
# this is not valid html but this is just testing DOCTYPE entries
Summarize.new("<!DOCTYPE html>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