class RogerSassc::Processor

The Roger Processor for LibSass

Public Class Methods

new(options = {}) click to toggle source
# File lib/roger_sassc/processor.rb, line 10
def initialize(options = {})
  @options = {
    match: ["stylesheets/**/*.scss"],
    skip: [%r{/_.*\.scss\Z}],
    load_paths: RogerSassc.load_paths
  }.update(options)
end

Public Instance Methods

call(release, options = {}) click to toggle source

@option options [Hash]

:build_files
# File lib/roger_sassc/processor.rb, line 20
def call(release, options = {})
  @options = @options.update(options)
  @options[:roger_html_path] = release.build_path

  match = @options.delete(:match)
  skip = @options.delete(:skip)

  # Sassify SCSS files
  files = release.get_files(match)

  files.each do |f|
    # Doing skip by hand, so that we can clean the skipped ones
    next if skip.detect { |r| r.match(f) }

    release.log(self, "Processing: #{f}")
    # Compile SCSS
    compile_file(f)
  end

  # Remove source file
  clean_files(files)
end

Private Instance Methods

clean_files(files) click to toggle source
# File lib/roger_sassc/processor.rb, line 45
def clean_files(files)
  files.each { |f| File.unlink(f) }
end
compile_file(path) click to toggle source
# File lib/roger_sassc/processor.rb, line 49
def compile_file(path)
  @options[:filename] = path.to_s
  if @options[:source_map]
    @options[:source_map_file] = path.gsub(/\.scss$/, ".css.map")
    @options[:source_map_contents] = true
  end

  scss = File.read(path)
  engine = ::SassC::Engine.new(scss, @options)

  File.write(path.gsub(/\.scss$/, ".css"), engine.render)
  File.write(path.gsub(/\.scss$/, ".css.map"), engine.source_map) if @options[:source_map]
end