2009-10-22 20:25:15 -04:00
|
|
|
require "sass"
|
2011-05-22 17:08:33 -04:00
|
|
|
require "sass/plugin"
|
2009-10-26 18:42:06 -04:00
|
|
|
require "compass"
|
2011-06-12 14:45:11 -04:00
|
|
|
require "susy"
|
2009-10-22 20:25:15 -04:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
module Middleman
|
|
|
|
module Renderers
|
|
|
|
module Sass
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
|
|
|
app.after_feature_init do
|
2011-06-24 15:06:28 -04:00
|
|
|
views_root = File.basename(self.views)
|
2010-09-06 21:48:25 -04:00
|
|
|
::Compass.configuration do |config|
|
|
|
|
config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
|
|
|
|
config.project_path = self.root
|
2011-06-24 15:06:28 -04:00
|
|
|
config.sass_dir = File.join(views_root, self.css_dir)
|
2010-09-06 21:48:25 -04:00
|
|
|
config.output_style = :nested
|
2011-06-24 15:06:28 -04:00
|
|
|
config.fonts_dir = File.join(views_root, self.fonts_dir)
|
|
|
|
config.css_dir = File.join(views_root, self.css_dir)
|
|
|
|
config.images_dir = File.join(views_root, self.images_dir)
|
2010-09-06 21:48:25 -04:00
|
|
|
config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
|
|
|
|
config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
|
2011-06-24 15:06:28 -04:00
|
|
|
config.asset_cache_buster :none
|
2010-01-20 18:22:40 -05:00
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
config.add_import_path(config.sass_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
configure :build do
|
2011-06-24 15:06:28 -04:00
|
|
|
build_root = File.basename(self.build_dir)
|
2010-09-06 21:48:25 -04:00
|
|
|
::Compass.configuration do |config|
|
2011-06-24 15:06:28 -04:00
|
|
|
config.css_dir = File.join(build_root, self.css_dir)
|
|
|
|
config.images_dir = File.join(build_root, self.images_dir)
|
2010-09-06 21:48:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
alias :included :registered
|
2009-10-27 21:13:19 -04:00
|
|
|
end
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
|
|
|
|
def sass_options
|
2011-05-12 15:18:17 -04:00
|
|
|
return super if basename.nil?
|
|
|
|
|
2010-09-05 22:28:38 -04:00
|
|
|
location_of_sass_file = Middleman::Server.environment == :build ?
|
|
|
|
File.join(Middleman::Server.root, Middleman::Server.build_dir) :
|
2011-05-31 18:12:36 -04:00
|
|
|
Middleman::Server.views
|
2010-09-04 23:26:48 -04:00
|
|
|
|
|
|
|
parts = basename.split('.')
|
|
|
|
parts.pop
|
2010-09-05 22:28:38 -04:00
|
|
|
css_filename = File.join(location_of_sass_file, Middleman::Server.css_dir, parts.join("."))
|
2010-09-04 23:26:48 -04:00
|
|
|
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
|
|
|
|
end
|
2011-04-29 15:24:40 -04:00
|
|
|
|
|
|
|
def evaluate(scope, locals, &block)
|
|
|
|
begin
|
|
|
|
super
|
|
|
|
rescue Sass::SyntaxError => e
|
|
|
|
Sass::SyntaxError.exception_to_css(e, :full_exception => true)
|
|
|
|
end
|
|
|
|
end
|
2010-09-04 23:26:48 -04:00
|
|
|
end
|
|
|
|
Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
|
|
|
|
|
|
|
|
class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
|
|
|
|
def sass_options
|
|
|
|
super.merge(:syntax => :scss)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
|
|
|
|
|
|
|
|
|
2010-09-06 21:48:25 -04:00
|
|
|
module Middleman::Renderers::Haml
|
2010-09-04 23:26:48 -04:00
|
|
|
module Sass
|
|
|
|
include ::Haml::Filters::Base
|
|
|
|
|
|
|
|
def render(text)
|
|
|
|
::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
|
2009-10-27 21:13:19 -04:00
|
|
|
end
|
2009-10-26 18:42:06 -04:00
|
|
|
end
|
2009-10-22 20:25:15 -04:00
|
|
|
end
|