FEATURE: Display emojis in user stream.
This commit is contained in:
parent
410ae47dd7
commit
7c1e16da54
|
@ -32,7 +32,7 @@ class UserActionSerializer < ApplicationSerializer
|
|||
|
||||
def excerpt
|
||||
cooked = object.cooked || PrettyText.cook(object.raw)
|
||||
PrettyText.excerpt(cooked, 300) if cooked
|
||||
PrettyText.excerpt(cooked, 300, { keep_emojis: true }) if cooked
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
|
|
|
@ -196,7 +196,7 @@ class UserSerializer < BasicUserSerializer
|
|||
end
|
||||
|
||||
def bio_excerpt
|
||||
object.user_profile.bio_excerpt(350 ,keep_newlines: true)
|
||||
object.user_profile.bio_excerpt(350 , { keep_newlines: true, keep_emojis: true })
|
||||
end
|
||||
|
||||
def include_suspend_reason?
|
||||
|
|
|
@ -13,6 +13,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
@text_entities = options[:text_entities] == true
|
||||
@markdown_images = options[:markdown_images] == true
|
||||
@keep_newlines = options[:keep_newlines] == true
|
||||
@keep_emojis = options[:keep_emojis] == true
|
||||
@start_excerpt = false
|
||||
end
|
||||
|
||||
|
@ -48,10 +49,15 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
|
|||
case name
|
||||
when "img"
|
||||
|
||||
attributes = Hash[*attributes.flatten]
|
||||
|
||||
if @keep_emojis && attributes["class"] == 'emoji'
|
||||
return include_tag(name, attributes)
|
||||
end
|
||||
|
||||
# If include_images is set, include the image in markdown
|
||||
characters("!") if @markdown_images
|
||||
|
||||
attributes = Hash[*attributes.flatten]
|
||||
if attributes["alt"]
|
||||
characters("[#{attributes["alt"]}]")
|
||||
elsif attributes["title"]
|
||||
|
|
|
@ -230,6 +230,11 @@ describe PrettyText do
|
|||
expect(PrettyText.excerpt("'", 500, text_entities: true)).to eq("'")
|
||||
end
|
||||
|
||||
it "should have an option to preserve emojis" do
|
||||
emoji_image = "<img src='/images/emoji/emoji_one/heart.png?v=0' title=':heart:' class='emoji' alt='heart'>"
|
||||
expect(PrettyText.excerpt(emoji_image, 100, { keep_emojis: true })).to match_html(emoji_image)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "strip links" do
|
||||
|
|
Loading…
Reference in New Issue