1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Sass] Update docs about defining custom functions.

This commit is contained in:
Nathan Weizenbaum 2009-12-23 20:55:27 -08:00
parent abbbae842a
commit 2411cf0bad
3 changed files with 25 additions and 7 deletions

View file

@ -154,8 +154,17 @@ but it's not a great idea to put much logic in there anyway
due to how browsers handle them. due to how browsers handle them.
If you really need some sort of dynamic CSS, If you really need some sort of dynamic CSS,
the best thing to do is put only the snippet you need to dynamically set you can define your own {Sass::Script::Functions Sass functions} using Ruby
in the `head` of your HTML document. that can access the database or other configuration.
*Be aware when doing this that Sass files are by default only compiled once
and then served statically.*
If you really, really need to compile Sass on each request,
first make sure you have adequate caching set up.
Then you can use {Sass::Engine} to render the code,
using the {file:SASS_REFERENCE.md#custom-option `:custom` option}
to pass in data that {Sass::Script::Functions::EvaluationContext#options can be accessed}
from your Sass functions.
## You still haven't answered my question! ## You still haven't answered my question!

View file

@ -203,6 +203,10 @@ Available options are:
as a comment. Useful for debugging especially when using imports as a comment. Useful for debugging especially when using imports
and mixins. and mixins.
{#custom-option} `:custom`
: An option that's available for individual applications to set
to make data available to {Sass::Script::Functions custom Sass functions}.
## CSS Rules ## CSS Rules
Rules in flat CSS have two elements: Rules in flat CSS have two elements:

View file

@ -54,11 +54,16 @@ module Sass::Script
# #
# Second, making Ruby functions accessible from Sass introduces the temptation # Second, making Ruby functions accessible from Sass introduces the temptation
# to do things like database access within stylesheets. # to do things like database access within stylesheets.
# This temptation must be resisted. # This is generally a bad idea;
# Keep in mind that Sass stylesheets are only compiled once # since Sass files are by default only compiled once,
# at a somewhat indeterminate time # dynamic code is not a great fit.
# and then left as static CSS files. #
# Any dynamic CSS should be left in `<style>` tags in the HTML. # If you really, really need to compile Sass on each request,
# first make sure you have adequate caching set up.
# Then you can use {Sass::Engine} to render the code,
# using the {file:SASS_REFERENCE.md#custom-option `options` parameter}
# to pass in data that {EvaluationContext#options can be accessed}
# from your Sass functions.
# #
# Within one of the functions in this module, # Within one of the functions in this module,
# methods of {EvaluationContext} can be used. # methods of {EvaluationContext} can be used.