diff --git a/CHANGELOG b/CHANGELOG index e4153f05..766aad42 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,4 +7,6 @@ - Refactored Dynamically Reloadable Core - Combine views/ and public/ into a single source/ folder. - Support YAML front-matter +- Added callback to run code after Compass is configured +- Added support for a compass.config file which is passed directly to Compass - Blog-aware Feature \ No newline at end of file diff --git a/features/builder.feature b/features/builder.feature index 0d845fd4..186703f5 100644 --- a/features/builder.feature +++ b/features/builder.feature @@ -19,5 +19,5 @@ Feature: Builder Scenario: Force relative assets Given a built test app with flags "--relative" - Then "stylesheets/site.css" should exist and include "../" + Then "stylesheets/relative_assets.css" should exist and include "../" And cleanup built test app \ No newline at end of file diff --git a/lib/middleman/core_extensions/compass.rb b/lib/middleman/core_extensions/compass.rb index f92d01a4..ad753a20 100644 --- a/lib/middleman/core_extensions/compass.rb +++ b/lib/middleman/core_extensions/compass.rb @@ -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 \ No newline at end of file diff --git a/lib/middleman/features/asset_host.rb b/lib/middleman/features/asset_host.rb index c6f53e8f..3c1b58e5 100644 --- a/lib/middleman/features/asset_host.rb +++ b/lib/middleman/features/asset_host.rb @@ -1,9 +1,9 @@ module Middleman::Features::AssetHost class << self def registered(app) - app.after_compass_init do + app.compass_config do |config| if app.asset_host.is_a?(Proc) - ::Compass.configuration.asset_host(&app.asset_host) + config.asset_host(&app.asset_host) end end diff --git a/lib/middleman/features/cache_buster.rb b/lib/middleman/features/cache_buster.rb index 921d5220..f9cffd3f 100755 --- a/lib/middleman/features/cache_buster.rb +++ b/lib/middleman/features/cache_buster.rb @@ -25,16 +25,14 @@ module Middleman::Features::CacheBuster end end - app.after_compass_init do - ::Compass.configuration do |config| - config.asset_cache_buster do |path, real_path| - real_path = real_path.path if real_path.is_a? File - real_path = real_path.gsub(File.join(app.root, app.build_dir), app.views) - if File.readable?(real_path) - File.mtime(real_path).strftime("%s") - else - $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}" - end + app.compass_config do |config| + config.asset_cache_buster do |path, real_path| + real_path = real_path.path if real_path.is_a? File + real_path = real_path.gsub(File.join(app.root, app.build_dir), app.views) + if File.readable?(real_path) + File.mtime(real_path).strftime("%s") + else + $stderr.puts "WARNING: '#{File.basename(path)}' was not found (or cannot be read) in #{File.dirname(real_path)}" end end end diff --git a/lib/middleman/features/minify_css.rb b/lib/middleman/features/minify_css.rb index 2756b514..0eac1acc 100644 --- a/lib/middleman/features/minify_css.rb +++ b/lib/middleman/features/minify_css.rb @@ -1,8 +1,8 @@ module Middleman::Features::MinifyCss class << self def registered(app) - app.after_compass_init do - ::Compass.configuration.output_style = :compressed + app.compass_config do |config| + config.output_style = :compressed end end alias :included :registered diff --git a/lib/middleman/templates/default/config.tt b/lib/middleman/templates/default/config.tt index d60082ff..ef3804aa 100755 --- a/lib/middleman/templates/default/config.tt +++ b/lib/middleman/templates/default/config.tt @@ -52,6 +52,11 @@ set :images_dir, "<%= options[:images_dir] -%>" # set :images_dir, "alternative_image_directory" <% end -%> +# Change Compass configuration +# compass_config do |config| +# config.output_style = :compact +# end + # Build-specific configuration configure :build do # For example, change the Compass output style for deployment