Class: RicherText::Content
- Inherits:
-
Object
- Object
- RicherText::Content
- Includes:
- ActiveModel::Conversion, Rendering, Serialization
- Defined in:
- lib/richer_text/content.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#fragment ⇒ Object
readonly
Returns the value of attribute fragment.
Instance Method Summary collapse
- #image_blob_ids ⇒ Object
- #image_blobs ⇒ Object
- #images ⇒ Object
-
#initialize(body) ⇒ Content
constructor
A new instance of Content.
- #inspect ⇒ Object
- #mentionees_global_ids ⇒ Object
- #to_html ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(body) ⇒ Content
Returns a new instance of Content.
7 8 9 10 11 |
# File 'lib/richer_text/content.rb', line 7 def initialize(body) @body = body @fragment = RicherText::Fragment.parse(body) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
51 52 53 |
# File 'lib/richer_text/content.rb', line 51 def body @body end |
#fragment ⇒ Object (readonly)
Returns the value of attribute fragment.
50 51 52 |
# File 'lib/richer_text/content.rb', line 50 def fragment @fragment end |
Instance Method Details
#image_blob_ids ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/richer_text/content.rb', line 41 def image_blob_ids images.map do |image| # Ensure old images from ActionText which used the proxy url are supported image = image.gsub("/proxy/", "/redirect/") # Fetch the signed_blob_id from the image src image.split("/rails/active_storage/blobs/redirect/").last.split("/").first end end |
#image_blobs ⇒ Object
37 38 39 |
# File 'lib/richer_text/content.rb', line 37 def image_blobs image_blob_ids.map { |id| ActiveStorage::Blob.find_signed(id) } end |
#images ⇒ Object
25 26 27 28 29 |
# File 'lib/richer_text/content.rb', line 25 def images @images ||= fragment.find_all("img").map do |img| img.attributes["src"].value end.uniq end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/richer_text/content.rb', line 13 def inspect "#<#{self.class.name} #{to_html.truncate(25).inspect}>" end |
#mentionees_global_ids ⇒ Object
31 32 33 34 35 |
# File 'lib/richer_text/content.rb', line 31 def mentionees_global_ids global_ids = fragment.find_all("span[data-type=mention]").map do |span| span.attributes["data-id"].value end.uniq end |
#to_html ⇒ Object
21 22 23 |
# File 'lib/richer_text/content.rb', line 21 def to_html body end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/richer_text/content.rb', line 17 def to_s render partial: to_partial_path, layout: false, locals: { content: self } end |