Class: Canon::Comparison::HtmlCompareProfile
- Inherits:
-
CompareProfile
- Object
- CompareProfile
- Canon::Comparison::HtmlCompareProfile
- Defined in:
- lib/canon/comparison/html_compare_profile.rb
Overview
HtmlCompareProfile extends CompareProfile with HTML-specific comparison policies
HTML has different semantics than XML:
-
Comments are presentational (default to :ignore unless explicitly :strict)
-
Whitespace preservation required in specific elements
-
Case sensitivity differs between HTML4 and HTML5
-
Self-closing tags handled differently
This class provides HTML-specific policy decisions while maintaining the separation of concerns established by CompareProfile.
Instance Attribute Summary collapse
-
#html_version ⇒ Object
readonly
Returns the value of attribute html_version.
Attributes inherited from CompareProfile
Instance Method Summary collapse
-
#affects_equivalence?(dimension) ⇒ Boolean
Override for HTML-specific comment handling.
-
#case_sensitive? ⇒ Boolean
Check if element names should be compared case-sensitively.
-
#initialize(match_options, html_version: :html5) ⇒ HtmlCompareProfile
constructor
A new instance of HtmlCompareProfile.
-
#preserve_whitespace?(element_name) ⇒ Boolean
Check if whitespace should be preserved for a given element.
Methods inherited from CompareProfile
#normative_dimension?, #supports_formatting_detection?, #track_dimension?
Constructor Details
#initialize(match_options, html_version: :html5) ⇒ HtmlCompareProfile
Returns a new instance of HtmlCompareProfile.
24 25 26 27 |
# File 'lib/canon/comparison/html_compare_profile.rb', line 24 def initialize(, html_version: :html5) super() @html_version = html_version end |
Instance Attribute Details
#html_version ⇒ Object (readonly)
Returns the value of attribute html_version.
20 21 22 |
# File 'lib/canon/comparison/html_compare_profile.rb', line 20 def html_version @html_version end |
Instance Method Details
#affects_equivalence?(dimension) ⇒ Boolean
Override for HTML-specific comment handling
In HTML, comments are presentational content (not part of the DOM semantics) unless explicitly set to :strict. This differs from XML where comments may carry semantic meaning.
HTML default for comments is :ignore, so comments don’t affect equivalence unless the user explicitly sets comments: :strict
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/canon/comparison/html_compare_profile.rb', line 40 def affects_equivalence?(dimension) # Comments in HTML: default is :ignore (presentational) # Only affect equivalence if explicitly set to :strict if dimension == :comments # Check if comments key exists in options if .is_a?(Hash) # If comments key doesn't exist, default to false (HTML default: ignore) return false unless .key?(:comments) # If key exists, check if it's :strict return [:comments] == :strict elsif .respond_to?(:behavior_for) behavior = behavior_for(dimension) # In HTML, only :strict makes comments affect equivalence return behavior == :strict end # Default: comments don't affect equivalence in HTML return false end # All other dimensions use base class behavior super end |
#case_sensitive? ⇒ Boolean
Check if element names should be compared case-sensitively
HTML4 is case-insensitive, HTML5 is case-sensitive
80 81 82 |
# File 'lib/canon/comparison/html_compare_profile.rb', line 80 def case_sensitive? @html_version == :html5 end |
#preserve_whitespace?(element_name) ⇒ Boolean
Check if whitespace should be preserved for a given element
HTML has specific elements where whitespace is significant: <pre>, <code>, <textarea>, <script>, <style>
71 72 73 |
# File 'lib/canon/comparison/html_compare_profile.rb', line 71 def preserve_whitespace?(element_name) html_preserve_elements.include?(element_name.to_s.downcase) end |