Created
October 5, 2010 23:36
-
-
Save josevalim/612548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Imagine the following files: | |
# foo.css.scss | |
@import bar | |
foo { | |
@include bar | |
} | |
# bar.css.scss | |
mixin bar { | |
bar: baz | |
} | |
# Today, when I give it to SASS template handler, the template handler is going | |
# to return a string that will result in the following compiled method: | |
def compiled_method | |
"foo {\n bar: baz }" | |
end | |
# This method already included the mixin. This means that, to know if we need to | |
# recompile the file, we need to track everything that was already imported. | |
# My approach relies on pre-compiliation. The compiled template sass would | |
# generate would be like this: | |
def compiled_template | |
Sass.importer.find("omg") | |
"\nfoo{" << Sass::Mixins.handle(:bar, :ident => 2) << "}" | |
end | |
# Look that the mixin was not included and it will only be once we call render. | |
# In production, render will be called just on the first request, but in every | |
# request in development. But since it is simply doing string concatenation, | |
# it will still be really fast! | |
# | |
# The huge benefit is that we don't need to track dependencies, no trees! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment