Skip to content
Browse files

Initial commit

guard-compass basics are working.

Signed-off-by: Olivier Amblet <olivier@amblet.net>
  • Loading branch information...
0 parents commit 6e7bee1c3a84436f11c1205513e4dc3e429b2c0a oamblet committed Oct 25, 2010
2 .gitignore
@@ -0,0 +1,2 @@
+Gemfile.lock
+guard-compass-*.gem
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem 'growl'
+gemspec
6 Guardfile
@@ -0,0 +1,6 @@
+guard 'rspec', :version => 2 do
+ require 'growl' rescue nil
+ watch('^spec/(.*)_spec.rb')
+ watch('^lib/(.*).rb') { |m| "spec/#{m[1]}_spec.rb" }
+ watch('^spec/spec_helper.rb') { "spec" }
+end
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Thibaud Guillaume-Gentil
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 README.textile
@@ -0,0 +1,24 @@
+h1. Guard Compass Plug-in
+
+Let you configure a Guard that will run compass whenever a stylesheet is updated.
+
+h2. Quick Start
+
+ $ (sudo) gem install compass
+ $ compass -f blueprint my_compass_project
+ $ cd my_compass_project
+ $ bundle init
+
+Then, edit the Gemfile for it to looks like:
+
+ source "http://rubygems.org"
+
+ gem 'guard-compass'
+
+ $ bundle install
+ $ guard init
+ $ guard init compass
+ $ guard
+
+Your scss(or sass) stylesheets are now guarded.
+
7 Rakefile
@@ -0,0 +1,7 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
+
27 guard-compass.gemspec
@@ -0,0 +1,27 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'guard/sass'
+
+Gem::Specification.new do |s|
+ s.name = 'guard-compass'
+ s.version = Guard::Sass::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['Olivier Amblet']
+ s.email = ['olivier@amblet.net']
+ s.homepage = 'http://rubygems.org/gems/guard-compass'
+ s.summary = 'Guard gem for Compass'
+ s.description = 'Guard::Compass automatically rebuilds scss|sass files when a modification occurs taking in account your compass configuration.'
+
+ s.required_rubygems_version = '>= 1.3.6'
+ s.rubyforge_project = 'guard-compass'
+
+ s.add_dependency 'guard', '>= 0.2.1'
+ s.add_dependency 'compass', '>= 0.10.5'
+
+ s.add_development_dependency 'bundler', '~> 1.0.2'
+ s.add_development_dependency 'rspec', '~> 2.0.0.rc'
+ s.add_development_dependency 'guard-rspec', '>= 0.1.4'
+
+ s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.textile]
+ s.require_path = 'lib'
+end
54 lib/guard/compass.rb
@@ -0,0 +1,54 @@
+require 'guard'
+require 'guard/guard'
+
+require 'compass'
+require 'compass/commands'
+require 'compass/logger'
+
+module Guard
+ class Compass < Guard
+ attr_reader :updater
+
+ VERSION = '0.0.5'
+
+ def initialize(watchers = [], options = {})
+ @watchers, @options = watchers, options
+ super
+ @options.merge!(:path => File.expand_path(File.dirname(".")) )
+ end
+
+ # Guard Interface Implementation
+
+ # Compile all the sass|scss stylesheets
+ def start
+ super
+ create_updater
+ end
+
+ def stop
+ super
+ @updater = nil
+ end
+
+ # Reload the configuration
+ def reload
+ super
+ create_updater
+ end
+
+ # Compile all the sass|scss stylesheets
+ def run_all
+ @updater.execute
+ end
+
+ # Compile the changed stylesheets
+ def run_on_change(paths)
+ @updater.execute
+ end
+
+ private
+ def create_updater
+ @updater = ::Compass::Commands::UpdateProject.new(@options[:path], @options)
+ end
+ end
+end
3 lib/guard/compass/templates/Guardfile
@@ -0,0 +1,3 @@
+guard 'compass' do
+ watch('^src/(.*)\.s[ac]ss')
+end
BIN ...ixtures/compass_prj/.sass-cache/77242121e92e5208094a0a0f6fbd9eb05d2c3832/_utilities.scssc
Binary file not shown.
BIN spec/fixtures/compass_prj/.sass-cache/804c142587e371bce0dd76315d953aa707422b74/_reset.scssc
Binary file not shown.
9 spec/fixtures/compass_prj/config.rb
@@ -0,0 +1,9 @@
+# Require any additional compass plugins here.
+# Set this to the root of your project when deployed:
+http_path = "/"
+css_dir = "stylesheets"
+sass_dir = "src"
+images_dir = "images"
+javascripts_dir = "javascripts"
+# To enable relative paths to assets via compass helper functions. Uncomment:
+# relative_assets = true
5 spec/fixtures/compass_prj/src/ie.scss
@@ -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]--> */
3 spec/fixtures/compass_prj/src/print.scss
@@ -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" /> */
6 spec/fixtures/compass_prj/src/screen.scss
@@ -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";
74 spec/guard/compass_spec.rb
@@ -0,0 +1,74 @@
+require 'fileutils'
+require 'spec_helper'
+require 'guard/compass'
+
+describe Guard::Compass do
+ subject { Guard::Compass.new }
+
+ before :each do
+ @project_path = File.expand_path('./compass_prj')
+ end
+
+ describe "start" do
+ it "supports creation of the updater instance" do
+ subject.updater.should be_nil
+ subject.start
+ subject.updater.should_not be_nil
+ end
+
+ it "should not generate anything" do
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ end
+ end
+
+ describe "default options" do
+ it "should have a default path mathching the run location" do
+ subject.options[:path].should == File.expand_path(".")
+ subject.start
+ end
+ end
+
+ describe "after start" do
+
+ before :each do
+ FileUtils.mkdir(TMP_PATH) if ! File.exists? TMP_PATH
+ @project_path = TMP_PATH + '/compass_prj'
+ FileUtils.cp_r FIXTURES_PATH + '/compass_prj', TMP_PATH
+ subject.options.merge!(:path => @project_path)
+
+ subject.start
+ end
+ after :each do
+ FileUtils.rm_rf(TMP_PATH)
+
+ subject.stop
+ end
+
+ describe "stop" do
+ it "Stop remove the updater" do
+ subject.updater.should_not be_nil
+ subject.stop
+ subject.updater.should be_nil
+ end
+ end
+
+ describe "run_on_change" do
+ it "rebuilds all scss files in compass path" do
+ File.exists?(@project_path + "/src/screen.scss").should(be_true)
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ subject.run_on_change(@project_path + "/src/screen.scss")
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_true
+ end
+ end
+
+ describe "run all" do
+ it "rebuilds all scss files in compass path" do
+ File.exists?(@project_path + "/src/screen.scss").should(be_true)
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_false
+ subject.run_all
+ File.exists?(@project_path + "/stylesheets/screen.css").should be_true
+ end
+ end
+
+ end
+end
16 spec/spec_helper.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+FIXTURES_PATH = File.expand_path(File.dirname(__FILE__) + '/fixtures')
+TMP_PATH = File.expand_path(File.dirname(__FILE__) + '/tmp_files')
+
+RSpec.configure do |config|
+ config.color_enabled = true
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+
+ config.before(:each) do
+ ENV["GUARD_ENV"] = 'test'
+ @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__))
+ @lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
+ end
+end

0 comments on commit 6e7bee1

Please sign in to comment.
Something went wrong with that request. Please try again.