Skip to content

Commit

Permalink
Moved Sass compilation into it's own class
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencepit authored and Erich Ocean committed Sep 30, 2008
1 parent 0f4d7d4 commit 2ae0b82
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
5 changes: 3 additions & 2 deletions lib/sproutcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def self.logger=(new_logger); @logger = new_logger; end
%w(library bundle bundle_manifest bundle_installer jsdoc jsmin cssmin version).each do |fname|
require "sproutcore/#{fname}"
end
require "sproutcore/renderers/erubis"
require "sproutcore/renderers/haml"
%w(erubis haml sass).each do |fname|
require "sproutcore/renderers/#{fname}"
end

SC= SproutCore
40 changes: 1 addition & 39 deletions lib/sproutcore/build_tools/resource_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _build_one(filename, lines, required, link_only = false)
elsif file_lines.size > 0

if entry.ext == "sass"
file_lines = [ compile_sass(entry, file_lines.join()) ]
file_lines = [ SproutCore::Renderers::Sass.compile(entry, file_lines.join()) ]
end

lines << "/* Start ----------------------------------------------------- " << filename << "*/\n\n"
Expand Down Expand Up @@ -138,44 +138,6 @@ def _require_for(filename,line)
def filename_for_require(ret)
filenames.include?("#{ret}.css") ? "#{ret}.css" : "#{ret}.sass"
end

private

def compile_sass(entry, content)
require 'sass'
begin
Sass::Engine.new(content).render
rescue Exception => e
e_string = "#{e.class}: #{e.message}"
if e.is_a? Sass::SyntaxError
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
end
end
<<END
/*
#{e_string}
Backtrace:\n#{e.backtrace.join("\n")}
*/
body:before {
white-space: pre;
font-family: monospace;
content: "#{e_string.gsub('"', '\"').gsub("\n", '\\A ')}"; }
END
end
end



end

class JavaScriptResourceBuilder < ResourceBuilder
Expand Down
42 changes: 42 additions & 0 deletions lib/sproutcore/renderers/sass.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module SproutCore
module Renderers

class Sass

def self.compile(entry, content)
require 'sass'
begin
::Sass::Engine.new(content).render
rescue Exception => e
e_string = "#{e.class}: #{e.message}"
if e.is_a? Sass::SyntaxError
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
end
end
<<END
/*
#{e_string}
Backtrace:\n#{e.backtrace.join("\n")}
*/
body:before {
white-space: pre;
font-family: monospace;
content: "#{e_string.gsub('"', '\"').gsub("\n", '\\A ')}"; }
END
end
end

end

end
end

0 comments on commit 2ae0b82

Please sign in to comment.