Sha256: c38f16f7afac82ecbf102211d081b1266add49b4a5a627b44e4478fff96f3e48

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require "sassc"
require "roger/release"

require "fileutils"
require "pathname"

module RogerSassc
  # The Roger Processor for LibSass
  class Processor < ::Roger::Release::Processors::Base
    def initialize(options = {})
      @options = {
        match: ["stylesheets/**/*.scss"],
        skip: [%r{/_.*\.scss\Z}],
        load_paths: RogerSassc.load_paths
      }.update(options)
    end

    # @option options [Hash]
    #   :build_files
    def call(release, options = {})
      @release = release
      @options = @options.update(options)

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

      @options[:load_paths] = @options[:load_paths].map do |path|
        build_path + path
      end

      # 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

    def clean_files(files)
      files.each { |f| File.unlink(f) }
    end

    def build_path
      @release.project.path
    end

    def compile_file(path)
      scss = File.read(path)

      File.open(path.gsub(/\.scss$/, ".css"), "w+") do |file|
        file.write(SassC::Engine.new(scss, @options).render)
      end
    end
  end
end

Roger::Release::Processors.register(:sassc, RogerSassc::Processor)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roger_sassc-0.1.1 lib/roger_sassc/processor.rb