views:

370

answers:

3

Instead of serving my Sass files from the default 'views' directory I'd like to change this to /assets/sass

The following attempts are in my main ruby root file in the app:

Attempt 1

set :sass, Proc.new { File.join(root, "assets/sass") }

get '/stylesheet.css' do
    sass :core
end

With this I get the following error:

 myapp.rb:17 NoMethodError: undefined method `merge' for "/Users/x/x/x/mysinatraapp/assets/sass":String

Attempt 2

get '/stylesheet.css' do
    sass :'/assets/sass/core'
end

Attempt 3

get '/stylesheet.css' do
    sass :'/assets/sass/core'
end

Both return the following error:

Errno::ENOENT: No such file or directory - ./views/assets/sass/core.sass

Attempt 4

get '/stylesheet.css' do
    sass :'../assets/sass/core'
end

This works! however, there must be something along the lines of set :sass, Proc.new { File.join(root, "assets/sass") } that sets this up for me?

A: 

I currently can't test this myself, but have you tried the following.

set :sass, File.dirname(__FILE__) + '/assets'

EDIT: The Sass reference might help as well.

ponzao
I've taken a look at the Sass ref thanks, your code snippet gives me the same error as in Attempt 1. Cheers
Dr. Frankenstein
A: 

This probably doesn't help since I'm guessing you have other stuff under views that you want to stay put, but you can change the views directory as well...

set :views, File.dirname(__FILE__) + '/assets'

Then you could do:

get '/stylesheet.css' do
    sass :'sass/core'
end
sevennineteen
A: 

There is no such way at the moment, as Sinatra currently only accepts a single view directory.

You could try using sinatra-compass and set :compass, :sass_dir => 'assets' and only place a single sass file in your view folder, that will simply @import stylesheet.sass or you could overwrite #sass:

helpers do
  def sass(template, *args)
    template = :"#{settings.sass_dir}/#{template}" if template.is_a? Symbol
    super(template, *args)
  end
end

set :sass_dir, '../assets'
Konstantin Haase
This answer looks great but I can't seem to get it rolling - any ideas where I am going wrong? - http://pastie.org/986956 - Thanks a lot
Dr. Frankenstein
You use `settings.sass_dir` but `set :sass, ...`. You should `set :sass_dir, ...` (`sass` might be used by sinatra and expected to be a hash, so you should avoid using that name).
Konstantin Haase