cleanup: move jsroutes generator function and only generate in
debug mode
This commit is contained in:
parent
3041ea6869
commit
04248deccd
4 changed files with 59 additions and 30 deletions
|
|
@ -27,10 +27,12 @@ import logging
|
|||
import rhodecode
|
||||
import platform
|
||||
import re
|
||||
import io
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
from pylons.configuration import PylonsConfig
|
||||
from pylons.error import handle_mako_error
|
||||
from pyramid.settings import asbool
|
||||
|
||||
# don't remove this import it does magic for celery
|
||||
from rhodecode.lib import celerypylons # noqa
|
||||
|
|
@ -39,6 +41,7 @@ import rhodecode.lib.app_globals as app_globals
|
|||
|
||||
from rhodecode.config import utils
|
||||
from rhodecode.config.routing import make_map
|
||||
from rhodecode.config.jsroutes import generate_jsroutes_content
|
||||
|
||||
from rhodecode.lib import helpers
|
||||
from rhodecode.lib.auth import set_available_permissions
|
||||
|
|
@ -51,7 +54,6 @@ from rhodecode.model.scm import ScmModel
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_environment(global_conf, app_conf, initial=False,
|
||||
test_env=None, test_index=None):
|
||||
"""
|
||||
|
|
@ -80,34 +82,15 @@ 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)
|
||||
|
||||
if asbool(config['debug']):
|
||||
jsroutes = config['routes.map'].jsroutes()
|
||||
jsroutes_file_content = generate_jsroutes_content(jsroutes)
|
||||
jsroutes_file_path = os.path.join(
|
||||
paths['static_files'], 'js', 'rhodecode', 'routes.js')
|
||||
|
||||
with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(jsroutes_file_content)
|
||||
|
||||
config['pylons.app_globals'] = app_globals.Globals(config)
|
||||
config['pylons.h'] = helpers
|
||||
|
|
|
|||
42
rhodecode/config/jsroutes.py
Normal file
42
rhodecode/config/jsroutes.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2010-2016 RhodeCode GmbH
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License, version 3
|
||||
# (only), as published by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# This program is dual-licensed. If you wish to learn more about the
|
||||
# RhodeCode Enterprise Edition, including its added features, Support services,
|
||||
# and proprietary license terms, please see https://rhodecode.com/licenses/
|
||||
|
||||
def generate_jsroutes_content(jsroutes):
|
||||
statements = []
|
||||
for url_name, url, fields in jsroutes:
|
||||
statements.append(
|
||||
"pyroutes.register('%s', '%s', %s);" % (url_name, url, fields))
|
||||
return 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
|
||||
}
|
||||
''' % '\n '.join(statements)
|
||||
|
||||
|
|
@ -580,6 +580,8 @@ def make_map(config):
|
|||
action='index', conditions={'method': ['GET']})
|
||||
m.connect('new_gist', '/gists/new', jsroute=True,
|
||||
action='new', conditions={'method': ['GET']})
|
||||
m.connect('gists', '/gists', jsroute=True,
|
||||
action='index', conditions={'method': ['GET']})
|
||||
|
||||
m.connect('/gists/{gist_id}',
|
||||
action='delete', conditions={'method': ['DELETE']})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/******************************************************************************
|
||||
* *
|
||||
* DO NOT CHANGE THIS FILE MANUALLY *
|
||||
|
|
@ -16,6 +17,7 @@ function registerRCRoutes() {
|
|||
pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']);
|
||||
pyroutes.register('gists', '/_admin/gists', []);
|
||||
pyroutes.register('new_gist', '/_admin/gists/new', []);
|
||||
pyroutes.register('gists', '/_admin/gists', []);
|
||||
pyroutes.register('toggle_following', '/_admin/toggle_following', []);
|
||||
pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']);
|
||||
pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue