Permalink
Browse files

Merge branch 'master' of git://github.com/oliamb/guard-compass

Conflicts:
	README.textile
	lib/guard/compass.rb
	lib/guard/compass/templates/Guardfile
  • Loading branch information...
2 parents 5225ed7 + 85ec3db commit d43a46649b9158ccba19d081af9ca7a22ea8864d Rémy Coutable committed Oct 3, 2011
View
@@ -1,7 +1,14 @@
+== 0.0.7
+
+* Create a watch rules based on the compass config (no more need to create watchers)
+* [BUGFIX] #1: You can now define the options :project_path and :configuration_file to
+find and run Compass Compiler (see README for more information). This was a problem with
+non-standard deployment
+
== 0.0.6
-Guard quit on ctrl-c when guard-compass is in
+* Guard quit on ctrl-c when guard-compass is in
== 0.0.5
-Initial release
+* Initial release
View
@@ -28,16 +28,20 @@ h2. Configure Guard::Compass plug-in
The default configuration generated by 'guard init compass' looks like this
bc. guard 'compass' do
- watch(%r{^src/(.*)\.s[ac]ss})
-end
-the compass guard accept two options:
+You can override Compass options from the Guard declaration. You want to use
+that if Guard cannot locate your compass configuration file. In this case use:
- * :workdir: all compass relative path will be computed from there
- * :configuration_file: relative or absolute path to your compass configuration file
+ * :project_path: path to the compass project directory (from guard working directory)
+ * :configuration_file: path to your compass configuration file (from guard working directory)
-By default, the working directory is the folder where you run guard in and
-the configuration_file is computed by compass
+By default, the project path is equal to the guard working directory(the folder from where you start Guard).
+Compass will look into some default location for the config file from there.
+
+The configuration_file is computed by compass. You don't need to define watchers like
+in other Guard plug-in because they are generated from the Compass configuration files, cool!
+
+For the complete list of options, please refer to the Compass documentation.
h2. Roadmap
View
@@ -1,53 +1,106 @@
require 'guard'
require 'guard/guard'
+require 'guard/watcher'
require 'guard/reporter'
+require 'guard/compass_helper'
require 'compass'
require 'compass/commands'
require 'compass/logger'
module Guard
class Compass < Guard
- attr_reader :updater, :options
+ attr_reader :updater, :working_path
attr_accessor :reporter
def initialize(watchers = [], options = {})
super
@reporter = Reporter.new
- @options[:workdir] ||= File.expand_path(File.dirname("."))
+ @working_path = Pathname.pwd # the Guard base path is the current working_path
end
-
+
+ # Load Compass Configuration
+ def create_watchers
+ # root_path is the path to the compass project
+ # working_path is the current Guard (and by extension Compass) working directory
+
+ watchers.clear
+
+ config_file = (options[:configuration_file] || ::Compass.detect_configuration_file(root_path))
+
+ if(config_file.nil?)
+ reporter.failure "Cannot find a Compass configuration file, please add information to your Guardfile guard 'compass' declaration."
+ return false
+ end
+
+ config_path = pathname(working_path, config_file)
+
+ unless(config_path.exist?)
+ reporter.failure "Compass configuration file not found: #{config_path}\nPlease check Guard configuration."
+ return false
+ end
+ src_path = pathname(root_path, ::Compass.configuration.sass_dir)
+
+ watchers.push Watcher.new(%r{^#{src_path.relative_path_from(working_path)}/.*})
+ watchers.push Watcher.new(%r{^#{config_path.relative_path_from(working_path)}$})
+ end
+
+ def root_path
+ options[:project_path].nil? ? working_path : pathname(working_path, options[:project_path])
+ end
+
+ def valid_sass_path?
+ path = pathname(root_path, ::Compass.configuration.sass_dir)
+ unless path.exist?
+ reporter.failure("Sass files src directory not found: #{path}\nPlease check your Compass configuration.")
+ false
+ else
+ true
+ end
+ end
+
# Guard Interface Implementation
-
+
# Compile all the sass|scss stylesheets
def start
create_updater
reporter.announce "Guard::Compass is watching at your stylesheets."
true
end
-
+
def stop
@updater = nil
true
end
-
+
# Reload the configuration
def reload
create_updater
true
end
-
+
# Compile all the sass|scss stylesheets
def run_all
perform
end
-
+
# Compile the changed stylesheets
def run_on_change(paths)
perform
end
-
+
private
+ include CompassHelper
+
+ # Cleanup of the given options
+ def cleanup_options
+
+ # Ensure configuration file make reference to an absolute path.
+ if(options[:configuration_file])
+ options[:configuration_file] = pathname(working_path, options[:configuration_file]).to_s
+ end
+ end
+
def perform
if valid_sass_path?
@updater.execute
@@ -56,31 +109,12 @@ def perform
false
end
end
-
+
def create_updater
- if(options[:configuration_file])
- filepath = Pathname.new(options[:configuration_file])
- if(filepath.relative?)
- filepath = Pathname.new([options[:workdir], options[:configuration_file]].join("/"))
- end
- if(filepath.exist?)
- ::Compass.add_configuration filepath
- options[:configuration_file] = filepath
- else
- reporter.failure "Compass configuration file not found: #{filepath}\nPlease check Guard configuration."
- end
- end
- @updater = ::Compass::Commands::UpdateProject.new(@options[:workdir] , @options)
+ cleanup_options
+ @updater = ::Compass::Commands::UpdateProject.new(working_path.to_s, options)
+ create_watchers
valid_sass_path?
end
-
- def valid_sass_path?
- unless File.exists? ::Compass.configuration.sass_path
- reporter.failure("Sass files src directory not found: #{::Compass.configuration.sass_path}\nPlease check your Compass configuration.")
- false
- else
- true
- end
- end
end
-end
+end
@@ -1,8 +1,15 @@
-guard 'compass' do
- watch(%r{^src/(.*)\.s[ac]ss})
-end
+# Guard::Compass
+#
+# You don't need to configure watchers for guard 'compass' declaration as they generated
+# from your Compass configuration file. You might need to define the Compass working directory
+# and point to the configuration file depending of your project structure.
+#
+# Available options:
+#
+# * :workging_directory => Define the Compass working directory, relative to the Guardfile directory
+# * :configuration_file => Path to the Compass configuration file, relative to :project_path
+#
+# Like usual, the Compass configuration path are relative to the :project_path
-# # Alternative
-# guard 'compass', :workdir => 'not_current_dir', :configuration_file => 'path/to/my/compass_config.rb' do
-# watch(%r{^src/(.*)\.s[ac]ss})
-# end
+# guard 'compass', :project_path => 'not_current_dir', :configuration_file => 'path/to/my/compass_config.rb'
+guard 'compass'
@@ -0,0 +1,47 @@
+require 'compass'
+require 'compass/commands'
+require 'compass/commands/project_base'
+require 'compass/compiler'
+
+module Guard
+ module CompassHelper
+ # Build a path agains components that might be relative or absolute.
+ # Whenever an absolute component is found, it became the new
+ # base path on which next relative components are built.
+ def pathname(*components)
+ result = Pathname.pwd
+ components.each do |c|
+ pc = Pathname.new(c)
+ if(pc.relative?)
+ result = result + pc
+ else
+ result = pc
+ end
+ end
+ return result
+ rescue
+ raise "Cannot process #{components.inspect}: #{$!}"
+ end
+
+ # Excerpt from Compass updater commands #
+
+ def check_for_sass_files!(compiler)
+ if compiler.sass_files.empty?
+ message = "Nothing to compile. If you're trying to start a new project, you have left off the directory argument.\n"
+ message << "Run \"compass -h\" to get help."
+ raise Compass::Error, message
+ end
+ end
+
+ def new_compiler_instance(working_path)
+ compiler_opts = ::Compass.sass_engine_options
+ compiler_opts.merge!(:quiet => options[:quiet],
+ :force => options[:force],
+ :dry_run => options[:dry_run])
+ ::Compass::Compiler.new(working_path,
+ ::Compass.configuration.sass_path,
+ ::Compass.configuration.css_path,
+ compiler_opts)
+ end
+ end
+end
@@ -0,0 +1,9 @@
+# Require any additional compass plugins here.
+# Set this to the root of your project when deployed:
+http_path = "/"
+css_dir = "custom_config_file_2/another_stylesheets_location"
+sass_dir = "custom_config_file_2/another_src_location"
+images_dir = "custom_config_file_2/another_images_location"
+javascripts_dir = "custom_config_file_2/another_javascripts_location"
+# To enable relative paths to assets via compass helper functions. Uncomment:
+# relative_assets = true
@@ -0,0 +1,5 @@
+/* Welcome to Compass. Use this file to write IE specific override styles.
+ * Import this file using the following HTML or equivalent:
+ * <!--[if IE]>
+ * <link href="/stylesheets/ie.css" media="screen, projection" rel="stylesheet" type="text/css" />
+ * <![endif]--> */
@@ -0,0 +1,3 @@
+/* Welcome to Compass. Use this file to define print styles.
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css" /> */
@@ -0,0 +1,6 @@
+/* Welcome to Compass.
+ * In this file you should write your main styles. (or centralize your imports)
+ * Import this file using the following HTML or equivalent:
+ * <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css" /> */
+
+@import "compass/reset";
@@ -1 +1 @@
-guard 'compass', :workdir => 'test', :configuration_file => 'test_also.rb'
+guard 'compass', :project_path => 'test', :configuration_file => 'test_also.rb'
@@ -0,0 +1,39 @@
+require 'spec_helper'
+
+describe Guard::CompassHelper do
+ subject {self}
+
+ include Guard::CompassHelper
+
+ before :each do
+ Pathname.stub!(:pwd).and_return(Pathname.new('/test/me'))
+ end
+
+ describe "pathname method" do
+ it "retrieve pwd when nothing given" do
+ subject.pathname.should == Pathname.new('/test/me')
+ end
+
+ it "retrieve the absolut path as it" do
+ subject.pathname('/hello/boy').should == Pathname.new('/hello/boy')
+ end
+
+ it "computes the relative path" do
+ subject.pathname('a', 'b', 'c').should == Pathname.new('/test/me/a/b/c')
+ end
+
+ it "takes the absolute path in middle of the run" do
+ subject.pathname('a', '/another/test', 'c').should == Pathname.new('/another/test/c')
+ end
+
+ it "understand double dot notation" do
+ subject.pathname('..').should == Pathname.new('/test')
+ subject.pathname('..').to_s.should == '/test'
+ subject.pathname('..', 'a/d/c').should == Pathname.new('/test/a/d/c')
+
+
+ subject.pathname('..', 'custom_config_file/another_config_location/config.rb').to_s.should == '/test/custom_config_file/another_config_location/config.rb'
+ end
+ end
+
+end
Oops, something went wrong.

0 comments on commit d43a466

Please sign in to comment.