本文整理匯總了Python中compressor.js.JsCompressor.concat方法的典型用法代碼示例。如果您正苦於以下問題:Python JsCompressor.concat方法的具體用法?Python JsCompressor.concat怎麽用?Python JsCompressor.concat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類compressor.js.JsCompressor
的用法示例。
在下文中一共展示了JsCompressor.concat方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CompressorTestCase
# 需要導入模塊: from compressor.js import JsCompressor [as 別名]
# 或者: from compressor.js.JsCompressor import concat [as 別名]
class CompressorTestCase(TestCase):
def setUp(self):
settings.COMPRESS = True
self.css = """
<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">
<style type="text/css">p { border:5px solid green;}</style>
<link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8">
"""
self.cssNode = CssCompressor(self.css)
self.js = """
<script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">obj.value = "value";</script>
"""
self.jsNode = JsCompressor(self.js)
def test_css_split(self):
out = [
('file', os.path.join(settings.MEDIA_ROOT, u'css/one.css'), u'<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8" />'),
('hunk', u'p { border:5px solid green;}', u'<style type="text/css">p { border:5px solid green;}</style>'),
('file', os.path.join(settings.MEDIA_ROOT, u'css/two.css'), u'<link rel="stylesheet" href="/media/css/two.css" type="text/css" charset="utf-8" />'),
]
split = self.cssNode.split_contents()
split = [(x[0], x[1], self.cssNode.parser.elem_str(x[2])) for x in split]
self.assertEqual(out, split)
def test_css_hunks(self):
out = ['body { background:#990; }', u'p { border:5px solid green;}', 'body { color:#fff; }']
self.assertEqual(out, self.cssNode.hunks)
def test_css_output(self):
out = u'body { background:#990; }\np { border:5px solid green;}\nbody { color:#fff; }'
self.assertEqual(out, self.cssNode.combined)
def test_css_mtimes(self):
is_date = re.compile(r'^\d{10}\.\d$')
for date in self.cssNode.mtimes:
self.assert_(is_date.match(str(float(date))), "mtimes is returning something that doesn't look like a date")
def test_css_return_if_off(self):
settings.COMPRESS = False
self.assertEqual(self.css, self.cssNode.output())
def test_cachekey(self):
is_cachekey = re.compile(r'django_compressor\.\w{12}')
self.assert_(is_cachekey.match(self.cssNode.cachekey), "cachekey is returning something that doesn't look like r'django_compressor\.\w{12}'")
def test_css_hash(self):
self.assertEqual('f7c661b7a124', self.cssNode.hash)
def test_css_return_if_on(self):
output = u'<link rel="stylesheet" href="/media/cache/css/f7c661b7a124.css" type="text/css">'
self.assertEqual(output, self.cssNode.output().strip())
def test_js_split(self):
out = [('file', os.path.join(settings.MEDIA_ROOT, u'js/one.js'), '<script src="/media/js/one.js" type="text/javascript" charset="utf-8"></script>'),
('hunk', u'obj.value = "value";', '<script type="text/javascript" charset="utf-8">obj.value = "value";</script>')
]
split = self.jsNode.split_contents()
split = [(x[0], x[1], self.jsNode.parser.elem_str(x[2])) for x in split]
self.assertEqual(out, split)
def test_js_hunks(self):
out = ['obj = {};', u'obj.value = "value";']
self.assertEqual(out, self.jsNode.hunks)
def test_js_concat(self):
out = u'obj = {};\nobj.value = "value";'
self.assertEqual(out, self.jsNode.concat())
def test_js_output(self):
out = u'obj={};obj.value="value";'
self.assertEqual(out, self.jsNode.combined)
def test_js_return_if_off(self):
settings.COMPRESS = False
self.assertEqual(self.js, self.jsNode.output())
def test_js_return_if_on(self):
output = u'<script type="text/javascript" src="/media/cache/js/3f33b9146e12.js" charset="utf-8"></script>'
self.assertEqual(output, self.jsNode.output())
def test_custom_output_dir(self):
old_output_dir = settings.OUTPUT_DIR
settings.OUTPUT_DIR = 'custom'
output = u'<script type="text/javascript" src="/media/custom/js/3f33b9146e12.js" charset="utf-8"></script>'
self.assertEqual(output, JsCompressor(self.js).output())
settings.OUTPUT_DIR = ''
output = u'<script type="text/javascript" src="/media/js/3f33b9146e12.js" charset="utf-8"></script>'
self.assertEqual(output, JsCompressor(self.js).output())
settings.OUTPUT_DIR = '/custom/nested/'
output = u'<script type="text/javascript" src="/media/custom/nested/js/3f33b9146e12.js" charset="utf-8"></script>'
self.assertEqual(output, JsCompressor(self.js).output())
settings.OUTPUT_DIR = old_output_dir