Class: Crm::ArticleRevisionDiffRowComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Crm::ArticleRevisionDiffRowComponent
- Defined in:
- app/components/crm/article_revision_diff_row_component.rb
Overview
Renders one side-by-side Article revision comparison row.
Defined Under Namespace
Classes: ContentDiff, DataValues, FragmentMarker, KeyedDiff, SegmentCursor, TokenDiff
Constant Summary collapse
- FORMATS =
Supported comparison formats.
%i[collection rich_text source text].freeze
- RICH_CONTENT_FIELDS =
Article content fields whose values hold rich-text HTML.
%i[description solution].freeze
Class Method Summary collapse
-
.for_article_data(field:, current:, proposed:) ⇒ Crm::ArticleRevisionDiffRowComponent
Builds a row comparing one Article data (non-content) field as a collection of labeled entries.
-
.for_content(field:, current:, proposed:) ⇒ Crm::ArticleRevisionDiffRowComponent
Builds a row comparing one Article content field.
Instance Method Summary collapse
-
#initialize(label:, current:, proposed:, format: :text) ⇒ ArticleRevisionDiffRowComponent
constructor
A new instance of ArticleRevisionDiffRowComponent.
Methods inherited from ApplicationComponent
#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags
Constructor Details
#initialize(label:, current:, proposed:, format: :text) ⇒ ArticleRevisionDiffRowComponent
Returns a new instance of ArticleRevisionDiffRowComponent.
50 51 52 53 54 55 56 57 58 |
# File 'app/components/crm/article_revision_diff_row_component.rb', line 50 def initialize(label:, current:, proposed:, format: :text) super() raise ArgumentError, "Unsupported comparison format: #{format}" unless FORMATS.include?(format.to_sym) @label = label @current = current @proposed = proposed @format = format.to_sym end |
Class Method Details
.for_article_data(field:, current:, proposed:) ⇒ Crm::ArticleRevisionDiffRowComponent
Builds a row comparing one Article data (non-content) field as a
collection of labeled entries.
40 41 42 43 |
# File 'app/components/crm/article_revision_diff_row_component.rb', line 40 def self.for_article_data(field:, current:, proposed:) current_values, proposed_values = DataValues.new(field:, current:, proposed:).to_a new(label: field.to_s.humanize, current: current_values, proposed: proposed_values, format: :collection) end |
.for_content(field:, current:, proposed:) ⇒ Crm::ArticleRevisionDiffRowComponent
Builds a row comparing one Article content field.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/crm/article_revision_diff_row_component.rb', line 21 def self.for_content(field:, current:, proposed:) format = if RICH_CONTENT_FIELDS.include?(field.to_sym) :rich_text elsif field.to_sym == :inline_js :source else :text end new(label: field.to_s.humanize, current:, proposed:, format:) end |