guard-sass 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/guard/sass.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'sass'
1
2
  require 'sass/plugin'
2
3
 
3
4
  require 'guard'
@@ -95,44 +96,22 @@ module Guard
95
96
  run_on_changes files.reject {|f| partial?(f) }
96
97
  end
97
98
 
98
- def resolve_partials_to_owners(paths, depth = 0)
99
- # If we get more than 10 levels of includes deep, we're probably in an
100
- # import loop.
101
- return run_all if depth > 10
102
-
99
+ def resolve_partials_to_owners(paths)
103
100
  # Get all files that might have imports
104
- root = options[:input]
105
- root += '/' unless root.end_with?('/')
106
-
107
- partials = paths.find_all {|f| partial?(f) }
108
- paths -= partials
109
- sub_paths = partials.map {|p|
110
- # Remove root, need relative paths
111
- p.sub(/^#{root}/, '')
112
- }.map {|p|
113
- # Make version without underscores
114
- [p, p.gsub(/(\/|^)_/, '\\1')]
115
- }.map {|ps|
116
- # For each of those, make a version with extensions
117
- ps.map {|p|
118
- [p, p.gsub(/\.s[ac]ss$/, '')]
119
- }
120
- }.flatten
121
-
122
- # Search through all eligible files and find those we need to recompile
123
- joined_paths = sub_paths.map {|p| Regexp.escape(p) }.join('|')
124
- matcher = /@import.*(:?#{joined_paths})/
125
- importing = files.find_all {|file| open(file, 'r').read.match(matcher) }
126
- paths += importing
127
-
128
- # If any of the matched files were partials, then go ahead and walk up the
129
- # import tree
130
- if paths.any? {|f| partial?(f) }
131
- paths = resolve_partials_to_owners(paths, depth + 1)
101
+ search_files = Dir.glob("#{options[:input]}/**/*.s[ac]ss")
102
+ search_files = Watcher.match_files(self, search_files)
103
+
104
+ # Get owners
105
+ owners = search_files.select do |file|
106
+ # Get dependencies of file
107
+ deps = ::Sass::Engine.for_file(file, @options).dependencies.collect! {|dep| dep.options[:filename] }
108
+ # Find intersection with paths
109
+ deps_in_paths = deps.intersection paths
110
+ # Any paths in the dependencies?
111
+ !deps_in_paths.empty?
132
112
  end
133
-
134
113
  # Return our resolved set of paths to recompile
135
- paths
114
+ owners
136
115
  end
137
116
 
138
117
  def run_with_partials(paths)
@@ -75,17 +75,14 @@ module Guard
75
75
  # @param file [String] Path to sass/scss file to compile
76
76
  # @return [String] Compiled css.
77
77
  def compile(file)
78
- content = IO.read(file)
79
-
80
78
  sass_options = {
81
- :filename => file,
82
- :syntax => file[-4..-1].to_sym,
83
79
  :load_paths => options[:load_paths],
84
80
  :style => options[:style],
85
81
  :debug_info => options[:debug_info],
86
82
  :line_numbers => options[:line_numbers]
87
83
  }
88
- ::Sass::Engine.new(content, sass_options).render
84
+
85
+ ::Sass::Engine.for_file(file, sass_options).render
89
86
  end
90
87
 
91
88
  # @param file [String]
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  class SassVersion
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-13 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard