Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Ruby/Rails variables inside Sass?

Is there a way to use variables from my Ruby application inside a Sass file?

like image 950
alik Avatar asked Oct 04 '11 20:10

alik


People also ask

How do you use variables in Sass?

The basic syntax for defining a variable is simple: Just use a $ before the variable name and treat its definition like a CSS rule: Sass Variable Syntax: $<variable name>:<value>; The following declares a variable named large-font.

Where do you declare variables in Sass?

Sass variables are only available at the level of nesting where they are defined. Will the color of the text inside a <p> tag be red or green? It will be red! The other definition, $myColor: green; is inside the <h1> rule, and will only be available there!

Does Sass support CSS variables?

Sass variables are all compiled away by Sass. CSS variables are included in the CSS output. CSS variables can have different values for different elements, but Sass variables only have one value at a time.

How do I declare a global variable in Sass?

Declaration of a variable in SASS: In SASS, you can define a variable by using $ symbol at the starting of the name of the variable and followed by its value. Understanding scope of a variable: SASS variables can be declared anywhere in the document before it is used.


1 Answers

You can add .erb extention to your .sass file and then add your variables just like in regular .erb file:

<%= APP_CONFIG[:yourkey] %> 

More information:

  • http://guides.rubyonrails.org/asset_pipeline.html#preprocessing
  • http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
  • http://rwilcox.tumblr.com/post/9038701675/sass-variables-and-the-rails-3-1-asset-pipeline
like image 91
Laurynas Avatar answered Sep 28 '22 05:09

Laurynas