Sha256: 48399dff11a939e12b43d481a36eab2dd6643975c379afff498efb7c265712e9

Contents?: true

Size: 1.79 KB

Versions: 17

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

17 entries across 17 versions & 2 rubygems

Version Path
sproutit-sproutcore-1.0.20090721145285 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1046 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1043 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1042 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1037 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1035 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1031 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1030 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1029 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1027 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1028 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1026 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1025 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1024 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1009 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1008 lib/sproutcore/builders/sass.rb
sproutcore-1.0.1003 lib/sproutcore/builders/sass.rb