lucuma/Clay — Issue #1: Referring to .scss files as .css
Author: newz2000
Created: 2011-11-30 19:19:37+00:00
State: open

Hi, I was trying this out and I like it a lot. I like the scss integration. I m considering deploying some sites to a static hosting and I'm concerned that *.scss files won't be sent with the correct mime-type. I thought it would be nice to have the clay run process the scss (or less) files when a .css file is requested but not found on the filesystem.

I hacked on the code a little and here's what I have, do you think something like this would be a nice addition, and if so, do you have some suggestions on how I could change it to make it most useful? I'd be happy to submit a patch for review.

From core.py line 72:

def swap_extension(self, path, ext):
data_path = path.split('.')
data_path.pop() # don't need that last part
data_path.append(ext)
return '.'.join(data_path)

def render_view(self, request, path=''):
"""Default controller.
Render the template at `path` guessing it's mimetype.
"""
path = self._normalize_path(path)
try:
content, ext = self.render(path)
mimetype = mimetypes.guess_type('a' + ext)[0] or 'text/plain'
except TemplateNotFound:
return self.not_found()
if content:
return Response(content, mimetype=mimetype)

fullpath = os.path.join(self.views_dir, path)
if not os.path.isfile(fullpath):
if ext == '.css':
# see if there is an scss version instead
scss_path = self.swap_extension(path, 'scss')
less_path = self.swap_extension(path, 'less')

if os.path.isfile(os.path.join(self.views_dir, scss_path)):
return self.render_view(request, scss_path)

if os.path.isfile(os.path.join(self.views_dir, less_path)):
return self.render_view(request, less_path)
return self.not_found()
return send_file(request, fullpath)