def test_app_get_config(self): app = Tipfy() self.assertEqual(app.get_config('resources.i18n', 'locale'), 'en_US') self.assertEqual(app.get_config('resources.i18n', 'locale', 'foo'), 'en_US') self.assertEqual(app.get_config('resources.i18n'), { 'locale': 'en_US', 'timezone': 'America/Chicago', 'required': REQUIRED_VALUE, })
def compile_templates(argv=None): """Compiles templates for better performance. This is a command line script. From the buildout directory, run: bin/jinja2_compile It will compile templates from the directory configured for 'templates_dir' to the one configured for 'templates_compiled_target'. At this time it doesn't accept any arguments. """ if argv is None: argv = sys.argv set_gae_sys_path() from config import config app = Tipfy(config=config) template_path = app.get_config('tipfyext.jinja2', 'templates_dir') compiled_path = app.get_config('tipfyext.jinja2', 'templates_compiled_target') if compiled_path is None: raise ValueError('Missing configuration key to compile templates.') if isinstance(template_path, basestring): # A single path. source = os.path.join(app_path, template_path) else: # A list of paths. source = [os.path.join(app_path, p) for p in template_path] target = os.path.join(app_path, compiled_path) # Set templates dir and deactivate compiled dir to use normal loader to # find the templates to be compiled. app.config['tipfyext.jinja2']['templates_dir'] = source app.config['tipfyext.jinja2']['templates_compiled_target'] = None if target.endswith('.zip'): zip_cfg = 'deflated' else: zip_cfg = None old_list_templates = FileSystemLoader.list_templates FileSystemLoader.list_templates = list_templates env = Jinja2.factory(app, 'jinja2').environment env.compile_templates(target, extensions=None, filter_func=filter_templates, zip=zip_cfg, log_function=logger, ignore_errors=False, py_compile=False) FileSystemLoader.list_templates = old_list_templates
def test_get_config(self): app = Tipfy(config={'tipfy': {'foo': 'bar'}}) self.assertEqual(app.get_config('tipfy', 'foo'), 'bar')
def compile_templates(argv=None): """Compiles templates for better performance. This is a command line script. From the buildout directory, run: bin/jinja2_compile It will compile templates from the directory configured for 'templates_dir' to the one configured for 'templates_compiled_target'. At this time it doesn't accept any arguments. """ if argv is None: argv = sys.argv base_path = os.getcwd() app_path = os.path.join(base_path, 'app') gae_path = os.path.join(base_path, 'var/parts/google_appengine') extra_paths = [ app_path, os.path.join(app_path, 'lib'), os.path.join(app_path, 'lib', 'dist'), gae_path, # These paths are required by the SDK. os.path.join(gae_path, 'lib', 'antlr3'), os.path.join(gae_path, 'lib', 'django'), os.path.join(gae_path, 'lib', 'ipaddr'), os.path.join(gae_path, 'lib', 'webob'), os.path.join(gae_path, 'lib', 'yaml', 'lib'), ] sys.path = extra_paths + sys.path from config import config app = Tipfy(config=config) template_path = app.get_config('tipfyext.jinja2', 'templates_dir') compiled_path = app.get_config('tipfyext.jinja2', 'templates_compiled_target') if compiled_path is None: raise ValueError('Missing configuration key to compile templates.') if isinstance(template_path, basestring): # A single path. source = os.path.join(app_path, template_path) else: # A list of paths. source = [os.path.join(app_path, p) for p in template_path] target = os.path.join(app_path, compiled_path) # Set templates dir and deactivate compiled dir to use normal loader to # find the templates to be compiled. app.config['tipfyext.jinja2']['templates_dir'] = source app.config['tipfyext.jinja2']['templates_compiled_target'] = None if target.endswith('.zip'): zip_cfg = 'deflated' else: zip_cfg = None old_list_templates = FileSystemLoader.list_templates FileSystemLoader.list_templates = list_templates env = Jinja2.factory(app, 'jinja2').environment env.compile_templates(target, extensions=None, filter_func=filter_templates, zip=zip_cfg, log_function=logger, ignore_errors=False, py_compile=False) FileSystemLoader.list_templates = old_list_templates
def test_get_config(self): app = Tipfy(config={'tipfy': {'foo': 'bar'}}) self.assertEqual(app.get_config('tipfy', 'foo'), 'bar')