refactor: made javascript routes autogenerate based on python routes

This commit is contained in:
Daniel Dourvaris 2016-06-03 15:10:45 +03:00
parent 2e53340908
commit 3041ea6869
6 changed files with 198 additions and 77 deletions

View file

@ -80,6 +80,35 @@ def load_environment(global_conf, app_conf, initial=False,
config['app_conf'].get('celery.always.eager'))
config['routes.map'] = make_map(config)
jsroutes = config['routes.map'].jsroutes()
statements = []
for url_name, url, fields in jsroutes:
statements.append(
"pyroutes.register('%s', '%s', %s);" % (url_name, url, fields))
import io
import textwrap
template = textwrap.dedent(u'''
/******************************************************************************
* *
* DO NOT CHANGE THIS FILE MANUALLY *
* *
* *
* This file is automatically generated when the app starts up. *
* *
* To add a route here pass jsroute=True to the route definition in the app *
* *
******************************************************************************/
function registerRCRoutes() {
// routes registration
%s
}
''').strip()
content = template % '\n '.join(statements)
js_routes_filepath = os.path.join(
paths['static_files'], 'js', 'rhodecode', 'routes.js')
with io.open(js_routes_filepath, 'w', encoding='utf-8') as f:
f.write(content)
config['pylons.app_globals'] = app_globals.Globals(config)
config['pylons.h'] = helpers
rhodecode.CONFIG = config