From e69e9f679418724a71bfc86916cb4980cc56621d Mon Sep 17 00:00:00 2001 From: zmagod Date: Fri, 24 Nov 2017 17:04:01 +0100 Subject: [PATCH] remove unneeded comment and add tiny_mce_asset regex in a constant --- app/helpers/tiny_mce_helper.rb | 5 ++--- app/utilities/protocols_exporter.rb | 2 +- app/utilities/protocols_importer.rb | 2 +- config/initializers/constants.rb | 2 ++ 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/tiny_mce_helper.rb b/app/helpers/tiny_mce_helper.rb index ade7c0df5..a58b88b0c 100644 --- a/app/helpers/tiny_mce_helper.rb +++ b/app/helpers/tiny_mce_helper.rb @@ -10,7 +10,6 @@ module TinyMceHelper img.replace(token) next unless obj tiny_img = TinyMceAsset.find_by_id(img_id) - # next if check_parse_token_permissions(obj, tiny_img) tiny_img.reference = obj unless tiny_img.step || tiny_img.result_text tiny_img.save end @@ -20,7 +19,7 @@ module TinyMceHelper def generate_image_tag_from_token(text, obj) return unless text - regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ + regex = Constants::TINY_MCE_ASSET_REGEX text.gsub(regex) do |el| match = el.match(regex) img = TinyMceAsset.find_by_id(match[1]) @@ -34,7 +33,7 @@ module TinyMceHelper def link_tiny_mce_assets(text, ref) ids = [] - regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ + regex = Constants::TINY_MCE_ASSET_REGEX text.gsub(regex) do |img| match = img.match(regex) tiny_img = TinyMceAsset.find_by_id(match[1]) diff --git a/app/utilities/protocols_exporter.rb b/app/utilities/protocols_exporter.rb index 9ea7f1fd0..5c4a98ab9 100644 --- a/app/utilities/protocols_exporter.rb +++ b/app/utilities/protocols_exporter.rb @@ -41,7 +41,7 @@ module ProtocolsExporter def get_tiny_mce_assets(text) return unless text - regex = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ + regex = Constants::TINY_MCE_ASSET_REGEX tiny_assets_xml = "\n" text.gsub(regex) do |el| match = el.match(regex) diff --git a/app/utilities/protocols_importer.rb b/app/utilities/protocols_importer.rb index 5c03b7a83..bf9292a69 100644 --- a/app/utilities/protocols_importer.rb +++ b/app/utilities/protocols_importer.rb @@ -170,6 +170,6 @@ module ProtocolsImporter # handle import from legacy exports def populate_rte_legacy(step_json) return unless step_json['description'] && step_json['description'].present? - step_json['description'].gsub(/\[~tiny_mce_id:([0-9a-zA-Z]+)\]/, '') + step_json['description'].gsub(Constants::TINY_MCE_ASSET_REGEX, '') end end diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 1bb0e2bc2..bdca92004 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -864,6 +864,8 @@ class Constants # Very basic regex to check for validity of emails BASIC_EMAIL_REGEX = URI::MailTo::EMAIL_REGEXP + TINY_MCE_ASSET_REGEX = /\[~tiny_mce_id:([0-9a-zA-Z]+)\]/ + # Team name for default admin user DEFAULT_PRIVATE_TEAM_NAME = 'My projects'.freeze