def test_compile_new(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') tmpl = text_type( handlebars.compile_template('test', f, handlebars.compat.NODE_PATH, self.path)[0]) self.assertTrue( os.path.isfile(os.path.join(self.path, 'test-%s-template' % prefix))) self.assertTrue( os.path.isfile( os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)))) self.assertIn('function (Handlebars,depth0,helpers,partials,data) {', tmpl)
def test_compile_existing(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template' % prefix) with open(f1, 'w') as fn: fn.write('existing1') time.sleep(0.01) f2 = os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)) with open(f2, 'w') as fn: fn.write('existing2') tmpl = text_type( handlebars.compile_template('test', f, handlebars.compat.NODE_PATH, self.path)[0]) self.assertEqual('existing2', tmpl)
def test_compile_existing(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template' % prefix) with open(f1, 'w') as fn: fn.write('existing1') time.sleep(0.01) f2 = os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)) with open(f2, 'w') as fn: fn.write('existing2') tmpl = text_type(handlebars.compile_template( 'test', f, handlebars.compat.NODE_PATH, self.path)[0]) self.assertEqual('existing2', tmpl)
def test_compile_no_node(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') tmpl = text_type(handlebars.compile_template( 'test', f, None, self.path)[0]) self.assertTrue(os.path.isfile( os.path.join(self.path, 'test-%s-template' % prefix))) self.assertTrue(os.path.isfile( os.path.join(self.path, 'test-%s-template.pre' % prefix))) self.assertIn('<div>{{test}}</div>', tmpl)
def test_compile_no_node(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') tmpl = text_type( handlebars.compile_template('test', f, None, self.path)[0]) self.assertTrue( os.path.isfile(os.path.join(self.path, 'test-%s-template' % prefix))) self.assertTrue( os.path.isfile( os.path.join(self.path, 'test-%s-template.pre' % prefix))) self.assertIn('<div>{{test}}</div>', tmpl)
def test_compile_new_i18n(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}{{#i18n}}i18n text{{/i18n}}</div>') tmpl, i18n = handlebars.compile_template( 'test', f, handlebars.compat.NODE_PATH, self.path) tmpl = text_type(tmpl) self.assertIn('i18n text', i18n) self.assertTrue(os.path.isfile( os.path.join(self.path, 'test-%s-template.i18n' % prefix))) self.assertEqual( open(os.path.join( self.path, 'test-%s-template' % prefix), 'r').read(), '<div>{{test}}{{#i18n-test}}i18n text{{/i18n-test}}</div>')
def test_compile_new(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') tmpl = text_type(handlebars.compile_template( 'test', f, handlebars.compat.NODE_PATH, self.path)[0]) self.assertTrue(os.path.isfile( os.path.join(self.path, 'test-%s-template' % prefix))) self.assertTrue(os.path.isfile( os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)))) self.assertIn( 'function (Handlebars,depth0,helpers,partials,data) {', tmpl)
def test_compile_existing_i18n(self): """ Skip compilation if it is compiled already """ from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template' % prefix) with open(f1, 'w') as fn: fn.write('existing1') time.sleep(0.01) f2 = os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)) with open(f2, 'w') as fn: fn.write('existing2') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template.i18n' % prefix) with open(f1, 'w') as fn: fn.write('["existing3"]') tmpl, i18n = handlebars.compile_template('test', f, handlebars.compat.NODE_PATH, self.path) self.assertEqual(['existing3'], i18n)
def test_compile_new_i18n(self): from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}{{#i18n}}i18n text{{/i18n}}</div>') tmpl, i18n = handlebars.compile_template('test', f, handlebars.compat.NODE_PATH, self.path) tmpl = text_type(tmpl) self.assertIn('i18n text', i18n) self.assertTrue( os.path.isfile( os.path.join(self.path, 'test-%s-template.i18n' % prefix))) self.assertEqual( open(os.path.join(self.path, 'test-%s-template' % prefix), 'r').read(), '<div>{{test}}{{#i18n-test}}i18n text{{/i18n-test}}</div>')
def test_compile_existing_i18n(self): """ Skip compilation if it is compiled already """ from pyramid_amdjs import handlebars self.cfg['amd.tmpl-cache'] = self.path prefix = os.path.split(self.path)[-1] f = os.path.join(self.path, 'template') with open(f, 'w') as fn: fn.write('<div>{{test}}</div>') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template' % prefix) with open(f1, 'w') as fn: fn.write('existing1') time.sleep(0.01) f2 = os.path.join( self.path, 'test-%s-template.js.%s' % (prefix, handlebars.VERSION)) with open(f2, 'w') as fn: fn.write('existing2') time.sleep(0.01) f1 = os.path.join(self.path, 'test-%s-template.i18n' % prefix) with open(f1, 'w') as fn: fn.write('["existing3"]') tmpl, i18n = handlebars.compile_template( 'test', f, handlebars.compat.NODE_PATH, self.path) self.assertEqual(['existing3'], i18n)