本文整理汇总了Python中scss.Scss类的典型用法代码示例。如果您正苦于以下问题:Python Scss类的具体用法?Python Scss怎么用?Python Scss使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Scss类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocessCSS
def preprocessCSS (self, targetFile):
from scss import Scss
logging.basicConfig()
scssVariables = {}
scssCompiler = Scss(
scss_vars = None,
scss_opts = {
'compress': True,
# 'debug_info': True,
},
scss_files = self.loadIndividualFilesContent('scss', self.settings['scss']),
# super_selector = None,
# live_errors = False,
# library = ALL_BUILTINS_LIBRARY,
search_paths = [os.path.join(self.absolutePathForSources(), 'scss')]
)
cssFileContent = scssCompiler.compile()
dst = targetFile
dst = os.path.join(os.path.dirname(dst), "_" + os.path.basename(dst))
main.createFolder(os.path.dirname(dst))
file = open(dst, 'w')
file.write(cssFileContent.encode('utf-8'))
file.close()
示例2: _convert
def _convert(src, dst):
css = Scss()
source = codecs.open(src, 'r', encoding='utf-8').read()
output = css.compile(source)
outfile = codecs.open(dst, 'w', encoding='utf-8')
outfile.write(output)
outfile.close()
示例3: scss
def scss(request, path):
settings = request.registry.settings
cache = asbool(settings['css_cache'])
compress = asbool(settings['css_compress'])
new_css_filename = 'local.css'
asset_path = pkg_resources.resource_filename('devqus', 'static' + path)
asset_prefix = os.path.dirname(path)
new_path = os.path.join(os.path.dirname(asset_path), new_css_filename)
asset_modified = int(os.stat(asset_path).st_mtime)
assetc_modified = None
if os.path.exists(new_path):
assetc_modified = int(os.stat(new_path).st_mtime)
# if the asset has changed recently than the compiled one,
# then we know it has been modified.
if not assetc_modified or asset_modified > assetc_modified:
# Create parser object
scss_compiler = Scss(scss_opts={'compress': compress,
'cache': cache})
asset = scss_compiler.compile(open(asset_path).read())
f = open(new_path, 'w')
f.write(asset)
f.close()
less_asset = os.path.join(asset_prefix, new_css_filename)
return assets_url(request, less_asset)
示例4: sassify
def sassify(file,input,output):
#process scss file using Sass
scss = read_file(file,input)
compiler = Scss(scss_opts={'style':'compact'})
css = compiler.compile(scss)
fileName = file[:-4]+'css'
write_file(fileName,output,css)
示例5: test_debug_info
def test_debug_info():
# nb: debug info doesn't work if the source isn't a file
compiler = Scss(scss_opts=dict(style='expanded', debug_info=True))
compiler._scss_files = {}
compiler._scss_files['input.css'] = """\
div {
color: green;
}
table {
color: red;
}
"""
expected = """\
@media -sass-debug-info{filename{font-family:file\:\/\/input\.css}line{font-family:\\000031}}
div {
color: green;
}
@media -sass-debug-info{filename{font-family:file\:\/\/input\.css}line{font-family:\\000034}}
table {
color: red;
}
"""
output = compiler.compile()
assert expected == output
示例6: compile_assets
def compile_assets(config):
adir = config.pathto('assets')
if not os.path.exists(adir):
print("Warning: no assets directory")
return
scss = Scss()
outdir = config.outpathto('assets')
for (dirpath, dirnames, filenames) in os.walk(adir):
for fn in filenames:
sfn = os.path.join(dirpath, fn)
ddir = os.path.join(outdir, dirpath[len(adir):].lstrip('/'))
makedirs(ddir)
dfn = os.path.join(ddir, fn)
ext = sfn[sfn.rindex('.')+1:]
if ext == "scss":
dfn = dfn[:-4] + 'css'
print("Converting {} to {}".format(sfn, dfn))
with open(sfn, 'r') as sf, open(dfn, 'w') as df:
df.write(scss.compile(sf.read()))
else:
print("Copying {} to {}".format(sfn, dfn))
shutil.copyfile(sfn, dfn)
示例7: scss_compile
def scss_compile(filename):
from scss import Scss
scss = Scss(search_paths=[os.path.dirname(filename)])
if six.PY3:
return scss.compile(contents(filename))
else:
return scss.compile(contents(filename).encode('utf-8')).decode('utf-8')
示例8: compile_scss
def compile_scss(self, **kwargs):
genwebthemeegg = pkg_resources.get_distribution('genweb.alternatheme')
scssfile = open('{}/genweb/alternatheme/scss/_dynamic.scss'.format(genwebthemeegg.location))
settings = dict(especific1=self.especific1, especific2=self.especific2)
variables_scss = """
$genwebPrimary: {especific1};
$genwebTitles: {especific2};
""".format(**settings)
scss.config.LOAD_PATHS = [
'{}/genweb/alternatheme/bootstrap/scss/compass_twitter_bootstrap'.format(genwebthemeegg.location)
]
css = Scss(scss_opts={
'compress': False,
'debug_info': False,
})
dynamic_scss = ''.join([variables_scss, scssfile.read()])
return css.compile(dynamic_scss)
示例9: test_extend_across_files
def test_extend_across_files():
compiler = Scss(scss_opts=dict(compress=0))
compiler._scss_files = OrderedDict()
compiler._scss_files['first.css'] = '''
@option style:legacy, short_colors:yes, reverse_colors:yes;
.specialClass extends .basicClass {
padding: 10px;
font-size: 14px;
}
'''
compiler._scss_files['second.css'] = '''
@option style:legacy, short_colors:yes, reverse_colors:yes;
.basicClass {
padding: 20px;
background-color: #FF0000;
}
'''
actual = compiler.compile()
expected = """\
.specialClass {
padding: 10px;
font-size: 14px;
}
.basicClass, .specialClass {
padding: 20px;
background-color: #FF0000;
}
"""
assert expected == actual
示例10: main
def main():
current_directory = os.getcwd()
logging.info("Compiling from local files ...")
dashing_dir = os.path.join(current_directory, 'pydashie')
logging.info("Using walk path : %s" % dashing_dir)
fileList = []
for root, subFolders, files in os.walk(dashing_dir):
for fileName in files:
if 'scss' in fileName:
fileList.append(os.path.join(root, fileName))
log.info('Found SCSS to compile: %s' % fileName)
css_output = StringIO.StringIO()
css = Scss()
css_output.write('\n'.join([css.compile(open(filePath).read()) for filePath in fileList]))
fileList = []
for root, subFolders, files in os.walk(dashing_dir):
for fileName in files:
if 'css' in fileName and 'scss' not in fileName:
if not fileName.endswith('~'):
# discard any temporary files
fileList.append(os.path.join(root, fileName))
log.info('Found CSS to append: %s' % fileName)
css_output.write('\n'.join([open(filePath).read() for filePath in fileList]))
app_css_filepath = os.path.join(current_directory, 'pydashie/assets/stylesheets/application.css')
with open(app_css_filepath, 'w') as outfile:
outfile.write(css_output.getvalue())
log.info('Wrote CSS out to : %s' % app_css_filepath )
示例11: do_build
def do_build(options, args):
if options.output is not None:
out = open(options.output, 'wb')
else:
out = sys.stdout
# Get the unencoded stream on Python 3
out = getattr(out, 'buffer', out)
css = Scss(scss_opts={
'style': options.style,
'debug_info': options.debug_info,
})
if args:
source_files = [
SourceFile.from_file(sys.stdin, "<stdin>", is_sass=options.is_sass) if path == '-' else SourceFile.from_filename(path, is_sass=options.is_sass)
for path in args
]
else:
source_files = [
SourceFile.from_file(sys.stdin, "<stdin>", is_sass=options.is_sass)]
encodings = set(source.encoding for source in source_files)
if len(encodings) > 1:
sys.stderr.write(
"Can't combine these files! "
"They have different encodings: {0}\n"
.format(', '.join(encodings))
)
sys.exit(3)
output = css.compile(source_files=source_files)
out.write(output.encode(source_files[0].encoding))
for f, t in profiling.items():
sys.stderr.write("%s took %03fs" % (f, t))
示例12: expandScss
def expandScss(self,header,content,config=None):
from scss import Scss
#TODO offline images
css = Scss(scss_opts={
"compress": config["css-compress"],
})
#TODO scss unicode call
return unicode(css.compile(content))
示例13: get_dev_output
def get_dev_output(self, name, variation, content=None):
compiler = Scss()
# here we support piped output
if not content:
content = super(ScssFilter, self).get_dev_output(name, variation)
return compiler.compile(str(content.encode("utf8")))
示例14: test_unicode_files
def test_unicode_files():
compiler = Scss(scss_opts=dict(style='expanded'))
unicode_input = u"""q {
quotes: "“" "”" "‘" "’";
}
"""
output = compiler.compile(unicode_input)
assert output == unicode_input
示例15: regenerate_scss
def regenerate_scss():
compiler = Scss()
filenames = get_scss_filenames()
for filename in filenames:
with open(filename, 'r') as f:
raw_sass = ''.join(f.readlines())
output = compiler.compile(raw_sass)
output_filename = get_output_filename(filename)
with open(output_filename, 'w') as f:
f.write(output)