Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created October 5, 2010 23:36
Show Gist options
  • Save josevalim/612548 to your computer and use it in GitHub Desktop.
Save josevalim/612548 to your computer and use it in GitHub Desktop.
## 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