本文整理汇总了Python中compressor.js.JsCompressor.get_filecontent方法的典型用法代码示例。如果您正苦于以下问题:Python JsCompressor.get_filecontent方法的具体用法?Python JsCompressor.get_filecontent怎么用?Python JsCompressor.get_filecontent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类compressor.js.JsCompressor
的用法示例。
在下文中一共展示了JsCompressor.get_filecontent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RequireJSPrecompiler
# 需要导入模块: from compressor.js import JsCompressor [as 别名]
# 或者: from compressor.js.JsCompressor import get_filecontent [as 别名]
class RequireJSPrecompiler(FilterBase):
def __init__(self, content, attrs=None, filter_type=None, charset=None, filename=None):
self.content = content
self.attrs = attrs
self.filter_type = filter_type
self.filename = filename
self.charset = charset
# The RequireJS compiler for building optimized JS
self.requireJSCompiler = RequireJSCompiler()
# Use Django-Compressor's builtin Compressor tools to get the file
# paths and contents of needed files
self.compressor = JsCompressor()
def input(self, **kwargs):
if getattr(django_settings, 'COMPRESS_ENABLED', False):
# Only use the build file to create RequireJS-optimizer content when
# compress is enabled
build_filepath = self.get_filepath(self.attrs.get('data-build'))
global_config = getattr(settings, 'COMPRESSOR_REQUIREJS_GLOBAL_CONFIG', None)
config_path = self.compressor.get_filename(global_config)
paths = self.get_paths_from_required_libs()
return self.requireJSCompiler.requirejs(
build_filepath, config_path=config_path, paths=paths,
charset=self.charset)
else:
# Just return the content of the main file, with no RequireJS
# optimization (i.e., just use async-loading for all modules)
main_file_full_path = self.compressor.get_filename(kwargs['basename'])
return self.compressor.get_filecontent(main_file_full_path, self.charset)
def get_paths_from_required_libs(self):
paths = []
if hasattr(settings, 'COMPRESSOR_REQUIREJS_REQUIRED_LIBS'):
for arg in settings.COMPRESSOR_REQUIREJS_REQUIRED_LIBS.keys():
path = self.get_filepath(settings.COMPRESSOR_REQUIREJS_REQUIRED_LIBS[arg])
if path.endswith('.js'):
path = path[:-3]
paths.append('paths.%s=%s' % (arg, path))
return paths
def get_filepath(self, static_path):
"""
Get the absolute file-path of the the file given its
STATIC_URL-inclusive path.
Returns the file path on the file system.
"""
basename = self.compressor.get_basename(static_path)
return self.compressor.get_filename(basename)