本文整理汇总了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)