Pregunta

I'm using sass-rails and compass-rails for the mixins.

My website allows users to pick their own colors. A bunch of those colors need to get run through the sass/compass mixins. The colors are stored in the database.

The solution I thought of is to dynamically set the color inside tags in the head. Unfortunately, I can't figure out a way to get Rails to process a block of SASS within a view file.

This solution does half the job. It processes the sass in an external file and loads it into the view, but I have no way of passing a color to it:

<%= Rails.application.assets.find_asset('mystyle').to_s.html_safe %>

Any ideas?

¿Fue útil?

Solución

You can use the Sass Engine in your app like this too:

  color = "#0000ff"
  engine = Sass::Engine.new("#main {background-color: #{color};height: pow(10,2)px}", :syntax => :scss)  
  engine.render
  => "#main {\n  background-color: #0000ff;\n  height: 100 px; }\n"

pow() is a compass function just to show you can use compass there. You need to have the compass gem in your Gemfile.

See under "Using Sass" here:

http://sass-lang.com/documentation/file.SASS_REFERENCE.html

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top