refactor: made javascript routes autogenerate based on python routes
This commit is contained in:
parent
2e53340908
commit
3041ea6869
6 changed files with 198 additions and 77 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue