Simplify compass config with extra file or new callback
This commit is contained in:
parent
d3cb8808ae
commit
2c3523b94a
7 changed files with 65 additions and 31 deletions
|
@ -12,31 +12,60 @@ module Middleman::CoreExtensions::Compass
|
|||
end
|
||||
|
||||
app.after_feature_init do
|
||||
views_root = File.basename(app.views)
|
||||
# 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
|
||||
|
||||
::Compass.configuration do |config|
|
||||
# config.cache = false # For sassc files
|
||||
config.cache_path = File.join(app.root, ".sass-cache")
|
||||
config.project_path = app.root
|
||||
config.environment = :development
|
||||
config.cache_path = File.join(app.root, ".sass-cache")
|
||||
|
||||
views_root = File.basename(app.views)
|
||||
config.sass_dir = File.join(views_root, app.css_dir)
|
||||
config.output_style = :nested
|
||||
config.fonts_dir = File.join(views_root, app.fonts_dir)
|
||||
config.css_dir = File.join(views_root, app.css_dir)
|
||||
config.images_dir = File.join(views_root, app.images_dir)
|
||||
config.http_images_path = app.http_images_path rescue File.join(app.http_prefix || "/", app.images_dir)
|
||||
config.http_stylesheets_path = app.http_css_path rescue File.join(app.http_prefix || "/", app.css_dir)
|
||||
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
|
||||
|
||||
config.asset_cache_buster :none
|
||||
config.output_style = :nested
|
||||
|
||||
config.add_import_path(config.sass_dir)
|
||||
end
|
||||
|
||||
# Required for relative paths
|
||||
configure :build do
|
||||
build_root = File.basename(self.build_dir)
|
||||
::Compass.configuration do |config|
|
||||
config.css_dir = File.join(build_root, self.css_dir)
|
||||
config.images_dir = File.join(build_root, self.images_dir)
|
||||
end
|
||||
end
|
||||
::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
|
||||
|
||||
app.execute_after_compass_init!
|
||||
|
||||
|
@ -48,14 +77,14 @@ module Middleman::CoreExtensions::Compass
|
|||
|
||||
module ClassMethods
|
||||
# Add a block/proc to be run after features have been setup
|
||||
def after_compass_init(&block)
|
||||
def compass_config(&block)
|
||||
@run_after_compass ||= []
|
||||
@run_after_compass << block
|
||||
end
|
||||
|
||||
def execute_after_compass_init!
|
||||
@run_after_compass ||= []
|
||||
@run_after_compass.each { |block| class_eval(&block) }
|
||||
@run_after_compass.each { |block| block.call(::Compass.configuration) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue