1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/renderers/sass.rb

67 lines
2.5 KiB
Ruby
Raw Normal View History

require "sass"
2009-10-26 18:42:06 -04:00
require "compass"
class Middleman::Base
def scss(template, options={}, locals={})
options[:layout] = false
render :scss, template, options, locals
end
2010-01-20 18:22:40 -05:00
after_feature_init do
2009-10-26 18:42:06 -04:00
::Compass.configuration do |config|
config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
2009-10-29 12:43:08 -04:00
config.project_path = self.root
config.sass_dir = File.join(File.basename(self.views), self.css_dir)
config.output_style = :nested
2009-11-30 14:32:02 -05:00
config.fonts_dir = File.join(File.basename(self.public), self.fonts_dir)
2009-10-29 12:43:08 -04:00
config.css_dir = File.join(File.basename(self.public), self.css_dir)
config.images_dir = File.join(File.basename(self.public), self.images_dir)
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)
2009-10-29 12:43:08 -04:00
config.asset_cache_buster { false }
config.add_import_path(config.sass_dir)
2009-10-26 18:42:06 -04:00
end
2010-03-22 23:48:06 -04:00
configure :build do
::Compass.configuration do |config|
2010-03-22 23:48:06 -04:00
config.css_dir = File.join(File.basename(self.build_dir), self.css_dir)
config.images_dir = File.join(File.basename(self.build_dir), self.images_dir)
end
end
end
end
class Tilt::SassPlusCSSFilenameTemplate < Tilt::SassTemplate
def sass_options
location_of_sass_file = Middleman::Base.environment == "build" ?
File.join(Middleman::Base.root, Middleman::Base.build_dir) :
Middleman::Base.public
parts = basename.split('.')
parts.pop
css_filename = File.join(location_of_sass_file, Middleman::Base.css_dir, parts.join("."))
super.merge(::Compass.configuration.to_sass_engine_options).merge(:css_filename => css_filename)
end
end
Tilt.register 'sass', Tilt::SassPlusCSSFilenameTemplate
Middleman::Renderers.register(:sass, Tilt::SassPlusCSSFilenameTemplate)
class Tilt::ScssPlusCSSFilenameTemplate < Tilt::SassPlusCSSFilenameTemplate
def sass_options
super.merge(:syntax => :scss)
end
end
Tilt.register 'scss', Tilt::ScssPlusCSSFilenameTemplate
Middleman::Renderers.register(:scss, Tilt::ScssPlusCSSFilenameTemplate)
module Middleman::Haml
module Sass
include ::Haml::Filters::Base
def render(text)
::Sass::Engine.new(text, ::Compass.configuration.to_sass_engine_options).render
end
2009-10-26 18:42:06 -04:00
end
end