Need help with import_all function

4 views
Skip to first unread message

picardo

unread,
Nov 1, 2009, 2:06:00 PM11/1/09
to Compass
Hey,

I am working on a function to import all sass scripts at once. It's
turning a bit harder than I though. So here is my function:

module Compass::SassExtensions::Functions::ImportAll
def import_all()
target = File.join("**","partials", "**", "*.sass")

files = Dir.glob(target)
ret = Array.new
files.each do |o|
Sass::Script::Parse.parse("@import #{o}")
end

end
end

I'm stuck here. The imports are not executed, and the mixins set in
the partial files are not recognized. I think Sass::Script::Parse.parse
("@import #{o}") is not outputting the correct string values, or maybe
this is not how parse is not meant to be used? Can anyone improve this
function or give me feedback for debugging it?

thanks,
Volkan

Chris Eppstein

unread,
Nov 1, 2009, 3:33:38 PM11/1/09
to compas...@googlegroups.com
FYI: This is a better post for the haml mailing list. To summarize, I don't think you can accomplish this via a custom function; Nathan may know a trick that I don't tho.

A couple reasons:

1. The Sass::Plugin has special handling of the @import directive for quickly building a dependency map of files so that Sass knows when files are "out of date". If you use a function like this, compass and sass may not recompile your sass files when their dependencies change.

2. Function calls don't have a way to modify the document structure. Even if you accomplish parsing the import directive (Hint: no need to parse anything, you can just create an ImportNode directly), the calling document doesn't know that the import statement you created is part of the document.

If you're serious about this feature, you should work on a patch for the Sass Parser to allow for a glob syntax to be passed to the @import directive.

Also note that sass imports files are imported off the Sass load_path, imports must be relative to one of the entries on the path list (which always contains the current directory of the sass file being parsed). However, for clarity, I think a glob syntax should only work for the directory containing the sass file that's using it.

chris
Reply all
Reply to author
Forward
0 new messages