From 1de1d3d25ef7ea236fb54000455778c3fc0a76a5 Mon Sep 17 00:00:00 2001 From: kematzy Date: Mon, 16 Jul 2012 14:34:36 +0800 Subject: [PATCH 1/3] Added :sass_cache_path custom config of SASS cache directory The default output of SASS .sass_cache directory is in the Middleman app root directory, which to my mind adds clutter to the directory. Secondly, when storing Middleman apps in a Dropbox subfolder, the .sass_cache directory gets synced unnecessarily. This fix enables moving the .sass_cache directory to any path on the system, such as the "/tmp" directory for automatic discarding of files when restarting the system. Suggested usage: #in config.rb set :sass_cache_path, File.join('/tmp', "middleman-#{File.basename(Dir.pwd)}", "sass_cache") which could return something like: `/tmp/middleman-example.com/sass_cache` This keeps multiple projects separated and easily identifiable. --- middleman-core/lib/middleman-core/application.rb | 5 +++++ middleman-more/lib/middleman-more/core_extensions/compass.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 093edc13..383be6f8 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -101,6 +101,11 @@ module Middleman # @return [String] set :css_dir, "stylesheets" + # Location of SASS .sass_cache directory. + # @return [String] + # set :sass_cache_path, "/tmp/middleman-app-name/sass_cache" + set(:sass_cache_path) { File.join(root_path, '.sass_cache') } # runtime compile of path + # Location of images within source. Used by HTML helpers and Compass. # @return [String] set :images_dir, "images" diff --git a/middleman-more/lib/middleman-more/core_extensions/compass.rb b/middleman-more/lib/middleman-more/core_extensions/compass.rb index 7c488bc5..2735fb08 100644 --- a/middleman-more/lib/middleman-more/core_extensions/compass.rb +++ b/middleman-more/lib/middleman-more/core_extensions/compass.rb @@ -21,7 +21,7 @@ module Middleman ::Compass.configuration do |config| config.project_path = source_dir config.environment = :development - config.cache_path = File.join(root, ".sass-cache") + config.cache_path = sass_cache_path config.sass_dir = css_dir config.css_dir = css_dir config.javascripts_dir = js_dir From c00f9d57826b13ab27560799b1c1aa0b37a6848c Mon Sep 17 00:00:00 2001 From: kematzy Date: Mon, 16 Jul 2012 14:39:26 +0800 Subject: [PATCH 2/3] Tests for :sass_cache_path custom config First time working with Cucumber, so perhaps not the best way to do things. * Tests for default setting which stores the .sass_cache directory in Middleman app root. * Tests for custom setting which stores the .sass_cache directory in /tmp directory. Please Note! Unable to test the output of the default .sass_cache location since the directory is stored outside of the app root during testing, but inside app root in "production" --- .../features/sass_cache_path.feature | 22 +++++++++++++++++++ .../sass-cache-path-custom-app/config.rb | 3 +++ .../source/stylesheets/plain.css.sass | 4 ++++ .../sass-cache-path-default-app/config.rb | 3 +++ .../source/stylesheets/plain.css.sass | 4 ++++ 5 files changed, 36 insertions(+) create mode 100644 middleman-more/features/sass_cache_path.feature create mode 100644 middleman-more/fixtures/sass-cache-path-custom-app/config.rb create mode 100644 middleman-more/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass create mode 100644 middleman-more/fixtures/sass-cache-path-default-app/config.rb create mode 100644 middleman-more/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass diff --git a/middleman-more/features/sass_cache_path.feature b/middleman-more/features/sass_cache_path.feature new file mode 100644 index 00000000..08f0f0ad --- /dev/null +++ b/middleman-more/features/sass_cache_path.feature @@ -0,0 +1,22 @@ +Feature: SASS .sass_cache custom location + + Scenario: Using the default location for .sass_cache folder + Given the Server is running at "sass-cache-path-default-app" + + When I go to "/stylesheets/plain.css" + Then I should see "color: blue;" + + # TODO:: + # Not sure how to test this location, as the directory is stored outside of the app root + # during testing, but inside app root in "production" + + # Then a directory named ".sass_cache" should exist + + + Scenario: Using a custom location for .sass_cache folder + Given the Server is running at "sass-cache-path-custom-app" + + When I go to "/stylesheets/plain.css" + Then I should see "html, body, div, span, applet, object, iframe," + + Then a directory named "/tmp/middleman-more-custom-sass_cache_path" should exist diff --git a/middleman-more/fixtures/sass-cache-path-custom-app/config.rb b/middleman-more/fixtures/sass-cache-path-custom-app/config.rb new file mode 100644 index 00000000..ed058bd5 --- /dev/null +++ b/middleman-more/fixtures/sass-cache-path-custom-app/config.rb @@ -0,0 +1,3 @@ + + +set :sass_cache_path, File.join('/tmp', "#{File.basename(Dir.pwd)}-custom-sass_cache_path") \ No newline at end of file diff --git a/middleman-more/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass b/middleman-more/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass new file mode 100644 index 00000000..79115283 --- /dev/null +++ b/middleman-more/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass @@ -0,0 +1,4 @@ +@import "compass/reset" + +red + color: blue \ No newline at end of file diff --git a/middleman-more/fixtures/sass-cache-path-default-app/config.rb b/middleman-more/fixtures/sass-cache-path-default-app/config.rb new file mode 100644 index 00000000..363c54fe --- /dev/null +++ b/middleman-more/fixtures/sass-cache-path-default-app/config.rb @@ -0,0 +1,3 @@ + +# Using default setting +# set :sass_cache_path, File.join(Dir.pwd, '.sass_cache') \ No newline at end of file diff --git a/middleman-more/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass b/middleman-more/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass new file mode 100644 index 00000000..79115283 --- /dev/null +++ b/middleman-more/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass @@ -0,0 +1,4 @@ +@import "compass/reset" + +red + color: blue \ No newline at end of file From 5368875d05777e24d2b2ce9e602098d9fcd33916 Mon Sep 17 00:00:00 2001 From: kematzy Date: Tue, 17 Jul 2012 09:35:40 +0800 Subject: [PATCH 3/3] Moved :sass_cache_path from global to Sass renderer --- middleman-core/lib/middleman-core/application.rb | 5 ----- middleman-core/lib/middleman-core/renderers/sass.rb | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 383be6f8..093edc13 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -101,11 +101,6 @@ module Middleman # @return [String] set :css_dir, "stylesheets" - # Location of SASS .sass_cache directory. - # @return [String] - # set :sass_cache_path, "/tmp/middleman-app-name/sass_cache" - set(:sass_cache_path) { File.join(root_path, '.sass_cache') } # runtime compile of path - # Location of images within source. Used by HTML helpers and Compass. # @return [String] set :images_dir, "images" diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index 5b85c4f3..550db121 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -14,6 +14,11 @@ module Middleman # Default sass options app.set :sass, {} + # Location of SASS .sass_cache directory. + # @return [String] + # set :sass_cache_path, "/tmp/middleman-app-name/sass_cache" + app.set(:sass_cache_path) { File.join(app.root_path, '.sass_cache') } # runtime compile of path + app.before_configuration do template_extensions :scss => :css, :sass => :css