本文整理汇总了Python中sass.compile方法的典型用法代码示例。如果您正苦于以下问题:Python sass.compile方法的具体用法?Python sass.compile怎么用?Python sass.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sass
的用法示例。
在下文中一共展示了sass.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_scss
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def process_scss():
"""Compiles SCSS into CSS in the Static Assets folder"""
paths = [
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/foundation-sites/scss/'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/motion-ui/src/')
]
# File dirs
app_scss_file = os.path.join(settings.BASE_DIR, 'themes/OLH/assets/scss/app.scss')
app_css_file = os.path.join(settings.BASE_DIR, 'static/OLH/css/app.css')
compiled_css_from_file = sass.compile(filename=app_scss_file, include_paths=paths)
# Open the CSS file and write into it
write_file = open(app_css_file, 'w', encoding="utf-8")
write_file.write(compiled_css_from_file)
示例2: compile_sass
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def compile_sass(source_path, target_path_pattern):
# First generate the content from which we can generate the hashname
log.info("Compiling SCSS.")
output = sass.compile(
filename=str(source_path),
output_style='compressed')
hash = hashlib.sha512(output.encode('utf-8')).hexdigest()[:8]
target_path = str(target_path_pattern).format(hash)
source_map_target_path = target_path + '.map'
output = sass.compile(
filename=str(source_path),
output_style='compressed',
source_map_filename=source_map_target_path)
with open(target_path, 'w') as fp:
fp.write(output[0])
with open(source_map_target_path, 'w') as fp:
fp.write(output[1])
return Path(target_path)
示例3: compile_filename
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def compile_filename(input_file, output_file, **kwargs):
"""Compile and save QtSASS file as CSS.
.. code-block:: python
>>> import qtsass
>>> qtsass.compile_filename("dummy.scss", "dummy.css")
:param input_file: Path to QtSass file.
:param output_file: Path to write Qt compliant CSS.
:param kwargs: Keyword arguments to pass to sass.compile
:returns: CSS string
"""
input_root = os.path.abspath(os.path.dirname(input_file))
kwargs.setdefault('include_paths', [input_root])
with open(input_file, 'r') as f:
string = f.read()
_log.info('Compiling {}...'.format(os.path.normpath(input_file)))
css = compile(string, **kwargs)
output_root = os.path.abspath(os.path.dirname(output_file))
if not os.path.isdir(output_root):
os.makedirs(output_root)
with open(output_file, 'w') as css_file:
css_file.write(css)
_log.info('Created CSS file {}'.format(os.path.normpath(output_file)))
return css
示例4: compile_dirname
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def compile_dirname(input_dir, output_dir, **kwargs):
"""Compiles QtSASS files in a directory including subdirectories.
.. code-block:: python
>>> import qtsass
>>> qtsass.compile_dirname("./scss", "./css")
:param input_dir: Directory containing QtSass files.
:param output_dir: Directory to write compiled Qt compliant CSS files to.
:param kwargs: Keyword arguments to pass to sass.compile
"""
kwargs.setdefault('include_paths', [input_dir])
def is_valid(file_name):
return not file_name.startswith('_') and file_name.endswith('.scss')
for root, _, files in os.walk(input_dir):
relative_root = os.path.relpath(root, input_dir)
output_root = os.path.join(output_dir, relative_root)
fkwargs = dict(kwargs)
fkwargs['include_paths'] = fkwargs['include_paths'] + [root]
for file_name in [f for f in files if is_valid(f)]:
scss_path = os.path.join(root, file_name)
css_file = os.path.splitext(file_name)[0] + '.css'
css_path = os.path.join(output_root, css_file)
if not os.path.isdir(output_root):
os.makedirs(output_root)
compile_filename(scss_path, css_path, **fkwargs)
示例5: process_js
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def process_js():
"""Copies JS from compile into static assets
"""
source_paths = [
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/admin.js'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/app.js'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/footnotes.js'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/table_of_contents.js'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/text_resize.js'),
os.path.join(settings.BASE_DIR, 'themes/OLH/assets/js/toastr.js'),
]
dest_path = os.path.join(settings.BASE_DIR, 'static/OLH/js/app.js')
min_path = os.path.join(settings.BASE_DIR, 'static/OLH/js/app.min.js')
process_js_files(source_paths, dest_path, min_path)
示例6: process_fonts
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def process_fonts():
"""Processes fonts from the compile folder into Static Assets"""
fonts_path = os.path.join(settings.BASE_DIR, 'themes/OLH/assets/fonts/')
static_fonts = os.path.join(settings.BASE_DIR, 'static/OLH/fonts/')
copy_files(fonts_path, static_fonts)
示例7: process_images
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def process_images():
"""Processes images from the compile folder into Static Assets"""
image_path = os.path.join(settings.BASE_DIR, 'themes/OLH/assets/img/')
static_images = os.path.join(settings.BASE_DIR, 'static/OLH/img/')
copy_files(image_path, static_images)
示例8: process_journals
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def process_journals(override_css_dir, paths):
journals = journal_models.Journal.objects.all()
for journal in journals:
# look for SCSS folder and files
scss_files = journal.scss_files
if len(scss_files) == 0:
print('Journal with ID {0} [{1}] has no SCSS to compile'.format(journal.id, journal.name))
else:
print('Journal with ID {0} [{1}]: processing overrides'.format(journal.id, journal.name))
override_css_file = os.path.join(override_css_dir, 'journal{0}_override.css'.format(str(journal.id)))
# we will only process one single SCSS override file for a journal
compiled_css_from_file = sass.compile(filename=scss_files[0], include_paths=paths)
# open the journal CSS override file and write into it
with open(override_css_file, 'w', encoding="utf-8") as write_file:
write_file.write(compiled_css_from_file)
journal_dir = os.path.join(settings.BASE_DIR, 'files', 'journals', str(journal.id))
journal_header_image = os.path.join(journal_dir, 'header.png')
if os.path.isfile(journal_header_image):
print('Journal with ID {0} [{1}]: processing header image'.format(journal.id, journal.name))
dest_path = os.path.join(settings.BASE_DIR, 'static', 'OLH', 'img', 'journal_header{0}.png'.format(journal.id))
copy_file(journal_header_image, dest_path)
示例9: setup_css
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def setup_css(self, folder="."):
import sass
THEME_STYLE = "light"
THEME_COLOR = "#1d781d"
SASS_DIR = os.path.join(os.path.abspath(folder),
self.get_sass_folder())
theme_css = f"$primary-color: {THEME_COLOR};\n"
with open(os.path.join(SASS_DIR, f"{THEME_STYLE}.scss")) as f:
theme_css += f.read()
theme_css += "\n"
with open(os.path.join(SASS_DIR, "base_theme.scss")) as f:
raw_css = theme_css + f.read()
self.CSS = sass.compile(string=raw_css, output_style="compressed")
示例10: get_theme_sass_directories
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def get_theme_sass_directories(themes):
"""
Get sass directories for given themes and system.
Args:
themes (list): list of all the themes for whom to fetch sass directories
Returns:
List of all sass directories that need to be compiled for the given themes.
"""
applicable_dirs = list()
for theme in themes:
# compile sass with theme overrides and place them in theme dir.
applicable_dirs.append({
"sass_source_dir": Path("ecommerce/static/sass/base"),
"css_destination_dir": theme.path / "static" / "css" / "base",
"lookup_paths": [theme.path / "static" / "sass" / "partials"] + SYSTEM_SASS_PATHS,
})
# Now, override existing css with any other sass overrides
theme_sass_dir = theme.path / "static" / "sass" / "base"
if theme_sass_dir.isdir():
applicable_dirs.append({
"sass_source_dir": theme.path / "static" / "sass" / "base",
"css_destination_dir": theme.path / "static" / "css" / "base",
"lookup_paths": [theme.path / "static" / "sass" / "partials"] + SYSTEM_SASS_PATHS,
})
return applicable_dirs
示例11: compile_sass
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
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
示例12: execute_target
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def execute_target(cls, *unused):
_CommonTargets.activate_virtual_environment()
import sass
out_css_dir = os.path.join(IGUANA_STATIC_FILES_DIR, "css")
# use python libsass for compiling the sccs files
# output them to the iguana static files css directory
sass.compile(dirname=(IGUANA_SCSS_DIR, out_css_dir),
output_style="compressed")
示例13: generate_css
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def generate_css():
"""Generate css stylesheet."""
css = sass.compile(filename=CSS_FILE)
css_dir = os.path.join(DESTINATION_DIR, "css")
if not os.path.isdir(css_dir):
os.makedirs(css_dir)
filename = os.path.join(css_dir, "audiotsm.css")
with open(filename, 'w') as fileobj:
fileobj.write(css)
示例14: get_custom_admin_css
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def get_custom_admin_css():
if settings.DEBUG:
return sass.compile(string=get_sass_source())
# cache the css in production
global _compiled_sass
if not _compiled_sass:
_compiled_sass = sass.compile(string=get_sass_source())
return _compiled_sass
示例15: add_arguments
# 需要导入模块: import sass [as 别名]
# 或者: from sass import compile [as 别名]
def add_arguments(self, parser):
"""
Add arguments for update_assets command.
Args:
parser (django.core.management.base.CommandParser): parsed for parsing command line arguments.
"""
# Named (optional) arguments
parser.add_argument(
'--themes',
type=str,
nargs='+',
default=["all"],
help="List of themes whose sass need to compiled. Or 'no'/'all' to compile for no/all themes.",
)
parser.add_argument(
'--output-style',
type=str,
dest='output_style',
default='nested',
help='Coding style for compiled sass (default="nested").',
)
parser.add_argument(
'--skip-system',
dest='system',
action='store_false',
default=True,
help='Skip system sass compilation.',
)
parser.add_argument(
'--enable-source-comments',
dest='source_comments',
action='store_true',
default=False,
help="Add source comments in compiled sass.",
)
parser.add_argument(
'--skip-collect',
dest='collect',
action='store_false',
default=True,
help="Skip collection of static assets.",
)