2011-07-10 18:10:49 -04:00
|
|
|
module Middleman::CoreExtensions::Compass
|
|
|
|
class << self
|
|
|
|
def registered(app)
|
|
|
|
app.extend ClassMethods
|
|
|
|
|
|
|
|
require "compass"
|
|
|
|
|
|
|
|
# Susy grids
|
|
|
|
begin
|
|
|
|
require "susy"
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
app.after_feature_init do
|
2011-07-25 23:10:07 -04:00
|
|
|
# Support a stand-alone compass config file
|
|
|
|
# Many options are overwritten by Middleman, but the config is a good
|
|
|
|
# place to add:
|
|
|
|
# * output_style
|
|
|
|
# * disable_warnings
|
|
|
|
# * sass_options
|
|
|
|
# * line_comments
|
|
|
|
# * sprite_engine
|
|
|
|
# * chunky_png_options
|
|
|
|
compass_config_file = File.join(app.root, "compass.config")
|
|
|
|
if File.exists?(compass_config_file)
|
|
|
|
::Compass.add_project_configuration(compass_config_file)
|
|
|
|
end
|
|
|
|
|
2011-07-10 18:10:49 -04:00
|
|
|
::Compass.configuration do |config|
|
|
|
|
config.project_path = app.root
|
2011-07-25 23:10:07 -04:00
|
|
|
config.environment = :development
|
|
|
|
config.cache_path = File.join(app.root, ".sass-cache")
|
|
|
|
|
|
|
|
views_root = File.basename(app.views)
|
2011-07-10 18:10:49 -04:00
|
|
|
config.sass_dir = File.join(views_root, app.css_dir)
|
|
|
|
config.css_dir = File.join(views_root, app.css_dir)
|
2011-07-25 23:10:07 -04:00
|
|
|
config.javascripts_dir = File.join(views_root, app.js_dir)
|
|
|
|
config.fonts_dir = File.join(views_root, app.fonts_dir)
|
|
|
|
config.images_dir = File.join(views_root, app.images_dir)
|
|
|
|
|
|
|
|
if app.respond_to? :http_images_path
|
|
|
|
config.http_images_path = app.http_images_path
|
|
|
|
end
|
|
|
|
|
|
|
|
if app.respond_to? :http_css_path
|
|
|
|
config.http_stylesheets_path = app.http_css_path
|
|
|
|
end
|
|
|
|
|
|
|
|
if app.respond_to? :http_js_path
|
|
|
|
config.http_javascripts_path = app.http_js_path
|
|
|
|
end
|
|
|
|
|
2011-07-10 18:10:49 -04:00
|
|
|
config.asset_cache_buster :none
|
2011-07-25 23:10:07 -04:00
|
|
|
config.output_style = :nested
|
2011-07-10 18:10:49 -04:00
|
|
|
|
|
|
|
config.add_import_path(config.sass_dir)
|
|
|
|
end
|
2011-07-13 14:41:59 -04:00
|
|
|
|
|
|
|
# Required for relative paths
|
|
|
|
configure :build do
|
2011-07-25 23:10:07 -04:00
|
|
|
::Compass.configuration do |config|
|
|
|
|
config.environment = :production
|
|
|
|
|
|
|
|
build_root = File.basename(self.build_dir)
|
|
|
|
config.css_dir = File.join(build_root, self.css_dir)
|
|
|
|
config.images_dir = File.join(build_root, self.images_dir)
|
|
|
|
end
|
|
|
|
end
|
2011-07-10 18:10:49 -04:00
|
|
|
|
|
|
|
app.execute_after_compass_init!
|
|
|
|
|
|
|
|
app.set :sass, ::Compass.configuration.to_sass_engine_options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
alias :included :registered
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
# Add a block/proc to be run after features have been setup
|
2011-07-25 23:10:07 -04:00
|
|
|
def compass_config(&block)
|
2011-07-10 18:10:49 -04:00
|
|
|
@run_after_compass ||= []
|
|
|
|
@run_after_compass << block
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute_after_compass_init!
|
|
|
|
@run_after_compass ||= []
|
2011-07-25 23:10:07 -04:00
|
|
|
@run_after_compass.each { |block| block.call(::Compass.configuration) }
|
2011-07-10 18:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|