def declare_app(config_file, setup_func=None, instance_dir=None, **kw): """ Create an application instance from a config_file. """ from glashammer.utils.yconfig import yconfig_setup if instance_dir is None: instance_dir = sibpath(config_file, "instance") app = make_app(yconfig_setup(config_file, setup_func), instance_dir, **kw) return app
def setup_auth(app, add_auth_views=True): """ Setup the application to use auth. `add_auth_views` If True, the views for /login and /logout are created for you. This is the reference implementation that you may or may not want to replace. """ app.add_setup(setup_sessions) app.add_config_var('auth/token_key', str, 'auth_session_key') app.add_template_searchpath(sibpath(__file__, 'templates')) if add_auth_views: app.add_url('/login', endpoint='auth/login', view=view_login) app.add_url('/logout', endpoint='auth/logout', view=view_logout)
def setup_forms(app): app.add_template_searchpath(sibpath(__file__, 'templates'))
def default_setup_func(app): app.add_template_searchpath(sibpath(__file__, "templates"))
def setup_app(app, config=config, setup_func=setup_func): # empty config file if config is None: return if setup_func is not None: app.add_setup(setup_func) # settings for bundle in Bundles(config.get('bundles')): if bundle.value is not None: app.add_setup(bundle.value) else: print 'bad bundle %r' % bundle.u # what to do if it is None? # Warning? # urls urls = Urls() urls.set(config.get('urls', [])) if urls.validate(): for url in urls.value: app.add_url(url['url'], url['endpoint'], url.get('view')) else: print 'failed' print [g.error for g in urls.all_children] for f in TemplateFilters( config.get('template_filters', []) ): if f['filter'] is not None: app.add_template_filter(f['name'].value, f['filter'].value) for searchpath in TemplateSearchPaths( config.get('template_searchpaths', []) ): sp = searchpath.value if not os.path.isabs(sp): sp = sibpath(config_file, sp) app.add_template_searchpath(sp) for sharedpath in SharedPaths( config.get('shared', []) ): p = sharedpath.value if not os.path.isabs(p['path']): p['path'] = sibpath(config_file, p['path']) app.add_shared(p['name'], p['path']) for a in Appliances( config.get('appliances', []) ): appliance = a.value['import']( mountpoint_path=a.value['mountpoint_path']) app.add_setup(appliance)
def test_sibpath(): assert sibpath('foo', 'blah') == 'blah' assert sibpath('/foo/boo', 'blah') == '/foo/blah'
def setup(app): app.add_setup(setup_jquery) app.add_template_searchpath(sibpath(__file__, 'templates')) app.add_url('/', endpoint='index', view=hello_view) app.add_url('/svc', endpoint='service', view=HelloService())
def get_package_path(self, path): return sibpath(self.module.__file__, path)
# -*- coding: utf-8 -*- from os.path import dirname from glashammer.application import make_app from glashammer.utils import run_very_simple, sibpath from glashammer.bundles.couchdbdb import setup_couchdb TEMPLATES_DIRECTORY = sibpath(__file__, 'templates') SHARED_DIRECTORY = sibpath(__file__, 'shared') # Main application setup def setup(app): app.add_template_searchpath(TEMPLATES_DIRECTORY) app.add_shared('main', SHARED_DIRECTORY) app.add_setup(setup_couchdb) # Hook for gh-admin def create_app(): app = make_app(setup, dirname(__file__)) return app if __name__ == '__main__': app = create_app() run_very_simple(app)
def setup_jquery(app): app.add_template_searchpath(sibpath(__file__, 'templates'))
from glashammer.application import make_app as make_app_glas from glashammer.utils import run_very_simple, Response, sibpath, local from kouyou import views, forms from kouyou.db import BoardManager template_path = sibpath(__file__, 'templates') def setup(app): app.add_template_searchpath(template_path) app.add_url('/', 'site/index') app.add_url('/<string(maxlength=3):board_code>', 'board/index') app.add_url('/<string(maxlength=3):board_code>/<int:page>', 'board/index') app.add_url('/<string(maxlength=3):board_code>/newpost', 'thread/new') app.add_url('/<string(maxlength=3):board_code>/<string:thread_id>', 'thread/index') app.add_url('/<string(maxlength=3):board_code>/<string:thread_id>/reply', 'thread/reply') app.add_view('thread/new', forms.do_post) app.add_view('thread/reply', forms.do_post) app.add_view('board/index', views.board) app.add_view('thread/index', views.thread) app.add_view('site/index', views.index) setup_template_globals(app) def make_app(): return make_app_glas(setup) def setup_template_globals(app): bm = BoardManager() boards = bm.get_boards()
# -*- coding: utf-8 -*- from glashammer.application import declare_app from glashammer.utils import run_very_simple, sibpath application = declare_app(sibpath(__file__, "app.yaml")) if __name__ == "__main__": run_very_simple(application)