4

I'm playing with Padrino, experimenting with a very minimal site at the moment with no DB and just a few HAML and SASS files under the app/ directory.

What I've noticed is that each time I render a page which links to a stylesheet that's defined in a .sass file, it compiles the stylesheet to .css and stores it under public/.

This is all very well, but I also have some static assets stored in public/, including images and some other hand-written .css files.

What this means is that my public/ directory becomes a mix of things I placed there and things compiled by Padrino. So, looking in there will show a bunch of .css files, some of which are compiled .sass files, and some of which are my actual primary static assets. This is confusing.

Is there a way I can stop Padrino (or Sinatra, or Rack, or whatever is doing it) from saving these compiled files during development, and keep my public/ clean?

Alternatively, can someone explain why what I'm asking for is a bad idea / by design / I should learn to love it instead? :-)

Thanks.

Peter Lewis
  • 97
  • 1
  • 7
  • Do you have any SASS options already set up in `configure` or anything like that? – ian Feb 11 '13 at 17:10
  • Not that I can find. I didn't change much, and certainly nothing SASS related. Are you saying that what I'm describing isn't the standard behaviour? – Peter Lewis Feb 11 '13 at 19:46
  • For the record, I've just created a fresh padrino project with 'padrino g project test -c sass' and this is the default behaviour. – Peter Lewis Feb 11 '13 at 20:08

2 Answers2

0

I don't know how to set the SASS settings for Padrino, I had a look and couldn't find anything helpful either. I would feel a bit nervous about running it this way too, it could easily get confusing and unhelpful, and what if the asset names clash?

What you could do is not add SASS in via Padrino, and then run it yourself either via the --watch switch or via something like Guard. That way you can also specify different subfolders within the public directory (images/css/js etc), which is what I do (although it does mean you need to remember to add the subfolder as part of the path when describing links). The app doesn't even need to know you're using SASS, and precompilation, when it's this simple, is surely better than the kind of compilation on demand that you've got at the moment (IMO).

You might try the Padrino mailing list for help with the settings.

ian
  • 12,003
  • 9
  • 51
  • 107
  • Thanks for the suggestions. I've asked on the mailing list, and will post back here if I get an answer. – Peter Lewis Feb 12 '13 at 09:53
  • 1
    I've also discovered [padrino-assets](https://rubygems.org/gems/padrino-assets) which appears to solve it, since it replaces the way padrino manages static assets with a totally different method, keeping them under app/assets. This gem also seems very flexible, in that it will let me serve the static assets from elsewhere, e.g. another host or S3. – Peter Lewis Feb 12 '13 at 09:56
0

Using the padrino-sprockets gems I also wanted to change the default /public/stylesheets directory to /assets/stylesheets where sprockets pick them up. I found that my padrino project genereated with the -c sass option had a /lib/sass_plugin.rb file with the following:

# Enables support for SASS template reloading for rack.
# Store SASS files by default within 'app/stylesheets/sass'
# See http://nex-3.com/posts/88-sass-supports-rack for more details.

module SassInitializer
  def self.registered(app)
    require 'sass/plugin/rack'
    Sass::Plugin.options[:template_location] = File.join(Padrino.root, "app/stylesheets")
    Sass::Plugin.options[:css_location] = File.join(Padrino.root, "public/stylesheets")
    app.use Sass::Plugin::Rack
  end
end 

Editing the :css_location path and restarting Padrino did the trick!

ASabourin
  • 79
  • 7