Sha256: f275116871207524529be663cd155f828d89312f300793e553361131899c02b8

Contents?: true

Size: 1.08 KB

Versions: 10

Compression:

Stored size: 1.08 KB

Contents

require 'sass'

module SCSSLint
  class FileEncodingError < StandardError; end

  # Contains all information for a parsed SCSS file, including its name,
  # contents, and parse tree.
  class Engine
    ENGINE_OPTIONS = { cache: false, syntax: :scss }

    attr_reader :contents, :filename, :lines, :tree

    def initialize(scss_or_filename)
      if File.exists?(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
      else
        @engine = Sass::Engine.new(scss_or_filename, ENGINE_OPTIONS)
        @contents = scss_or_filename
      end

      @lines = @contents.split("\n")
      @tree = @engine.to_tree
    rescue Encoding::UndefinedConversionError, ArgumentError => error
      if error.is_a?(Encoding::UndefinedConversionError) ||
         error.message.include?('invalid byte sequence')
        raise FileEncodingError,
              "Unable to parse SCSS file: #{error.to_s}",
              error.backtrace
      else
        raise
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
scss-lint-0.20.3 lib/scss_lint/engine.rb
scss-lint-0.20.2 lib/scss_lint/engine.rb
scss-lint-0.20.1 lib/scss_lint/engine.rb
scss-lint-0.20.0 lib/scss_lint/engine.rb
scss-lint-0.19.0 lib/scss_lint/engine.rb
scss-lint-0.18.0 lib/scss_lint/engine.rb
scss-lint-0.17.3 lib/scss_lint/engine.rb
scss-lint-0.17.2 lib/scss_lint/engine.rb
scss-lint-0.17.1 lib/scss_lint/engine.rb
scss-lint-0.17.0 lib/scss_lint/engine.rb