Skip to content

Commit

Permalink
Merge pull request #3 from afdolriski/edit-sass-feature
Browse files Browse the repository at this point in the history
Fixed the libsass package taking a long time to create the Masonite framework
  • Loading branch information
josephmancuso committed Jan 11, 2018
2 parents 54ee71c + d24c82a commit b591785
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
docs
masonite.egg-info
venv
venv
.vscode
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

39 changes: 22 additions & 17 deletions masonite/storage.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
from config import storage, application
import os
import sass

class Storage(object):

def __init__(self):
pass

# this function will compile sass files only if the libsass module installed
def compile_sass(self):
matches = []
for files in storage.SASSFILES['importFrom']:
for root, dirnames, filenames in os.walk(os.path.join(application.BASE_DIRECTORY, files)):
for filename in filenames:
if filename.endswith(('.sass', '.scss')) and not filename.startswith('_'):
matches.append(os.path.join(root, filename))
try:
import sass
except ImportError as e:
pass
else:
matches = []
for files in storage.SASSFILES['importFrom']:
for root, dirnames, filenames in os.walk(os.path.join(application.BASE_DIRECTORY, files)):
for filename in filenames:
if filename.endswith(('.sass', '.scss')) and not filename.startswith('_'):
matches.append(os.path.join(root, filename))

for filename in matches:
with open(filename) as f:
compiled_sass = sass.compile(
string=f.read(), include_paths=storage.SASSFILES['includePaths']
)
name = filename.split(os.sep)[-1].replace('.scss', '').replace('.sass', '')
write_file = os.path.join(os.path.join(application.BASE_DIRECTORY,
storage.SASSFILES['compileTo']), '{0}.css'.format(name))
with open(write_file, 'w') as r:
r.write(compiled_sass)
for filename in matches:
with open(filename) as f:
compiled_sass = sass.compile(
string=f.read(), include_paths=storage.SASSFILES['includePaths']
)
name = filename.split(os.sep)[-1].replace('.scss', '').replace('.sass', '')
write_file = os.path.join(os.path.join(application.BASE_DIRECTORY,
storage.SASSFILES['compileTo']), '{0}.css'.format(name))
with open(write_file, 'w') as r:
r.write(compiled_sass)

0 comments on commit b591785

Please sign in to comment.