Class: Compass::SassCompiler

### Home Classes Methods

### In Files

- lib/compass/sass_compiler.rb

### Parent

Object

### Methods

- ::new
- #clean!
- #compile!
- #corresponding_css_file
- #file_list
- #individual_files
- #logger
- #sass_files
- #stylesheet_name
- #watch!
- #when_compilation_error
- #when_compilation_starting
- #when_creating_directory
- #when_deleting_css
- #when_deleting_sourcemap
- #when_template_created
- #when_template_deleted
- #when_template_modified
- #when_updated_stylesheet
- #when_updating_stylesheets

### Included Modules

- Compass::Actions

### Class/Module Index

Quicksearch

- Compass
- Compass::Actions
- Compass::AppIntegration
- Compass::AppIntegration::Helpers
- Compass::AppIntegration::StandAlone
- Compass::AppIntegration::StandAlone::ConfigurationDefaults
- Compass::AppIntegration::StandAlone::Installer
- Compass::Commands
- Compass::Commands::Base
- Compass::Commands::CleanProject
- Compass::Commands::CleanProjectOptionsParser
- Compass::Commands::CompileProjectOptionsParser
- Compass::Commands::ConfigurationOptionsParser
- Compass::Commands::CreateProject
- Compass::Commands::CreateProjectOptionsParser
- Compass::Commands::Default
- Compass::Commands::DefaultOptionsParser
- Compass::Commands::ExtensionCommand
- Compass::Commands::ExtensionOptionsParser
- Compass::Commands::ExtensionsOptionParser
- Compass::Commands::Help
- Compass::Commands::HelpOptionsParser
- Compass::Commands::Imports
- Compass::Commands::InstallerCommand
- Compass::Commands::Interactive
- Compass::Commands::InteractiveOptionsParser
- Compass::Commands::ListFrameworks
- Compass::Commands::PrintVersion
- Compass::Commands::ProjectBase
- Compass::Commands::ProjectStats
- Compass::Commands::Registry
- Compass::Commands::Sprite
- Compass::Commands::SpriteOptionsParser
- Compass::Commands::StampPattern
- Compass::Commands::StampPatternOptionsParser
- Compass::Commands::StatsOptionsParser
- Compass::Commands::StructureOptionsParser
- Compass::Commands::UnpackExtension
- Compass::Commands::UpdateProject
- Compass::Commands::ValidateProject
- Compass::Commands::ValidationOptionsParser
- Compass::Commands::VersionOptionsParser
- Compass::Commands::WriteConfiguration
- Compass::Compiler
- Compass::Configuration
- Compass::Configuration::Comments
- Compass::Configuration::Data
- Compass::Configuration::FileData
- Compass::Configuration::Helpers
- Compass::Configuration::Serialization
- Compass::Deprecation
- Compass::Exec
- Compass::Exec::CommandOptionParser
- Compass::Exec::GlobalOptionsParser
- Compass::Exec::Helpers
- Compass::Exec::ProjectOptionsParser
- Compass::Exec::SubCommandUI
- Compass::FilesystemConflict
- Compass::Installers
- Compass::Installers::BareInstaller
- Compass::Installers::Base
- Compass::Installers::Manifest
- Compass::Installers::Manifest::Entry
- Compass::Installers::ManifestInstaller
- Compass::Installers::TemplateContext
- Compass::Logger
- Compass::MissingDependency
- Compass::NullLogger
- Compass::SassCompiler
- Compass::SassExtensions
- Compass::SassExtensions::Functions
- Compass::SassExtensions::Functions::SassDeclarationHelper
- Compass::SassExtensions::Functions::Sprites
- Compass::SassExtensions::Functions::Sprites::VariableReader
- Compass::SassExtensions::Sprites
- Compass::SassExtensions::Sprites::ChunkyPngEngine
- Compass::SassExtensions::Sprites::Engine
- Compass::SassExtensions::Sprites::Image
- Compass::SassExtensions::Sprites::ImageMethods
- Compass::SassExtensions::Sprites::ImageRow
- Compass::SassExtensions::Sprites::Images
- Compass::SassExtensions::Sprites::Layout
- Compass::SassExtensions::Sprites::Layout::Diagonal
- Compass::SassExtensions::Sprites::Layout::Horizontal
- Compass::SassExtensions::Sprites::Layout::Smart
- Compass::SassExtensions::Sprites::Layout::SpriteLayout
- Compass::SassExtensions::Sprites::Layout::Vertical
- Compass::SassExtensions::Sprites::LayoutMethods
- Compass::SassExtensions::Sprites::RowFitter
- Compass::SassExtensions::Sprites::SpriteMap
- Compass::SassExtensions::Sprites::SpriteMethods
- Compass::SpriteException
- Compass::SpriteImporter
- Compass::Sprites
- Compass::Sprites::Binding
- Compass::Stats
- Compass::Stats::CssFile
- Compass::Stats::SassFile
- Compass::Stats::StatsVisitor
- Compass::TestCase
- Compass::Version
- Sass
- Sass::Script
- Sass::Script::Functions
- QuickCache

No matching classes.

# Compass::SassCompiler

### Attributes

config[RW]
display_compilation_times[RW]
error_count[R]
logger[W]
only_sass_files[RW]
quiet[R]
working_path[RW]

### Public Class Methods

new(options = {}, config = Compass.configuration) click to toggle source

    # File lib/compass/sass_compiler.rb, line 15
    def initialize(options = {}, config = Compass.configuration)
      options = options.dup
      self.config = config
      self.display_compilation_times = options.delete(:time)
      self.working_path = options.delete(:working_path) || Dir.pwd
      self.only_sass_files = options.delete(:only_sass_files) || []
      @quiet = options[:quiet]
      plugin_options = config.to_sass_plugin_options.merge(options)
      if only_sass_files.any?
        plugin_options[:template_location] = []
        plugin_options[:load_paths] = config.sass_load_paths
      end
      plugin_options[:always_update] = true if options.delete(:force)
      plugin_options[:compass] ||= {}
      plugin_options[:compass][:logger] = logger
      @compiler = Sass::Plugin::Compiler.new(plugin_options)
      @start_times = {}
      @error_count = 0

      public_methods(true).grep(/^when_/).each do |callback|
        @compiler.send(callback.to_s.sub(/^when_/, 'on_')) {|*args| send(callback, *args) }
      end
    end

### Public Instance Methods

clean!() click to toggle source

    # File lib/compass/sass_compiler.rb, line 57
    def clean!
      @compiler.clean(individual_files)
    end

compile!() click to toggle source

    # File lib/compass/sass_compiler.rb, line 39
    def compile!
      @compiler.update_stylesheets(individual_files)
    end

corresponding_css_file(sass_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 132
    def corresponding_css_file(sass_file)
      "#{config.css_path}/#{stylesheet_name(sass_file)}.css"
    end

file_list() click to toggle source

    # File lib/compass/sass_compiler.rb, line 61
    def file_list
      @compiler.file_list(individual_files)
    end

individual_files() click to toggle source

    # File lib/compass/sass_compiler.rb, line 53
    def individual_files
      only_sass_files.map {|sass_file| [sass_file, corresponding_css_file(sass_file)]}
    end

logger() click to toggle source

    # File lib/compass/sass_compiler.rb, line 128
    def logger
      @logger ||= Compass::Logger.new(:quiet => quiet)
    end

sass_files(options = {}) click to toggle source

    # File lib/compass/sass_compiler.rb, line 144
    def sass_files(options = {})
      @compiler.template_location_array.map do |(sass_dir, css_dir)|
        glob = options[:include_partials] ?
                 File.join("**","*.s[ac]ss*") :
                 File.join("**","[^_]*.s[ac]ss*")
        Dir.glob(File.join(sass_dir, glob))
      end.flatten
    end

stylesheet_name(sass_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 136
    def stylesheet_name(sass_file)
      if sass_file.index(config.sass_path) == 0
        sass_file[(config.sass_path.length + 1)..-6].sub(/\.css$/,'')
      else
        raise Compass::Error, "Individual stylesheets must be in the sass directory."
      end
    end

watch!(options = {}, &block) click to toggle source

    # File lib/compass/sass_compiler.rb, line 43
    def watch!(options = {}, &block)
      skip_initial_update = options.fetch(:skip_initial_update, false)
      begin
        @compiler.watch(individual_files, options.merge(:skip_initial_update => skip_initial_update), &block)
      rescue Sass::SyntaxError => e
        skip_initial_update = true
        retry
      end
    end

when_compilation_error(error, sass_file, css_file, sourcemap_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 113
    def when_compilation_error(error, sass_file, css_file, sourcemap_file)
      @error_count += 1
      if error.respond_to?(:sass_filename)
        error_filename = error.sass_filename || sass_file
        if relativize(error_filename) == relativize(sass_file)
          logger.record :error, "#{relativize(sass_file)} (Line #{error.sass_line}: #{error.message})"
        else
          logger.record :error, "#{relativize(sass_file)} (Line #{error.sass_line} of #{relativize(error_filename)}: #{error.message})"
        end
      else
        logger.record :error, "#{relativize(sass_file)} (#{error.backtrace.first}: #{error.message})"
      end
      config.run_stylesheet_error(sass_file, error.message)
    end

when_compilation_starting(sass_file, css, sourcemap) click to toggle source

    # File lib/compass/sass_compiler.rb, line 70
    def when_compilation_starting(sass_file, css, sourcemap)
      @start_times[sass_file] = Time.now
    end

when_creating_directory(dirname) click to toggle source

    # File lib/compass/sass_compiler.rb, line 99
    def when_creating_directory(dirname)
      logger.record :directory, relativize(dirname)
    end

when_deleting_css(filename) click to toggle source

    # File lib/compass/sass_compiler.rb, line 103
    def when_deleting_css(filename)
      logger.record :delete, relativize(filename)
      config.run_stylesheet_removed(filename) if filename
    end

when_deleting_sourcemap(filename) click to toggle source

    # File lib/compass/sass_compiler.rb, line 108
    def when_deleting_sourcemap(filename)
      logger.record :delete, relativize(filename)
      config.run_sourcemap_removed(filename) if filename
    end

when_template_created(sass_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 74
    def when_template_created(sass_file)
      logger.record :created, relativize(sass_file)
    end

when_template_deleted(sass_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 78
    def when_template_deleted(sass_file)
      logger.record :deleted, relativize(sass_file)
    end

when_template_modified(sass_file) click to toggle source

    # File lib/compass/sass_compiler.rb, line 82
    def when_template_modified(sass_file)
      logger.record :modified, relativize(sass_file)
    end

when_updated_stylesheet(sass_file, css, sourcemap) click to toggle source

    # File lib/compass/sass_compiler.rb, line 86
    def when_updated_stylesheet(sass_file, css, sourcemap)
      if css && display_compilation_times && @start_times[sass_file]
        duration = ((Time.now - @start_times[sass_file]) * 1000).round / 1000.0
        logger.record :write, "#{relativize(css)} (#{duration}s)"
      else
        logger.record :write, relativize(css) if css
      end
      config.run_stylesheet_saved(css) if css

      logger.record :write, relativize(sourcemap) if sourcemap
      config.run_sourcemap_saved(sourcemap) if sourcemap
    end

when_updating_stylesheets(individual_files) click to toggle source

    # File lib/compass/sass_compiler.rb, line 65
    def when_updating_stylesheets(individual_files)
      @start_times = {}
      @error_count = 0
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.