Merge pull request #1736 from aignatov-bio/ai-sci-3423-add-old-tinymce-support

Add old tinymce image support [SCI-3423]
This commit is contained in:
aignatov-bio 2019-05-10 15:27:42 +02:00 committed by GitHub
commit bbf54de9c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -13,6 +13,10 @@ module TinyMceImages
def prepare_for_report(field)
description = self[field]
# Check tinymce for old format
description = TinyMceAsset.update_old_tinymce(description)
tiny_mce_assets.each do |tm_asset|
tmp_f = Tempfile.open(tm_asset.image_file_name, Rails.root.join('tmp'))
begin
@ -41,7 +45,12 @@ module TinyMceImages
# and updates references in assosiated object's description
def reassign_tiny_mce_image_references(images = [])
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
parsed_description = Nokogiri::HTML(read_attribute(object_field))
description = read_attribute(object_field)
# Check tinymce for old format
description = TinyMceAsset.update_old_tinymce(description)
parsed_description = Nokogiri::HTML(description)
images.each do |image|
old_id = image[0]
new_id = image[1]

View file

@ -49,6 +49,9 @@ class TinyMceAsset < ApplicationRecord
end
def self.generate_url(description)
# Check tinymce for old format
description = update_old_tinymce(description)
description = Nokogiri::HTML(description)
tm_assets = description.css('img')
tm_assets.each do |tm_asset|
@ -103,9 +106,11 @@ class TinyMceAsset < ApplicationRecord
end
def self.update_old_tinymce(description)
return description unless description
description.scan(/\[~tiny_mce_id:(\w+)\]/).flatten.each do |token|
old_format = /\[~tiny_mce_id:#{token}\]/
new_format = "<img src=\"\" class=\"img-responsive\" data-mce-token=\"#{Base62.encode(token)}\"/>"
new_format = "<img src=\"\" class=\"img-responsive\" data-mce-token=\"#{Base62.encode(token.to_i)}\"/>"
description.sub!(old_format, new_format)
end
description