lib/scss_lint/engine.rb in scss-lint-0.30.0 vs lib/scss_lint/engine.rb in scss-lint-0.31.0

- old
+ new

@@ -8,18 +8,19 @@ class Engine ENGINE_OPTIONS = { cache: false, syntax: :scss } attr_reader :contents, :filename, :lines, :tree + # Creates a parsed representation of an SCSS document from the given string + # or file. + # + # @param scss_or_filename [String] def initialize(scss_or_filename) if File.exist?(scss_or_filename) - @filename = scss_or_filename - @engine = Sass::Engine.for_file(scss_or_filename, ENGINE_OPTIONS) - @contents = File.open(scss_or_filename, 'r').read + build_from_file(scss_or_filename) else - @engine = Sass::Engine.new(scss_or_filename, ENGINE_OPTIONS) - @contents = scss_or_filename + build_from_string(scss_or_filename) end # Need to force encoding to avoid Windows-related bugs. # Need `to_a` for Ruby 1.9.3. @lines = @contents.force_encoding('UTF-8').lines.to_a @@ -31,8 +32,23 @@ "Unable to parse SCSS file: #{error}", error.backtrace else raise end + end + + private + + # @param path [String] + def build_from_file(path) + @filename = path + @engine = Sass::Engine.for_file(path, ENGINE_OPTIONS) + @contents = File.open(path, 'r').read + end + + # @param scss [String] + def build_from_string(scss) + @engine = Sass::Engine.new(scss, ENGINE_OPTIONS) + @contents = scss end end end