当前位置: 首页>>代码示例>>Python>>正文


Python cssmin.cssmin方法代码示例

本文整理汇总了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) 
开发者ID:yubang,项目名称:modular_front,代码行数:9,代码来源:static_minify.py

示例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) 
开发者ID:jimmy201602,项目名称:django-gateone,代码行数:49,代码来源:utils.py

示例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() 
开发者ID:reahl,项目名称:reahl,代码行数:48,代码来源:fw.py


注:本文中的cssmin.cssmin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。