本文整理汇总了Python中sass.compile函数的典型用法代码示例。如果您正苦于以下问题:Python compile函数的具体用法?Python compile怎么用?Python compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
if len(sys.argv) != 2:
print "Usage: python sass-cli.py filename.sass"
sys.exit(1)
filename = sys.argv[1]
with codecs.open(filename, encoding="utf-8", mode="r") as f:
print sass.compile(string=f.read())
开发者ID:tOgg1,项目名称:wikipendium.no,代码行数:7,代码来源:scss-cli.py
示例2: sass
def sass(path):
import glob
import sass
for filename in sorted(glob.glob(path)):
print("SCSS compiling %s" % filename)
sass.compile(filename=filename, precision=3)
开发者ID:mchaput,项目名称:bookish,代码行数:7,代码来源:cli.py
示例3: build_rinds
def build_rinds(args):
""" Compile Sass found at rinds in user-specified order """
for rindpath in args.rinds:
print sass.compile(**{
'filename': rindpath,
'output_style': 'compressed' if args.prod else 'expanded',
})
开发者ID:zyrolasting,项目名称:procss,代码行数:7,代码来源:cli.py
示例4: test_compile_string
def test_compile_string(self):
actual = sass.compile(string='a { b { color: blue; } }')
assert actual == 'a b {\n color: blue; }\n'
commented = sass.compile(string='''a {
b { color: blue; }
color: red;
}''', source_comments=True)
assert commented == '''/* line 1, stdin */
a {
color: red; }
/* line 2, stdin */
a b {
color: blue; }
'''
actual = sass.compile(string=u'a { color: blue; } /* 유니코드 */')
self.assertEqual(
u'''@charset "UTF-8";
a {
color: blue; }
/* 유니코드 */
''',
actual
)
self.assertRaises(sass.CompileError, sass.compile,
string='a { b { color: blue; }')
# sass.CompileError should be a subtype of ValueError
self.assertRaises(ValueError, sass.compile,
string='a { b { color: blue; }')
self.assertRaises(TypeError, sass.compile, string=1234)
self.assertRaises(TypeError, sass.compile, string=[])
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:31,代码来源:sasstests.py
示例5: test_compile_string
def test_compile_string(self):
actual = sass.compile(string='a { b { color: blue; } }')
assert actual == 'a b {\n color: blue; }\n'
commented = sass.compile(string='''a {
b { color: blue; }
color: red;
}''', source_comments='line_numbers')
assert commented == '''/* line 1, source string */
a {
color: red; }
/* line 2, source string */
a b {
color: blue; }
'''
actual = sass.compile(string=u'a { color: blue; } /* 유니코드 */')
self.assertEqual(
u'''a {
color: blue; }
/* 유니코드 */''',
actual
)
self.assertRaises(sass.CompileError, sass.compile,
string='a { b { color: blue; }')
# sass.CompileError should be a subtype of ValueError
self.assertRaises(ValueError, sass.compile,
string='a { b { color: blue; }')
self.assertRaises(TypeError, sass.compile, string=1234)
self.assertRaises(TypeError, sass.compile, string=[])
# source maps are available only when the input is a filename
self.assertRaises(sass.CompileError, sass.compile,
string='a { b { color: blue; }',
source_comments='map')
开发者ID:uceo,项目名称:uceo-2015,代码行数:33,代码来源:sasstests.py
示例6: compile_sass
def compile_sass(sass_source_dir, css_destination_dir, lookup_paths, **kwargs):
"""
Compile given sass files.
Exceptions:
ValueError: Raised if sass source directory does not exist.
Args:
sass_source_dir (path.Path): directory path containing source sass files
css_destination_dir (path.Path): directory path where compiled css files would be placed
lookup_paths (list): a list of all paths that need to be consulted to resolve @imports from sass
Returns:
A tuple containing sass source dir, css destination dir and duration of sass compilation process
"""
output_style = kwargs.get('output_style', 'compressed')
source_comments = kwargs.get('source_comments', False)
start = datetime.datetime.now()
if not sass_source_dir.isdir():
logger.warning("Sass dir '%s' does not exist.", sass_source_dir)
raise ValueError("Sass dir '{dir}' must be a valid directory.".format(dir=sass_source_dir))
if not css_destination_dir.isdir():
# If css destination directory does not exist, then create one
css_destination_dir.mkdir_p()
sass.compile(
dirname=(sass_source_dir, css_destination_dir),
include_paths=lookup_paths,
source_comments=source_comments,
output_style=output_style,
)
duration = datetime.datetime.now() - start
return sass_source_dir, css_destination_dir, duration
开发者ID:BehavioralInsightsTeam,项目名称:ecommerce,代码行数:35,代码来源:update_assets.py
示例7: build
def build(src_dir, dst_dir, opts):
sass.compile(dirname=(src_dir, dst_dir))
# Copy non-scss files over
for (src_path, dst_path) in futil.pairwalk(src_dir, dst_dir):
if futil.ext(src_path) not in ['.scss', '.swp']:
futil.try_mkdirs(os.path.dirname(dst_path))
shutil.copy2(src_path, dst_path)
开发者ID:undefinedvalue,项目名称:lucidblue,代码行数:8,代码来源:110_compile_sass.py
示例8: compile_sass
def compile_sass(options):
"""
Compile Sass to CSS.
"""
# Note: import sass only when it is needed and not at the top of the file.
# This allows other paver commands to operate even without libsass being
# installed. In particular, this allows the install_prereqs command to be
# used to install the dependency.
import sass
debug = options.get('debug')
force = options.get('force')
systems = getattr(options, 'system', ALL_SYSTEMS)
if isinstance(systems, basestring):
systems = systems.split(',')
if debug:
source_comments = True
output_style = 'nested'
else:
source_comments = False
output_style = 'compressed'
timing_info = []
system_sass_directories = applicable_sass_directories(systems)
all_sass_directories = applicable_sass_directories()
dry_run = tasks.environment.dry_run
for sass_dir in system_sass_directories:
start = datetime.now()
css_dir = sass_dir.parent / "css"
if force:
if dry_run:
tasks.environment.info("rm -rf {css_dir}/*.css".format(
css_dir=css_dir,
))
else:
sh("rm -rf {css_dir}/*.css".format(css_dir=css_dir))
if dry_run:
tasks.environment.info("libsass {sass_dir}".format(
sass_dir=sass_dir,
))
else:
sass.compile(
dirname=(sass_dir, css_dir),
include_paths=SASS_LOAD_PATHS + all_sass_directories,
source_comments=source_comments,
output_style=output_style,
)
duration = datetime.now() - start
timing_info.append((sass_dir, css_dir, duration))
print("\t\tFinished compiling Sass:")
if not dry_run:
for sass_dir, css_dir, duration in timing_info:
print(">> {} -> {} in {}s".format(sass_dir, css_dir, duration))
开发者ID:10clouds,项目名称:edx-platform,代码行数:57,代码来源:assets.py
示例9: test_ignores_underscored_files
def test_ignores_underscored_files(self):
with tempdir() as tmpdir:
input_dir = os.path.join(tmpdir, 'input')
output_dir = os.path.join(tmpdir, 'output')
os.mkdir(input_dir)
write_file(os.path.join(input_dir, 'f1.scss'), '@import "f2";')
write_file(os.path.join(input_dir, '_f2.scss'), 'a{color:red}')
sass.compile(dirname=(input_dir, output_dir))
assert not os.path.exists(os.path.join(output_dir, '_f2.css'))
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:10,代码来源:sasstests.py
示例10: compile_file
def compile_file(self, infile, outfile, outdated=False, force=False):
"""Process sass file."""
myfile = codecs.open(outfile, 'w', 'utf-8')
if settings.DEBUG:
myfile.write(sass.compile(filename=infile))
else:
myfile.write(sass.compile(filename=infile,
output_style='compressed'))
return myfile.close()
开发者ID:sonic182,项目名称:libsasscompiler,代码行数:10,代码来源:__init__.py
示例11: compiled
def compiled():
#begin XML parse
tree = ET.parse(config)
root = tree.getroot()
#create primary scss file
file = open("style.scss", "w")
#download and write imports for all scss files
for x in range(0, len(root)):
if root[x].tag == "links":
for y in range(0, len(root[x])):
#gets array of attributes and puts files in appropriate directories
if len(root[x][y].attrib) > 0:
if 'saveas' in root[x][y].attrib:
if 'folder' in root[x][y].attrib:
try:
os.stat(root[x][y].attrib['folder'])
except:
os.makedirs(root[x][y].attrib['folder'])
if root[x][y].text[:4] == "http":
if not os.path.isfile(root[x][y].attrib["folder"] + "/" + root[x][y].attrib["saveas"]):
urllib.urlretrieve (root[x][y].text, root[x][y].attrib["folder"] + "/" + root[x][y].attrib["saveas"])
if root[x][y].attrib["saveas"][-4:] == "scss" or root[x][y].attrib["saveas"][-4:] == "sass":
file.write("@import \"" + root[x][y].attrib["folder"] + "/" + root[x][y].attrib["saveas"] + "\";\n")
else:
if 'folder' in root[x][y].attrib:
try:
os.stat(root[x][y].attrib['folder'])
except:
os.makedirs(root[x][y].attrib['folder'])
if root[x][y].text[:4] == "http":
if not os.path.isfile(root[x][y].attrib["folder"] + "/" + root[x][y].text.split('/')[-1]):
urllib.urlretrieve (root[x][y].text, root[x][y].attrib["folder"] + "/" + root[x][y].text.split('/')[-1])
if root[x][y].text.split('/')[-1][-4:] == "scss" or root[x][y].text.split('/')[-1][-4:] == "sass":
file.write("@import \"" + root[x][y].attrib["folder"] + "/" + root[x][y].text.split('/')[-1] + "\";\n")
#grabs all other files and drops them in the main directory
else:
if not os.path.isfile(root[x][y].text.split('/')[-1]) and root[x][y].text[:4] == "http":
urllib.urlretrieve (root[x][y].text, root[x][y].text.split('/')[-1])
#close main scss file
file.close()
#compile style.scss
if len(sys.argv) <= 2:
compiledString = sass.compile(filename="style.scss")
else:
for x in range(0, len(sys.argv)):
if sys.argv[x][:1] == "-":
compiledString = sass.compile(filename="style.scss", output_style=sys.argv[x].strip('-'))
#write compiled sass to file
outputFile = open("style.css", "w")
outputFile.write(compiledString)
outputFile.close()
开发者ID:mcglonelevi,项目名称:pysazz,代码行数:55,代码来源:pysazz.py
示例12: test_compile_disallows_arbitrary_arguments
def test_compile_disallows_arbitrary_arguments(self):
for args in (
{'string': 'a{b:c}'},
{'filename': 'test/a.scss'},
{'dirname': ('test', '/dev/null')},
):
with pytest.raises(TypeError) as excinfo:
sass.compile(herp='derp', harp='darp', **args)
msg, = excinfo.value.args
assert msg == (
"compile() got unexpected keyword argument(s) 'harp', 'herp'"
)
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:12,代码来源:sasstests.py
示例13: test_stack_trace_formatting
def test_stack_trace_formatting():
try:
sass.compile(string=u'a{☃')
raise AssertionError('expected to raise CompileError')
except sass.CompileError:
tb = traceback.format_exc()
assert tb.endswith(
'CompileError: Error: Invalid CSS after "a{☃": expected "{", was ""\n'
' on line 1 of stdin\n'
'>> a{☃\n'
' --^\n\n'
)
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:12,代码来源:sasstests.py
示例14: test_error
def test_error(self):
with tempdir() as tmpdir:
input_dir = os.path.join(tmpdir, 'input')
os.makedirs(input_dir)
write_file(os.path.join(input_dir, 'bad.scss'), 'a {')
with pytest.raises(sass.CompileError) as excinfo:
sass.compile(
dirname=(input_dir, os.path.join(tmpdir, 'output'))
)
msg, = excinfo.value.args
assert msg.startswith('Error: Invalid CSS after ')
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:12,代码来源:sasstests.py
示例15: test_compile_string_deprecated_source_comments_line_numbers
def test_compile_string_deprecated_source_comments_line_numbers(self):
source = '''a {
b { color: blue; }
color: red;
}'''
expected = sass.compile(string=source, source_comments=True)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
actual = sass.compile(string=source,
source_comments='line_numbers')
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
assert expected == actual
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:13,代码来源:sasstests.py
示例16: test_compile_filename
def test_compile_filename(self):
actual = sass.compile(filename='test/a.scss')
assert actual == A_EXPECTED_CSS
actual = sass.compile(filename='test/c.scss')
assert actual == C_EXPECTED_CSS
actual = sass.compile(filename='test/d.scss')
assert D_EXPECTED_CSS == actual
actual = sass.compile(filename='test/e.scss')
assert actual == E_EXPECTED_CSS
self.assertRaises(IOError, sass.compile,
filename='test/not-exist.sass')
self.assertRaises(TypeError, sass.compile, filename=1234)
self.assertRaises(TypeError, sass.compile, filename=[])
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:13,代码来源:sasstests.py
示例17: test_compile_filename
def test_compile_filename(self):
actual = sass.compile(filename='test/a.scss')
assert actual == A_EXPECTED_CSS
actual = sass.compile(filename='test/c.scss')
assert actual == C_EXPECTED_CSS
actual = sass.compile(filename='test/d.scss')
if text_type is str:
self.assertEqual(D_EXPECTED_CSS, actual)
else:
self.assertEqual(D_EXPECTED_CSS.decode('utf-8'), actual)
self.assertRaises(IOError, sass.compile,
filename='test/not-exist.sass')
self.assertRaises(TypeError, sass.compile, filename=1234)
self.assertRaises(TypeError, sass.compile, filename=[])
开发者ID:uceo,项目名称:uceo-2015,代码行数:14,代码来源:sasstests.py
示例18: compile_sass
def compile_sass():
"""Compiles sass files to css"""
import sass
static_dir = os.path.join(".", "synnefo_admin", "admin", "static")
sass_dir = os.path.join(static_dir, "sass")
css_dir = os.path.join(static_dir, "css")
output_style = "nested" if "develop" in sys.argv else "compressed"
try:
sass.compile(dirname=(sass_dir, css_dir,), output_style=output_style)
except Exception as e:
print(e)
raise Exception('Sass compile failed')
开发者ID:grnet,项目名称:synnefo,代码行数:14,代码来源:setup.py
示例19: test_compile_directories_unicode
def test_compile_directories_unicode(self):
with tempdir() as tmpdir:
input_dir = os.path.join(tmpdir, 'input')
output_dir = os.path.join(tmpdir, 'output')
os.makedirs(input_dir)
with io.open(
os.path.join(input_dir, 'test.scss'), 'w', encoding='UTF-8',
) as f:
f.write(u'a { content: "☃"; }')
# Raised a UnicodeEncodeError in py2 before #82 (issue #72)
# Also raised a UnicodeEncodeError in py3 if the default encoding
# couldn't represent it (such as cp1252 on windows)
sass.compile(dirname=(input_dir, output_dir))
assert os.path.exists(os.path.join(output_dir, 'test.css'))
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:14,代码来源:sasstests.py
示例20: test_importers_raises_exception
def test_importers_raises_exception(self):
def importer(path):
raise ValueError('Bad path: {0}'.format(path))
with assert_raises_compile_error(RegexMatcher(
r'^Error: \n'
r' Traceback \(most recent call last\):\n'
r'.+'
r'ValueError: Bad path: hi\n'
r' on line 1 of stdin\n'
r'>> @import "hi";\n'
r' --------\^\n'
)):
sass.compile(string='@import "hi";', importers=((0, importer),))
开发者ID:lucasmarcelli,项目名称:money-tracker,代码行数:14,代码来源:sasstests.py
注:本文中的sass.compile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论