Class: ForemanThemeSatellite::CssCompare
- Inherits:
-
Object
- Object
- ForemanThemeSatellite::CssCompare
- Defined in:
- lib/generators/foreman_theme_satellite/lib/css_compare.rb
Overview
Semantically compares two css files. returns hash: rule => prop => value
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #diff ⇒ Object
-
#initialize(left_filename: nil, left_css: nil, right_filename: nil, right_css: nil) ⇒ CssCompare
constructor
A new instance of CssCompare.
- #to_css(diff) ⇒ Object
Constructor Details
#initialize(left_filename: nil, left_css: nil, right_filename: nil, right_css: nil) ⇒ CssCompare
Returns a new instance of CssCompare.
11 12 13 14 |
# File 'lib/generators/foreman_theme_satellite/lib/css_compare.rb', line 11 def initialize(left_filename: nil, left_css: nil, right_filename: nil, right_css: nil) @left = left_filename ? Sass::Engine.for_file(left_filename, syntax: :scss) : Sass::Engine.new(left_css, syntax: :scss) @right = right_filename ? Sass::Engine.for_file(right_filename, syntax: :scss) : Sass::Engine.new(right_css, syntax: :scss) end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
9 10 11 |
# File 'lib/generators/foreman_theme_satellite/lib/css_compare.rb', line 9 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
9 10 11 |
# File 'lib/generators/foreman_theme_satellite/lib/css_compare.rb', line 9 def right @right end |
Instance Method Details
#diff ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/foreman_theme_satellite/lib/css_compare.rb', line 16 def diff result_hash = {} right_hash = rules_hash(right) rules_hash(left).each do |rule, props| right_props = right_hash[rule] unless props result_hash[rule] = props next end diffed_props = props_diff(props_hash(props), props_hash(right_props)) result_hash[rule] = diffed_props unless diffed_props.empty? end result_hash end |
#to_css(diff) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/foreman_theme_satellite/lib/css_compare.rb', line 36 def to_css(diff) diff.map do |rule, props| [ "#{rule} {", to_properties_css(props, ' '), '}' ] end.flatten.join("\n") end |