|
|
@@ -7,6 +7,7 @@ CSS plugins |
|
|
|
from hyde.plugin import CLTransformer, Plugin |
|
|
|
from hyde.exceptions import HydeException |
|
|
|
|
|
|
|
import os |
|
|
|
import re |
|
|
|
import subprocess |
|
|
|
|
|
|
@@ -306,3 +307,90 @@ class CleverCSSPlugin(Plugin): |
|
|
|
|
|
|
|
return self.clevercss.convert(text, self.settings) |
|
|
|
|
|
|
|
# |
|
|
|
# Sassy CSS |
|
|
|
# |
|
|
|
|
|
|
|
class SassyCSSPlugin(Plugin): |
|
|
|
""" |
|
|
|
The plugin class for SassyCSS |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, site): |
|
|
|
super(SassyCSSPlugin, self).__init__(site) |
|
|
|
try: |
|
|
|
import scss |
|
|
|
except ImportError, e: |
|
|
|
raise HydeException('Unable to import pyScss: ' + e.message) |
|
|
|
else: |
|
|
|
self.scss = scss |
|
|
|
|
|
|
|
def _should_parse_resource(self, resource): |
|
|
|
""" |
|
|
|
Check user defined |
|
|
|
""" |
|
|
|
return resource.source_file.kind == 'scss' and \ |
|
|
|
getattr(resource, 'meta', {}).get('parse', True) |
|
|
|
|
|
|
|
@property |
|
|
|
def options(self): |
|
|
|
""" |
|
|
|
Returns options depending on development mode |
|
|
|
""" |
|
|
|
try: |
|
|
|
mode = self.site.config.mode |
|
|
|
except AttributeError: |
|
|
|
mode = "production" |
|
|
|
|
|
|
|
debug = mode.startswith('dev') |
|
|
|
opts = {'compress': not debug, 'debug_info': debug} |
|
|
|
site_opts = self.settings.get('options', {}) |
|
|
|
opts.update(site_opts) |
|
|
|
return opts |
|
|
|
|
|
|
|
@property |
|
|
|
def vars(self): |
|
|
|
""" |
|
|
|
Returns scss variables. |
|
|
|
""" |
|
|
|
return self.settings.get('vars', {}) |
|
|
|
|
|
|
|
@property |
|
|
|
def includes(self): |
|
|
|
""" |
|
|
|
Returns scss load paths. |
|
|
|
""" |
|
|
|
return self.settings.get('includes', []) |
|
|
|
|
|
|
|
|
|
|
|
def begin_site(self): |
|
|
|
""" |
|
|
|
Find all the sassycss files and set their relative deploy path. |
|
|
|
""" |
|
|
|
self.scss.STATIC_URL = self.site.content_url('/') |
|
|
|
self.scss.STATIC_ROOT = self.site.config.content_root_path.path |
|
|
|
self.scss.ASSETS_URL = self.site.media_url('/') |
|
|
|
self.scss.ASSETS_ROOT = self.site.config.deploy_root_path.child( |
|
|
|
self.site.config.media_root) |
|
|
|
|
|
|
|
for resource in self.site.content.walk_resources(): |
|
|
|
if self._should_parse_resource(resource): |
|
|
|
new_name = resource.source_file.name_without_extension + ".css" |
|
|
|
target_folder = File(resource.relative_deploy_path).parent |
|
|
|
resource.relative_deploy_path = target_folder.child(new_name) |
|
|
|
|
|
|
|
def text_resource_complete(self, resource, text): |
|
|
|
""" |
|
|
|
Run sassycss compiler on text. |
|
|
|
""" |
|
|
|
if not self._should_parse_resource(resource): |
|
|
|
return |
|
|
|
|
|
|
|
includes = [resource.node.path] + self.includes |
|
|
|
includes = [path.rstrip(os.sep) + os.sep for path in includes] |
|
|
|
options = self.options |
|
|
|
if not 'load_paths' in options: |
|
|
|
options['load_paths'] = [] |
|
|
|
options['load_paths'].extend(includes) |
|
|
|
scss = self.scss.Scss(scss_opts=options, scss_vars=self.vars ) |
|
|
|
return scss.compile(text) |