Class: CssCompare::CSS::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/css_compare/css/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • (File)


7
8
9
# File 'lib/css_compare/css/parser.rb', line 7

def initialize(input)
  @input = File.expand_path(input)
end

Instance Method Details

#parse::Sass::Tree::RootNode

Note:

The specified syntax is ‘:scss` because `:css` has been throwing syntax error on @charset directive.

Parses a CSS project using the Sass parser

Returns:

  • (::Sass::Tree::RootNode)


18
19
20
21
22
23
24
25
# File 'lib/css_compare/css/parser.rb', line 18

def parse
  tree = ::Sass::Engine.new(
    File.read(@input),
    :syntax => :scss, :filename => File.expand_path(@input)
  ).to_tree
  ::Sass::Tree::Visitors::CheckNesting.visit(tree)
  ::Sass::Tree::Visitors::Perform.visit(tree)
end