##// END OF EJS Templates
cleanup: move jsroutes generator function and only generate in...
dan -
r95:d24c04eb default
parent child Browse files
Show More
@@ -0,0 +1,42 b''
1 # -*- coding: utf-8 -*-
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
21 def generate_jsroutes_content(jsroutes):
22 statements = []
23 for url_name, url, fields in jsroutes:
24 statements.append(
25 "pyroutes.register('%s', '%s', %s);" % (url_name, url, fields))
26 return u'''
27 /******************************************************************************
28 * *
29 * DO NOT CHANGE THIS FILE MANUALLY *
30 * *
31 * *
32 * This file is automatically generated when the app starts up. *
33 * *
34 * To add a route here pass jsroute=True to the route definition in the app *
35 * *
36 ******************************************************************************/
37 function registerRCRoutes() {
38 // routes registration
39 %s
40 }
41 ''' % '\n '.join(statements)
42
@@ -27,10 +27,12 b' import logging'
27 import rhodecode
27 import rhodecode
28 import platform
28 import platform
29 import re
29 import re
30 import io
30
31
31 from mako.lookup import TemplateLookup
32 from mako.lookup import TemplateLookup
32 from pylons.configuration import PylonsConfig
33 from pylons.configuration import PylonsConfig
33 from pylons.error import handle_mako_error
34 from pylons.error import handle_mako_error
35 from pyramid.settings import asbool
34
36
35 # don't remove this import it does magic for celery
37 # don't remove this import it does magic for celery
36 from rhodecode.lib import celerypylons # noqa
38 from rhodecode.lib import celerypylons # noqa
@@ -39,6 +41,7 b' import rhodecode.lib.app_globals as app_'
39
41
40 from rhodecode.config import utils
42 from rhodecode.config import utils
41 from rhodecode.config.routing import make_map
43 from rhodecode.config.routing import make_map
44 from rhodecode.config.jsroutes import generate_jsroutes_content
42
45
43 from rhodecode.lib import helpers
46 from rhodecode.lib import helpers
44 from rhodecode.lib.auth import set_available_permissions
47 from rhodecode.lib.auth import set_available_permissions
@@ -51,7 +54,6 b' from rhodecode.model.scm import ScmModel'
51
54
52 log = logging.getLogger(__name__)
55 log = logging.getLogger(__name__)
53
56
54
55 def load_environment(global_conf, app_conf, initial=False,
57 def load_environment(global_conf, app_conf, initial=False,
56 test_env=None, test_index=None):
58 test_env=None, test_index=None):
57 """
59 """
@@ -80,34 +82,15 b' def load_environment(global_conf, app_co'
80 config['app_conf'].get('celery.always.eager'))
82 config['app_conf'].get('celery.always.eager'))
81
83
82 config['routes.map'] = make_map(config)
84 config['routes.map'] = make_map(config)
83 jsroutes = config['routes.map'].jsroutes()
85
84 statements = []
86 if asbool(config['debug']):
85 for url_name, url, fields in jsroutes:
87 jsroutes = config['routes.map'].jsroutes()
86 statements.append(
88 jsroutes_file_content = generate_jsroutes_content(jsroutes)
87 "pyroutes.register('%s', '%s', %s);" % (url_name, url, fields))
89 jsroutes_file_path = os.path.join(
88 import io
90 paths['static_files'], 'js', 'rhodecode', 'routes.js')
89 import textwrap
91
90 template = textwrap.dedent(u'''
92 with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f:
91 /******************************************************************************
93 f.write(jsroutes_file_content)
92 * *
93 * DO NOT CHANGE THIS FILE MANUALLY *
94 * *
95 * *
96 * This file is automatically generated when the app starts up. *
97 * *
98 * To add a route here pass jsroute=True to the route definition in the app *
99 * *
100 ******************************************************************************/
101 function registerRCRoutes() {
102 // routes registration
103 %s
104 }
105 ''').strip()
106 content = template % '\n '.join(statements)
107 js_routes_filepath = os.path.join(
108 paths['static_files'], 'js', 'rhodecode', 'routes.js')
109 with io.open(js_routes_filepath, 'w', encoding='utf-8') as f:
110 f.write(content)
111
94
112 config['pylons.app_globals'] = app_globals.Globals(config)
95 config['pylons.app_globals'] = app_globals.Globals(config)
113 config['pylons.h'] = helpers
96 config['pylons.h'] = helpers
@@ -580,6 +580,8 b' def make_map(config):'
580 action='index', conditions={'method': ['GET']})
580 action='index', conditions={'method': ['GET']})
581 m.connect('new_gist', '/gists/new', jsroute=True,
581 m.connect('new_gist', '/gists/new', jsroute=True,
582 action='new', conditions={'method': ['GET']})
582 action='new', conditions={'method': ['GET']})
583 m.connect('gists', '/gists', jsroute=True,
584 action='index', conditions={'method': ['GET']})
583
585
584 m.connect('/gists/{gist_id}',
586 m.connect('/gists/{gist_id}',
585 action='delete', conditions={'method': ['DELETE']})
587 action='delete', conditions={'method': ['DELETE']})
@@ -1,3 +1,4 b''
1
1 /******************************************************************************
2 /******************************************************************************
2 * *
3 * *
3 * DO NOT CHANGE THIS FILE MANUALLY *
4 * DO NOT CHANGE THIS FILE MANUALLY *
@@ -16,6 +17,7 b' function registerRCRoutes() {'
16 pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']);
17 pyroutes.register('edit_user_group_members', '/_admin/user_groups/%(user_group_id)s/edit/members', ['user_group_id']);
17 pyroutes.register('gists', '/_admin/gists', []);
18 pyroutes.register('gists', '/_admin/gists', []);
18 pyroutes.register('new_gist', '/_admin/gists/new', []);
19 pyroutes.register('new_gist', '/_admin/gists/new', []);
20 pyroutes.register('gists', '/_admin/gists', []);
19 pyroutes.register('toggle_following', '/_admin/toggle_following', []);
21 pyroutes.register('toggle_following', '/_admin/toggle_following', []);
20 pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']);
22 pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']);
21 pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']);
23 pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']);
@@ -46,4 +48,4 b' function registerRCRoutes() {'
46 pyroutes.register('files_metadata_list_home', '/%(repo_name)s/metadata_list/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']);
48 pyroutes.register('files_metadata_list_home', '/%(repo_name)s/metadata_list/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']);
47 pyroutes.register('summary_home_slash', '/%(repo_name)s/', ['repo_name']);
49 pyroutes.register('summary_home_slash', '/%(repo_name)s/', ['repo_name']);
48 pyroutes.register('summary_home', '/%(repo_name)s', ['repo_name']);
50 pyroutes.register('summary_home', '/%(repo_name)s', ['repo_name']);
49 } No newline at end of file
51 }
General Comments 0
You need to be logged in to leave comments. Login now