# HG changeset patch # User Daniel Dourvaris # Date 2016-06-03 12:33:26 # Node ID d24c04eb52b4eac34e866f77830f100d61025e87 # Parent 6379077c8889426ced1d25744e3fb50c5308ac22 cleanup: move jsroutes generator function and only generate in debug mode diff --git a/rhodecode/config/environment.py b/rhodecode/config/environment.py --- a/rhodecode/config/environment.py +++ b/rhodecode/config/environment.py @@ -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_ 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_co 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 diff --git a/rhodecode/config/jsroutes.py b/rhodecode/config/jsroutes.py new file mode 100644 --- /dev/null +++ b/rhodecode/config/jsroutes.py @@ -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 . +# +# 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) + diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -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']}) diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -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']); @@ -46,4 +48,4 @@ function registerRCRoutes() { pyroutes.register('files_metadata_list_home', '/%(repo_name)s/metadata_list/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); pyroutes.register('summary_home_slash', '/%(repo_name)s/', ['repo_name']); pyroutes.register('summary_home', '/%(repo_name)s', ['repo_name']); -} \ No newline at end of file +}