Sha256: 89dde358cb0f8bc1c70fd8a30cce65ff713c88da544815343f270f1ecbbcc305

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

# ===========================================================================
# Project:   Abbot - SproutCore Build Tools
# Copyright: ©2009 Apple, Inc.
#            portions copyright @2006-2009 Sprout Systems, Inc.
#            and contributors
# ===========================================================================

require File.expand_path(File.join(File.dirname(__FILE__), 'base'))
require 'fileutils'

module SC

  # This build can compile a Sass stylesheet.  At this point it does no
  # further processing than simply executing the Sass.  It would be nice to 
  # add support for sc_static and other directives at some point.
  #
  class Builder::Sass < Builder::Base
    
    def build(dst_path)
      begin
        require 'sass'
      rescue
        raise "Cannot compile #{entry.source_path} because sass is not installed.  Please try 'sudo gem install haml' and try again"
      end

      begin
        content = readlines(entry.source_path)*''
        content = ::Sass::Engine.new(content).render
        writelines dst_path, [content]
      rescue Exception => e
        
        # explain sass syntax error a bit more...
        if e.is_a? Sass::SyntaxError
          e_string = "#{e.class}: #{e.message}"
          e_string << "\non line #{e.sass_line}"
          e_string << " of #{@entry.source_path}"
          if File.exists?(@entry.source_path)
            e_string << "\n\n"
            min = [e.sass_line - 5, 0].max
            File.read(@entry.source_path).rstrip.split("\n")[
              min .. e.sass_line + 5
            ].each_with_index do |line, i|
              e_string << "#{min + i + 1}: #{line}\n"
            end # File.read
          end # if File.exists?
          raise e_string
        else
          raise e # reraise
        end 
      end # rescue
    end # def
    
  end
  
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sproutit-sproutcore-1.0.0.20090407205609 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.0.20090408130025 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.0.20090416161445 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.0.20090720093355 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.0.20090720202429 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.0.20090721125122 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.126 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.20090721145236 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.20090721145251 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.20090721145280 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.20090721145281 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.20090721145282 lib/sproutcore/builders/sass.rb
sproutit-sproutcore-1.0.203 lib/sproutcore/builders/sass.rb