hawx / guard-sass

Guard::Sass automatically rebuilds sass files when modified (like sass --watch)
MIT License
88 stars 35 forks source link

Dependency resolution for partials, prettier output, Compass support #31

Closed cheald closed 12 years ago

cheald commented 12 years ago

Big series of changes here, so I understand if the pull request is rejected, but I tried to keep them atomic.

I:

Output now looks like:

    Sass [0.14s] smoketest.css.sass            -> smoketest.css
    Sass [0.14s] bootstrap/responsive.scss     -> bootstrap/responsive.css
    Sass [0.54s] bootstrap/bootstrap.scss      -> bootstrap/bootstrap.css
    Sass [0.94s] app.css.sass                  -> app.css

I've been testing it with my team for a few days, and it seems to work great so far.

hawx commented 12 years ago

Wow. Thanks, this is great. The dependency resolution is much faster.

I've just changed @include … searching to be more flexible, it will check for underscores and/or extension as well as without.

cheald commented 12 years ago

I actually had it with the underscores and extensions first (you can see that in my earlier commits), then moved to the much more general regex. You're actually right in adding the underscores (oops!), but that should be a simple tweak to the regex. The extension shouldn't be necessary, though, since it's not an anchored search, but I suppose they can't hurt! :)

hawx commented 12 years ago

My thoughts exactly.

chrisirhc commented 11 years ago

Just curious, why isn't this using the built-in Sass::Engine#dependencies method instead of looking through the files to find the dependencies? It can use that to create a map iterate through the maps.

hawx commented 11 years ago

Sass::Engine#dependencies returns the files it imports, not that import it (if that is clear). So the current method can be thought of as the reverse of #dependencies.

chrisirhc commented 11 years ago

Yep.

What I mean is to use the dependencies method on each search_file file instead of recursively searching the import tree. Why not just use the built-in method dependencies method and check if the the current file is in that list for each search file?

Something like:

def resolve_partials_to_owners(paths)
    # Get all files that might have imports
    root = (options[:input][-1] == "/" ? options[:input] : "#{options[:input]}/").reverse
    search_files = Dir.glob("#{options[:input]}/**/*.s[ac]ss")
    search_files = Watcher.match_files(self, search_files)

    # Get owners
    owners = search_files.select do |file|
        # Get dependencies of file
        deps = Sass::Engine.for_file(file, {}).dependencies.collect! {|dep| dep.options[:filename]}
        # Find intersection with paths
        deps_in_paths = deps.intersection paths
        # Any paths in the dependencies?
        !deps_in_paths.empty?
    end

    # Return our resolved set of paths to recompile
    paths + owners
end

I could send a pull request, but I'm wondering if there's a reason for not doing this instead. There's no need to walk the dependencies because it is already flattened by Sass::Engine.

hawx commented 11 years ago

I get what you mean now. It looks good. If you send me a pull request I'd be happy to accept it.