當前位置: 首頁>>代碼示例>>Python>>正文


Python JsCompressor.group_contents方法代碼示例

本文整理匯總了Python中compressor.js.JsCompressor.group_contents方法的典型用法代碼示例。如果您正苦於以下問題:Python JsCompressor.group_contents方法的具體用法?Python JsCompressor.group_contents怎麽用?Python JsCompressor.group_contents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在compressor.js.JsCompressor的用法示例。


在下文中一共展示了JsCompressor.group_contents方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: CompressorGroupFirstTestCase

# 需要導入模塊: from compressor.js import JsCompressor [as 別名]
# 或者: from compressor.js.JsCompressor import group_contents [as 別名]
class CompressorGroupFirstTestCase(TestCase):
    def setUp(self):
        settings.COMPRESS_ENABLED = True
        settings.COMPRESS_PRECOMPILERS = {}
        self.css = """\
<link rel="stylesheet" href="/media/css/one.css" type="text/css" />
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="/media/css/one.less" type="text/less" />
<link rel="stylesheet" href="/media/css/two.less" type="text/less" />"""
        self.css_node = CssCompressor(self.css)
        self.css_node.opts = {"group_first": "true"}

        self.js = """\
<script src="/media/js/one.js" type="text/javascript"></script>
<script type="text/javascript">obj.value = "value";</script>
<script src="/media/js/one.coffee" type="text/coffeescript"></script>
<script src="/media/js/two.coffee" type="text/coffeescript"></script>"""
        self.js_node = JsCompressor(self.js)

    def test_css_group(self):
        out = [
            [
                SOURCE_HUNK,
                u"body { background:#990; }p { border:5px solid green;}",
                u"css/one.css",
                u'<link rel="stylesheet" href="/media/css/one.css" type="text/css" /><style type="text/css">p { border:5px solid green;}</style>',
            ],
            [
                SOURCE_HUNK,
                u"body { background:#990; }body { color:#fff; }",
                u"css/one.less",
                u'<link rel="stylesheet" href="/media/css/one.less" type="text/less" /><link rel="stylesheet" href="/media/css/two.less" type="text/less" />',
            ],
        ]
        split = self.css_node.group_contents()
        split = [[x[0], x[1], x[2], make_elems_str(self.css_node.parser, x[3])] for x in split]
        self.assertEqual(out, split)

    def test_css_single(self):
        css_node = CssCompressor("""<link rel="stylesheet" href="/media/css/one.css" type="text/css" />""")
        css_node.opts = {"group_first": "true"}
        out = [
            [
                SOURCE_FILE,
                os.path.join(settings.COMPRESS_ROOT, u"css", u"one.css"),
                u"css/one.css",
                u'<link rel="stylesheet" href="/media/css/one.css" type="text/css" />',
            ]
        ]
        split = css_node.group_contents()
        split = [[x[0], x[1], x[2], make_elems_str(self.css_node.parser, x[3])] for x in split]
        self.assertEqual(out, split)

    def test_js_group(self):
        out = [
            [
                SOURCE_HUNK,
                u'obj = {};obj.value = "value";',
                u"js/one.js",
                '<script src="/media/js/one.js" type="text/javascript"></script><script type="text/javascript">obj.value = "value";</script>',
            ],
            [
                SOURCE_HUNK,
                u"# this is a comment.\n# this is a comment.",
                u"js/one.coffee",
                '<script src="/media/js/one.coffee" type="text/coffeescript"></script><script src="/media/js/two.coffee" type="text/coffeescript"></script>',
            ],
        ]
        split = self.js_node.group_contents()
        split = [[x[0], x[1], x[2], make_elems_str(self.js_node.parser, x[3])] for x in split]
        self.assertEqual(out, split)
開發者ID:xtranormal,項目名稱:django_compressor,代碼行數:73,代碼來源:test_base.py


注:本文中的compressor.js.JsCompressor.group_contents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。