compass on sinatra

106 views
Skip to first unread message

stephen murdoch

unread,
Jul 25, 2010, 4:26:00 AM7/25/10
to Compass
I'm using compass and sinatra and everything is working really well.

Something puzzles me though.

If I use compass in, say, a rails app, then I would normally run
"compass watch" to compile my sass into css as I make changes.

But, with sinatra, I've not actually been running "compass watch" so I
have no compiled css files, yet my app still has all the styles that
i've defined in my sass files.

I imagine that this is because of the following route in my
application's main file:

get '/stylesheets/:name.css' do
headers 'Content-Type' => 'text/css; charset=utf-8'
sass(:"stylesheets/#{params[:name]}", Compass.sass_engine_options )
end

Am I correct in thinking that compass (or sass) is converting the sass
versions of my stylsheets at runtime, without actually writing them to
disk?

So I have three questions if you don't mind...

1 - Should I still be running "compass watch"?
2 - Will compass use the compiled css if it is present or will it just
continue doing what it is doing?
3 - Is there a performance gain from using compiled css files or
should I just forget about them altogether?

Thanks




Nathan Weizenbaum

unread,
Jul 25, 2010, 5:22:27 AM7/25/10
to compas...@googlegroups.com
1) No, "compass watch" is never necessary when using a Ruby app, whatever the framework.
2) No, you have to explicitly make use of the compiled CSS.
3) Yes, using compiled CSS will result in a dramatic performance gain. Otherwise, Sass has to re-parse and re-render all of your files for every request. While Sass is pretty quick, this is still unnecessary processing time.

The proper way to use Sass/Compass with Sinatra is to use the Sass Rack plugin. This will allow any Rack app (including Sinatra apps) to compile Sass to CSS on the fly, with proper caching and so forth. In order to use it with Compass, simply set "Sass::Plugin.options = Compass.sass_engine_options".

There is one complication with this: if you're using Heroku as you indicated in your other email, compiling Sass on the server isn't going to work without some tweaking. I believe koppen's Hassle fork is the most up-to-date way to deal with this.





--
You received this message because you are subscribed to the Google Groups "Compass" group.
To post to this group, send email to compas...@googlegroups.com.
To unsubscribe from this group, send email to compass-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/compass-users?hl=en.


stephen murdoch

unread,
Jul 25, 2010, 6:33:12 AM7/25/10
to Compass
Thanks for the awesome reply! Very helpful, thanks

On Jul 25, 10:22 am, Nathan Weizenbaum <nex...@gmail.com> wrote:
> 1) No, "compass watch" is never necessary when using a Ruby app, whatever
> the framework.
> 2) No, you have to explicitly make use of the compiled CSS.
> 3) Yes, using compiled CSS will result in a dramatic performance gain.
> Otherwise, Sass has to re-parse and re-render all of your files for every
> request. While Sass is pretty quick, this is still unnecessary processing
> time.
>
> The proper way to use Sass/Compass with Sinatra is to use the Sass Rack
> plugin<http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBUQFjAA&url=http...>.
> This will allow any Rack app (including Sinatra apps) to compile Sass to CSS
> on the fly, with proper caching and so forth. In order to use it with
> Compass, simply set "Sass::Plugin.options = Compass.sass_engine_options".
>
> There is one complication with this: if you're using Heroku as you indicated
> in your other email, compiling Sass on the server isn't going to work
> without some tweaking. I believe koppen's Hassle
> fork<http://github.com/koppen/hassle> is
> the most up-to-date way to deal with this.
>
> On Sun, Jul 25, 2010 at 1:26 AM, stephen murdoch <
>
> > compass-user...@googlegroups.com<compass-users%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages