diff --git a/lib/open_project/text_formatting/matchers/attribute_macros.rb b/lib/open_project/text_formatting/matchers/attribute_macros.rb index 9d21b035a0c5..09511d88f34a 100644 --- a/lib/open_project/text_formatting/matchers/attribute_macros.rb +++ b/lib/open_project/text_formatting/matchers/attribute_macros.rb @@ -70,6 +70,14 @@ def self.relative_embed?(macro_attributes) macro_attributes[:id].nil? end + def self.relative_id(macro_attributes, context) + if project_embed?(macro_attributes) && context[:project].present? + context[:project].try(:id) + elsif work_package_embed?(macro_attributes) && work_package_context?(context) + context[:object].try(:id) + end + end + def self.process_match(match, _matched_string, context) # Leading string before match macro_attributes = { @@ -79,13 +87,7 @@ def self.process_match(match, _matched_string, context) } type = match[2].downcase - if relative_embed?(macro_attributes) - if project_embed?(macro_attributes) && context[:project].present? - macro_attributes[:id] = context[:project].try(:id) - elsif work_package_embed?(macro_attributes) && work_package_context?(context) - macro_attributes[:id] = context[:object].try(:id) - end - end + macro_attributes[:id] = relative_id(macro_attributes, context) if relative_embed?(macro_attributes) ApplicationController.helpers.content_tag "opce-macro-attribute-#{type}", "",