本文整理汇总了Python中scss.Scss.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Scss.compile方法的具体用法?Python Scss.compile怎么用?Python Scss.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scss.Scss
的用法示例。
在下文中一共展示了Scss.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scss_compile
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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')
示例2: __call__
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
def __call__(self, scss, system):
parser = Scss(scss_opts=self.options)
if 'request' in system:
request = system['request']
request.response_content_type = 'text/css'
if not self.options.get('cache', False) or scss not in self.cache:
Logger.info('caching %s', request.matchdict.get('css_path'))
self.cache[scss] = parser.compile(scss)
return self.cache.get(scss)
return parser.compile(scss)
示例3: draw_css_button
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
def draw_css_button(width=200, height=50, text='This is a button', color=rgb(200,100,50)):
""" Draws a simple CSS button. """
# TODO: once we've decided on a scss compiler, import it at the top instead
from scss import Scss
# TODO: make this customizable
css_class = 'button'
html = '<a class="{0}" href="TODO">{1}</a>'.format(css_class, text)
css = Scss()
scss_str = "a.{0} {{color: red + green;}}".format(css_class)
css.compile(scss_str)
示例4: __call__
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
def __call__(self, scss, system):
parser = Scss(scss_opts=self.options)
if "request" in system:
request = system.get("request")
request.response.content_type = "text/css"
key = request.matchdict.get("css_path")
if not self.options.get("cache", False) or key not in self.cache:
Logger.info("generating %s", key)
self.cache[key] = parser.compile(scss)
return self.cache.get(key)
return parser.compile(scss)
示例5: do_build
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
def do_build(options, args):
if options.output is not None:
output = open(options.output, "wt")
else:
output = sys.stdout
css = Scss(scss_opts={"compress": options.compress, "debug_info": options.debug_info})
if args:
for path in args:
output.write(css.compile(scss_file=path, is_sass=options.is_sass))
else:
output.write(css.compile(sys.stdin.read(), is_sass=options.is_sass))
for f, t in profiling.items():
sys.stderr.write("%s took %03fs" % (f, t))
示例6: do_build
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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))
示例7: compile_assets
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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)
示例8: main
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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 )
示例9: _convert
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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()
示例10: preprocessCSS
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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()
示例11: compile_scss
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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)
示例12: test_debug_info
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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
示例13: StaticCompiler
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
class StaticCompiler(object):
"""
Static files minifier.
"""
def __init__(self, path):
self.css_parser = Scss()
scss.LOAD_PATHS = path
def compile_file(self, filepath, need_compilation=True):
result = self.get_content(filepath)
if need_compilation:
mimetype = mimetypes.guess_type(filepath)[0]
result = self.compile_text(result, mimetype)
return result
def compile_text(self, text, mimetype):
result = ""
if mimetype == "text/css":
result = self.css_parser.compile(text)
elif mimetype == "application/javascript":
result = jsmin(text)
else:
result = text
return result
def get_content(self, file):
return open(file).read()
示例14: ScssTemplate
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
class ScssTemplate(Template):
default_mime_type = 'text/css'
@staticmethod
def is_engine_initialized():
return 'Scss' in globals()
def initialize_engine(self):
global Scss
from scss import Scss
def prepare(self):
self.engine = Scss(scss_opts=self.sass_options())
def sass_options(self):
options = self._options
options.update({
'filename': self.eval_file(),
'line': self._line,
'syntax':'scss'
})
return options
def evaluate(self,scope, locals, block=None):
if not hasattr(self,'output') or not self.output:
self.output = self.engine.compile(self.data)
return self.output
示例15: test_extend_across_files
# 需要导入模块: from scss import Scss [as 别名]
# 或者: from scss.Scss import compile [as 别名]
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