本文整理匯總了Python中cssmin.cssmin方法的典型用法代碼示例。如果您正苦於以下問題:Python cssmin.cssmin方法的具體用法?Python cssmin.cssmin怎麽用?Python cssmin.cssmin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cssmin
的用法示例。
在下文中一共展示了cssmin.cssmin方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_css
# 需要導入模塊: import cssmin [as 別名]
# 或者: from cssmin import cssmin [as 別名]
def handle_css(css_data):
"""
??css??
:param css_data: css???
:return:
"""
return cssmin.cssmin(css_data)
示例2: minify
# 需要導入模塊: import cssmin [as 別名]
# 或者: from cssmin import cssmin [as 別名]
def minify(path_or_fileobj, kind):
"""
Returns *path_or_fileobj* as a minified string. *kind* should be one of
'js' or 'css'. Works with JavaScript and CSS files using `slimit` and
`cssmin`, respectively.
"""
out = None
try:
import slimit
except ImportError:
slimit = None
try:
import cssmin
except ImportError:
cssmin = None
if isinstance(path_or_fileobj, basestring):
filename = os.path.split(path_or_fileobj)[1]
with io.open(path_or_fileobj, mode='r', encoding='utf-8') as f:
data = f.read()
else:
filename = os.path.split(path_or_fileobj.name)[1]
data = path_or_fileobj.read()
out = data
if slimit and kind == 'js':
if not filename.endswith('min.js'):
try:
out = slimit.minify(data, mangle=True)
logging.debug(_(
"(saved ~%s bytes minifying %s)" % (
(len(data) - len(out), filename)
)
))
except Exception:
logging.error(_("slimit failed trying to minify %s") % filename)
import traceback
traceback.print_exc(file=sys.stdout)
elif cssmin and kind == 'css':
if not filename.endswith('min.css'):
out = cssmin.cssmin(data)
logging.debug(_(
"(saved ~%s bytes minifying %s)" % (
(len(data) - len(out), filename)
)
))
return out
# This is so we can have the argument below be 'minify' (user friendly)
示例3: minifier
# 需要導入模塊: import cssmin [as 別名]
# 或者: from cssmin import cssmin [as 別名]
def minifier(self, relative_name):
class NoOpMinifier(object):
def minify(self, input_stream, output_stream):
for line in input_stream:
output_stream.write(line)
class JSMinifier(object):
def monkey_patch_ply(self):
# Current version of ply (used by slimit) has a bug in Py3
# See https://github.com/rspivak/slimit/issues/64
from ply import yacc
def __getitem__(self,n):
if isinstance(n, slice):
return self.__getslice__(n.start, n.stop)
if n >= 0: return self.slice[n].value
else: return self.stack[n].value
yacc.YaccProduction.__getitem__ = __getitem__
def minify(self, input_stream, output_stream):
if six.PY3:
self.monkey_patch_ply()
text = cStringIO()
for line in input_stream:
text.write(line)
output_stream.write(slimit.minify(text.getvalue(), mangle=True, mangle_toplevel=True))
class CSSMinifier(object):
def minify(self, input_stream, output_stream):
text = cStringIO()
for line in input_stream:
text.write(line)
output_stream.write(cssmin.cssmin(text.getvalue()))
context = ExecutionContext.get_context()
if context.config.reahlsystem.debug:
return NoOpMinifier()
if relative_name.endswith('.css'):
return CSSMinifier()
elif relative_name.endswith('.js'):
return JSMinifier()
else:
return NoOpMinifier()