Beispiel #1
0
def test2():
    result = sass.compile_string(
        b'''table.hl {
  margin: 2em 0;
  td.ln {
    text-align: right;
  }
}

li {
  font: {
    family: serif;
    weight: bold;
    size: 1.2em;
  }
}''', '', sass.SASS_STYLE_NESTED)

    expected = b'''table.hl {
  margin: 2em 0; }
  table.hl td.ln {
    text-align: right; }

li {
  font-family: serif;
  font-weight: bold;
  font-size: 1.2em; }
'''

    assert_equal(result, expected)
Beispiel #2
0
def test2():
	result = sass.compile_string(b'''table.hl {
  margin: 2em 0;
  td.ln {
    text-align: right;
  }
}

li {
  font: {
    family: serif;
    weight: bold;
    size: 1.2em;
  }
}''', '', sass.SASS_STYLE_NESTED)

	expected = b'''table.hl {
  margin: 2em 0; }
  table.hl td.ln {
    text-align: right; }

li {
  font-family: serif;
  font-weight: bold;
  font-size: 1.2em; }
'''

	assert_equal(result, expected)
Beispiel #3
0
    def run(self):
        import sass
        path = pathlib.Path().parent / 'src/data/styles/base.scss'
        path2 = pathlib.Path().parent / 'src/data/styles/base.css'

        print("Creating sass")
        with open(path, 'rb') as f:
            scss = f.read()
            css = sass.compile_string(scss)

        with open(path2, 'wb') as f2:
            f2.write(css)
            print(css)

        build_py.run(self)
Beispiel #4
0
def load_style_sheet():
    """Load css styles file and parse to include custom variables."""
    with open(GLOBAL_SASS_STYLES_PATH, 'r') as f:
        sass_data = f.read()

    load_sass_variables(sass_data)

    if sass_module_installed and DEV:
        # Needed on OSX
        try:
            sass_data = sass_data.encode()
        except Exception:
            pass

        try:
            # Using https://github.com/dahlia/libsass-python
            data = sass.compile(string=sass_data)
        except Exception:
            pass

        try:
            # Using https://github.com/pistolero/python-scss
            data = sass.compile_string(sass_data)
        except Exception:
            pass

        # Needed on OSX
        try:
            data = data.decode()
        except Exception:
            pass

        with open(GLOBAL_STYLES_PATH, 'w') as f:
            f.write(data)

    with open(GLOBAL_STYLES_PATH, 'r') as f:
        data = f.read()

    if os.name == 'nt':
        data = data.replace('$IMAGE_PATH',
                            images.IMAGE_PATH.replace('\\', '/'))
    else:
        data = data.replace('$IMAGE_PATH', images.IMAGE_PATH)

    return data
Beispiel #5
0
    def compile(self):
        try:
            import sass
        except ImportError:
            raise CompilerError('Unable to import sass module.')

        with open(self.original, 'r') as fp:
            contents = smart_str('$STATIC_URL: "{0}";\n\n{1}'.format(
                settings.STATIC_URL, fp.read())
            )

        locations = list(get_base_finders_locations())
        locations.append(os.path.dirname(self.original))

        contents = sass.compile_string(
            force_bytes(contents),
            include_paths=force_bytes(':'.join(reversed(locations)))
        )

        self.save_contents(contents)

        return self.new_name
Beispiel #6
0
 def test_compile_string_with_bad_string(self):
     self.assertRaises(sass.CompileError, lambda: sass.compile_string(b'bad string'))
Beispiel #7
0
# find and compile scss files
print '---- Compiling SASS Stylesheets ----'
scss_file_paths = _match_files_recursive(PATH_DIRECTORY_OUTPUT, '*.scss')
for scss_file_path in scss_file_paths:
    # open scss
    scss_file = open(scss_file_path, 'r')
    scss_file_contents = scss_file.read()
    scss_file.close()

    # delete sass file
    os.remove(scss_file_path)

    # compile to css
    try:
        css_file_contents = sass.compile_string(scss_file_contents)
    except Exception as e:
        print 'Error in SASS file {0}:\n{1}'.format(scss_file_path, str(e))
        continue

    # generate css file path
    scss_file_path_head, scss_file_path_tail = os.path.split(scss_file_path)
    scss_file_name = os.path.splitext(scss_file_path_tail)[0]
    css_file_path_tail = scss_file_name + '.css'
    css_file_path = os.path.join(scss_file_path_head, css_file_path_tail)

    # save css file
    css_file = open(css_file_path, 'w')
    css_file.write(css_file_contents)
    css_file.close()
Beispiel #8
0
def test1():
	result = sass.compile_string(b'asd', '', sass.SASS_STYLE_NESTED)
	eq_(result, b'asd')
# find and compile scss files
print '---- Compiling SASS Stylesheets ----'
scss_file_paths = _match_files_recursive(PATH_DIRECTORY_OUTPUT, '*.scss')
for scss_file_path in scss_file_paths:
	# open scss
	scss_file = open(scss_file_path, 'r')
	scss_file_contents = scss_file.read()
	scss_file.close()

	# delete sass file
	os.remove(scss_file_path)

	# compile to css
	try:
		css_file_contents = sass.compile_string(scss_file_contents)
	except Exception as e:
		print 'Error in SASS file {0}:\n{1}'.format(scss_file_path, str(e))
		continue

	# generate css file path
	scss_file_path_head, scss_file_path_tail = os.path.split(scss_file_path)
	scss_file_name = os.path.splitext(scss_file_path_tail)[0]
	css_file_path_tail = scss_file_name + '.css'
	css_file_path = os.path.join(scss_file_path_head, css_file_path_tail)

	# save css file
	css_file = open(css_file_path, 'w')
	css_file.write(css_file_contents)
	css_file.close()
Beispiel #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os, sass
from csscompressor import compress

if sys.version_info < (3, 0):
    reload(sys)
    sys.setdefaultencoding('utf8')
else:
    raw_input = input

file_contents = [open(x, 'r').read() for x in sys.argv[1:]]

print compress(sass.compile_string('\n\n'.join(file_contents)))
Beispiel #11
0
def test1():
    result = sass.compile_string(b'asd', '', sass.SASS_STYLE_NESTED)
    eq_(result, b'asd')
Beispiel #12
0
def test1():
    result = sass.compile_string(b"asd", "", sass.SASS_STYLE_NESTED)
    eq_(result, b"asd")
Beispiel #13
0
 def run(self, source, include_folder):
     source = bytes(source, encoding='utf-8')
     include_folder = include_folder.encode(sys.getfilesystemencoding())
     return sass.compile_string(source, include_folder).decode('utf-8')
Beispiel #14
0
 def test_compile_string(self):
     with file(scss_test_file, 'rb') as scss_file:
         result = sass.compile_string(scss_file.read())
     self.assertEqual(result, compiled_result)
Beispiel #15
0
def compileSass(sassstr):
	return sass.compile_string(sassstr)
 def input(self, **kwargs):
     return sass.compile_string(
         self.content.encode(),
         ':'.join([self.path, get_scss_include_paths()]).encode()
     ).decode()
 def _add_sass(self, path):
   return "%s\n<style>\n%s\n</style>" % (
     self._format_filename(path),
     sass.compile_string(bytes(self._read_file(path), 'utf-8')).decode('utf-8')
   )