Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
[➠] Allow “*.css.sass” or “*.css.scss” as file extensions without hav…
Browse files Browse the repository at this point in the history
…ing to write “@import "foo.css.scss"”.
  • Loading branch information
Maik Kempe committed Jun 18, 2013
1 parent 7ab685f commit 7df820c
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 18 deletions.
20 changes: 20 additions & 0 deletions lib/guard/sass/importer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'sass/importers/filesystem'

module Guard
class Sass
class Importer < ::Sass::Importers::Filesystem
def extensions
{
'css' => :scss,
'css.scss' => :scss,
'css.sass' => :sass,
'css.erb' => :scss,
'scss.erb' => :scss,
'sass.erb' => :sass,
'css.scss.erb' => :scss,
'css.sass.erb' => :sass
}.merge!(super)
end
end
end
end
11 changes: 7 additions & 4 deletions lib/guard/sass/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ def compile_files(files)
# @return [String] Compiled css.
def compile(file)
sass_options = {
:load_paths => options[:load_paths],
:style => options[:style],
:debug_info => options[:debug_info],
:line_numbers => options[:line_numbers]
:filesystem_importer => Importer,
:load_paths => options[:load_paths],
:style => options[:style],
:debug_info => options[:debug_info],
:line_numbers => options[:line_numbers]
}

::Sass::Engine.for_file(file, sass_options).render
Expand Down Expand Up @@ -125,3 +126,5 @@ def write_file(content, dir, file)
end
end
end

require 'guard/sass/importer'
2 changes: 2 additions & 0 deletions sass-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore sass cache
.sass-cache
4 changes: 2 additions & 2 deletions sass-test/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source :rubygems
source "http://rubygems.org"

group :osx do
gem 'growl'
Expand All @@ -8,4 +8,4 @@ end
gem 'compass'
gem 'guard', '>= 1.1.0'
gem 'guard-sass', :path => '../'
gem 'guard-shell'
gem 'guard-shell'
2 changes: 2 additions & 0 deletions sass-test/_sass/partials/_sass_importer.css.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
html
color: blue
3 changes: 1 addition & 2 deletions sass-test/_sass/partials/_test.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
html
color: blue

color: blue
2 changes: 1 addition & 1 deletion sass-test/_sass/print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
.badError {
@extend .error;
border-width: 4px;
}
}
4 changes: 4 additions & 0 deletions sass-test/_sass/sass_importer.css.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@import partials/_sass_importer

body
background: red
3 changes: 1 addition & 2 deletions sass-test/_sass/test.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
body
color: red

color: red
5 changes: 5 additions & 0 deletions sass-test/css/sass_importer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html {
color: blue; }

body {
background: red; }
14 changes: 7 additions & 7 deletions spec/guard/sass/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Guard.stub(:listener).and_return stub('Listener')
end


describe '#run' do

it 'returns a list of changed files' do
Expand Down Expand Up @@ -63,12 +62,13 @@

mock_engine = mock(::Sass::Engine)
::Sass::Engine.should_receive(:new).with('', {
:load_paths => ['sass'],
:style => :nested,
:debug_info => false,
:line_numbers => false,
:syntax => :sass,
:filename => "a.sass"
:filesystem_importer => Guard::Sass::Importer,
:load_paths => ['sass'],
:style => :nested,
:debug_info => false,
:line_numbers => false,
:syntax => :sass,
:filename => 'a.sass'
}).and_return(mock_engine)
mock_engine.should_receive(:render)

Expand Down

0 comments on commit 7df820c

Please sign in to comment.