Module: PublishingPlatformNokodiff

Defined in:
lib/publishing_platform_nokodiff.rb,
lib/publishing_platform_nokodiff/differ.rb,
lib/publishing_platform_nokodiff/engine.rb,
lib/publishing_platform_nokodiff/version.rb,
lib/publishing_platform_nokodiff/html_fragment.rb,
lib/publishing_platform_nokodiff/text_node_diffs.rb,
lib/publishing_platform_nokodiff/formatting_helpers.rb,
lib/publishing_platform_nokodiff/changes_in_fragments.rb

Defined Under Namespace

Modules: FormattingHelpers Classes: ChangesInFragments, Differ, Engine, HTMLFragment, TextNodeDiffs

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.diff(before_html, after_html) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/publishing_platform_nokodiff.rb', line 16

def self.diff(before_html, after_html)
  before = PublishingPlatformNokodiff::HTMLFragment.new(before_html)
  after = PublishingPlatformNokodiff::HTMLFragment.new(after_html)

  before_nodes, after_nodes = nodes(before, after)
  keys = (before_nodes.keys + after_nodes.keys).uniq

  html = keys.any? ? diff_by_keys(after, keys, before_nodes, after_nodes) : Differ.new(before, after).to_html
  safe_html(html)
end

.safe_html(html) ⇒ Object



27
28
29
# File 'lib/publishing_platform_nokodiff.rb', line 27

def self.safe_html(html)
  html.respond_to?(:html_safe) ? html.html_safe : html
end