2016-04-23 00:42:04 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
|
|
|
|
import os
|
2016-11-15 00:08:36 +01:00
|
|
|
import codecs
|
2016-11-18 18:27:50 +01:00
|
|
|
import sass
|
2016-04-23 00:42:04 +02:00
|
|
|
|
|
|
|
from verdandi.mixins.messagemixin import MessageMixin
|
|
|
|
from verdandi.mixins.rendermixin import RenderMixin
|
|
|
|
from verdandi.mixins.assetsmixin import AssetsMixin
|
|
|
|
|
|
|
|
class SassAssets(MessageMixin, RenderMixin, AssetsMixin):
|
|
|
|
|
|
|
|
def collect_assets(self, output_directory):
|
|
|
|
super(SassAssets, self).collect_assets(output_directory)
|
|
|
|
|
|
|
|
assets = self.get_assets()
|
|
|
|
|
|
|
|
for source, destination in assets:
|
|
|
|
source_path = os.path.join(self.asset_directory, source)
|
|
|
|
dest_path = os.path.join(output_directory, destination);
|
|
|
|
|
2016-11-11 00:25:12 +01:00
|
|
|
dest_dir = os.path.dirname(dest_path)
|
|
|
|
if not os.path.exists(dest_dir):
|
|
|
|
os.makedirs(dest_dir)
|
|
|
|
|
2016-04-23 00:42:04 +02:00
|
|
|
if os.path.isfile(source_path):
|
|
|
|
self.compile_file(source_path, dest_path)
|
|
|
|
else:
|
|
|
|
print "Skipping %s is not a file" % source_path
|
|
|
|
|
|
|
|
|
|
|
|
def compile_file(self, source_path, dest_path):
|
|
|
|
print "Compiling %s to %s" % (source_path, dest_path)
|
|
|
|
|
2016-11-11 14:48:32 +01:00
|
|
|
source_dir = os.path.dirname(source_path)
|
|
|
|
original_dir = os.getcwd()
|
|
|
|
|
2016-11-15 00:08:36 +01:00
|
|
|
sass_file = codecs.open(source_path, 'r', 'utf-8')
|
|
|
|
css_file = codecs.open(dest_path, 'w', 'utf-8')
|
2016-04-23 00:42:04 +02:00
|
|
|
|
2016-11-11 14:48:32 +01:00
|
|
|
os.chdir(source_dir)
|
|
|
|
|
2016-11-15 00:08:36 +01:00
|
|
|
sass_string = sass_file.read()
|
2016-11-18 18:27:50 +01:00
|
|
|
css_string = sass.compile(string=sass_string)
|
2016-11-15 00:08:36 +01:00
|
|
|
css_file.write(css_string)
|
2016-04-23 00:42:04 +02:00
|
|
|
|
2016-11-11 14:48:32 +01:00
|
|
|
os.chdir(original_dir)
|
|
|
|
|
2016-04-23 00:42:04 +02:00
|
|
|
sass_file.close()
|
|
|
|
css_file.close()
|