Closed lilith closed 13 years ago
Why not just rename CSS as SCSS and call it a day? You'd get better performance by including any CSS as SCSS partials in fewer stylesheets to boot.
Yes, but I'd lose all ability to debug my stylesheets in Firebug or Chrome Developer Tools, and that's something I simply can't live without. Frankly, I hate having the server mess with my stylesheets while I'm developing or debugging. I want my line numbers to match, and SCSS simply doesn't offer enough to offset that loss.
def local_stylesheet_link_tag(name)
pattern = File.expand_path("views/#{name}.{scss,sass,css}", Nesta::App.root)
if Dir.glob(pattern).size > 0
haml_tag :link, :href => "/css/#{name}.css", :rel => "stylesheet"
end
end
def css(template, options = {}, locals = {})
defaults, engine = Overrides.render_options(template, :css)
super(template, defaults.merge(options), locals)
end
def stylesheet(template, options = {}, locals = {})
defaults, engine = Overrides.render_options(template, :sass, :scss, :css)
renderer = Sinatra::Templates.instance_method(engine)
renderer.bind(self).call(template, defaults.merge(options), locals)
end
require 'tilt/template'
module Tilt
# Raw Htm (no template functionality). May eventually add syntax validation warnings
class PlainHtmlTemplate < Template
self.default_mime_type = 'text/html'
def self.engine_initialized?
true
end
def prepare
@rawhtml = data
end
def evaluate(scope, locals, &block)
@output ||= @rawhtml
end
end
# Raw css (no template functionality). May eventually add syntax validation warnings
class PlainCssTemplate < Template
self.default_mime_type = 'text/css'
def self.engine_initialized?
true
end
def prepare
@rawhtml = data
end
def evaluate(scope, locals, &block)
@output ||= @rawhtml
end
end
end
While I can see that it's a bit weird for those who aren't familiar with how Sinatra does that, allowing CSS files to appear in views as well as public would seem surprising to people who are already familiar with it. I'd rather "fix" this by documenting where to put your CSS, but I also agree with Wynn's suggestion of using .scss instead. You don't have to use any Sass syntax; just rename your file to .scss and it'll work.
Random aside: I've never had a big problem with line numbers when debugging, and I wonder whether this is a side effect of how I write most of my rules. I use a lot of descendent selectors so can look at the CSS rule in the debugger and immediately skip to the right line in my editor with incremental search.
I found it very unexpected that plain .css files didn't work in Nesta without putting them in /public/. It would nice to be able to mix SCSS and CSS without putting them so far apart.