Class: Crm::ArticleRevisionDiffRowComponent::FragmentMarker
- Inherits:
-
Object
- Object
- Crm::ArticleRevisionDiffRowComponent::FragmentMarker
- Defined in:
- app/components/crm/article_revision_diff_row_component/fragment_marker.rb
Overview
Applies one side's semantic ins/del nodes to an already-sanitized fragment.
Instance Method Summary collapse
-
#call ⇒ Nokogiri::HTML::DocumentFragment
Rebuilds every text node in the fragment, wrapping changed runs in the configured element.
-
#initialize(fragment:, segments:, element:, css_class:) ⇒ FragmentMarker
constructor
A new instance of FragmentMarker.
Constructor Details
#initialize(fragment:, segments:, element:, css_class:) ⇒ FragmentMarker
Returns a new instance of FragmentMarker.
12 13 14 15 16 17 |
# File 'app/components/crm/article_revision_diff_row_component/fragment_marker.rb', line 12 def initialize(fragment:, segments:, element:, css_class:) @fragment = fragment @cursor = Crm::ArticleRevisionDiffRowComponent::SegmentCursor.new(segments) @element = element @css_class = css_class end |
Instance Method Details
#call ⇒ Nokogiri::HTML::DocumentFragment
Rebuilds every text node in the fragment, wrapping changed runs in the
configured element.
22 23 24 25 26 27 28 29 30 |
# File 'app/components/crm/article_revision_diff_row_component/fragment_marker.rb', line 22 def call fragment.xpath(".//text()").each do |text_node| cursor.take(text_node.text).each do |text, changed| text_node.add_previous_sibling(build_node(text, changed)) end text_node.remove end fragment end |