Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rework Renderer#text_format to use keyword params

Alexander Brandon Coles0e7429431976
diff --git a/lib/open_project/text_formatting.rb b/lib/open_project/text_formatting.rb
index dc4a1f2640f..7cc2e8a98c7 100644
--- a/lib/open_project/text_formatting.rb
+++ b/lib/open_project/text_formatting.rb
@@ -93,12 +93,11 @@ module OpenProject
return "" if text.blank?
project ||= @project || object.try(:project)
- plain = Formats.plain?(format)
Renderer.format_text(
text,
**,
- plain:,
+ format:,
object:,
request: try(:request),
current_user:,
diff --git a/lib/open_project/text_formatting/formats.rb b/lib/open_project/text_formatting/formats.rb
index 5dd05b2b4aa..a59155b987d 100644
--- a/lib/open_project/text_formatting/formats.rb
+++ b/lib/open_project/text_formatting/formats.rb
@@ -52,10 +52,6 @@ module OpenProject::TextFormatting
def supported?(name)
[plain, rich].map(&:format).include?(name.to_sym)
end
-
- def plain?(name)
- name && plain.format == name.to_sym
- end
end
end
end
diff --git a/lib/open_project/text_formatting/renderer.rb b/lib/open_project/text_formatting/renderer.rb
index bd16827de89..c299b54390c 100644
--- a/lib/open_project/text_formatting/renderer.rb
+++ b/lib/open_project/text_formatting/renderer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -30,19 +32,20 @@ module OpenProject::TextFormatting
module Renderer
module_function
- def format_text(text, options = {})
+ def format_text(text, format: :rich, **context)
return "" if text.blank?
- formatter(plain: options.delete(:plain))
- .new(options)
+ formatter_for(format)
+ .new(context)
.to_html(text)
end
- def formatter(plain: false)
- if plain
- OpenProject::TextFormatting::Formats.plain_formatter
+ def formatter_for(format)
+ case format.to_sym
+ when :plain
+ Formats.plain_formatter
else
- OpenProject::TextFormatting::Formats.rich_formatter
+ Formats.rich_formatter
end
end
end