Skip to content

Commit

Permalink
Added a simple sass compiler for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
LongHairedHacker committed Apr 22, 2016
1 parent c775fc6 commit 46afdfb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 0 additions & 2 deletions mixins/assetsmixin.py
@@ -1,6 +1,4 @@
#!/usr/bin/env python2
import os
import shutil

from verdandi.constants import CONTENT_DIRECTORY

Expand Down
39 changes: 39 additions & 0 deletions modules/sassassets.py
@@ -0,0 +1,39 @@
#!/usr/bin/env python2

import os
from pylibsass import sass

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);

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)

sass_file = open(source_path, 'r')
css_file = open(dest_path, 'w')

sass_string = sass_file.read().decode('utf-8')
css_string = sass.compile_str(sass_string)

css_file.write(css_string.encode('utf-8'))

sass_file.close()
css_file.close()
5 changes: 5 additions & 0 deletions requirements.txt
@@ -1,7 +1,12 @@
argh==0.26.1
inotify==0.2.4
Jinja2==2.7.3
Markdown==2.6
MarkupSafe==0.23
pathtools==0.1.2
Pillow==3.1.0
pylibsass==0.1.4
python-dateutil==2.4.2
PyYAML==3.11
six==1.10.0
watchdog==0.8.3

0 comments on commit 46afdfb

Please sign in to comment.