Show More
@@ -87,15 +87,6 b' def load_environment(global_conf, app_co' | |||
|
87 | 87 | |
|
88 | 88 | config['routes.map'] = make_map(config) |
|
89 | 89 | |
|
90 | if asbool(config.get('generate_js_files', 'false')): | |
|
91 | jsroutes = config['routes.map'].jsroutes() | |
|
92 | jsroutes_file_content = generate_jsroutes_content(jsroutes) | |
|
93 | jsroutes_file_path = os.path.join( | |
|
94 | paths['static_files'], 'js', 'rhodecode', 'routes.js') | |
|
95 | ||
|
96 | with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f: | |
|
97 | f.write(jsroutes_file_content) | |
|
98 | ||
|
99 | 90 | config['pylons.app_globals'] = app_globals.Globals(config) |
|
100 | 91 | config['pylons.h'] = helpers |
|
101 | 92 | rhodecode.CONFIG = config |
@@ -53,7 +53,8 b' from rhodecode.lib.middleware.vcs import' | |||
|
53 | 53 | from rhodecode.lib.plugins.utils import register_rhodecode_plugin |
|
54 | 54 | from rhodecode.lib.utils2 import aslist as rhodecode_aslist |
|
55 | 55 | from rhodecode.subscribers import ( |
|
56 |
scan_repositories_if_enabled, write_metadata_if_needed |
|
|
56 | scan_repositories_if_enabled, write_metadata_if_needed, | |
|
57 | write_js_routes_if_enabled) | |
|
57 | 58 | |
|
58 | 59 | |
|
59 | 60 | log = logging.getLogger(__name__) |
@@ -301,6 +302,7 b' def includeme(config):' | |||
|
301 | 302 | # Add subscribers. |
|
302 | 303 | config.add_subscriber(scan_repositories_if_enabled, ApplicationCreated) |
|
303 | 304 | config.add_subscriber(write_metadata_if_needed, ApplicationCreated) |
|
305 | config.add_subscriber(write_js_routes_if_enabled, ApplicationCreated) | |
|
304 | 306 | |
|
305 | 307 | # Set the authorization policy. |
|
306 | 308 | authz_policy = ACLAuthorizationPolicy() |
@@ -17,7 +17,8 b'' | |||
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | ||
|
20 | import io | |
|
21 | import re | |
|
21 | 22 | import datetime |
|
22 | 23 | import logging |
|
23 | 24 | import pylons |
@@ -27,9 +28,13 b' import os' | |||
|
27 | 28 | |
|
28 | 29 | from pyramid.i18n import get_localizer |
|
29 | 30 | from pyramid.threadlocal import get_current_request |
|
31 | from pyramid.interfaces import IRoutesMapper | |
|
32 | from pyramid.settings import asbool | |
|
33 | from pyramid.path import AssetResolver | |
|
30 | 34 | from threading import Thread |
|
31 | 35 | |
|
32 | 36 | from rhodecode.translation import _ as tsf |
|
37 | from rhodecode.config.jsroutes import generate_jsroutes_content | |
|
33 | 38 | |
|
34 | 39 | import rhodecode |
|
35 | 40 | |
@@ -173,6 +178,57 b' def write_metadata_if_needed(event):' | |||
|
173 | 178 | pass |
|
174 | 179 | |
|
175 | 180 | |
|
181 | def write_js_routes_if_enabled(event): | |
|
182 | registry = event.app.registry | |
|
183 | ||
|
184 | mapper = registry.queryUtility(IRoutesMapper) | |
|
185 | _argument_prog = re.compile('\{(.*?)\}|:\((.*)\)') | |
|
186 | ||
|
187 | def _extract_route_information(route): | |
|
188 | """ | |
|
189 | Convert a route into tuple(name, path, args), eg: | |
|
190 | ('show_user', '/profile/%(username)s', ['username']) | |
|
191 | """ | |
|
192 | ||
|
193 | routepath = route.pattern | |
|
194 | pattern = route.pattern | |
|
195 | ||
|
196 | def replace(matchobj): | |
|
197 | if matchobj.group(1): | |
|
198 | return "%%(%s)s" % matchobj.group(1).split(':')[0] | |
|
199 | else: | |
|
200 | return "%%(%s)s" % matchobj.group(2) | |
|
201 | ||
|
202 | routepath = _argument_prog.sub(replace, routepath) | |
|
203 | ||
|
204 | return ( | |
|
205 | route.name, | |
|
206 | routepath, | |
|
207 | [(arg[0].split(':')[0] if arg[0] != '' else arg[1]) | |
|
208 | for arg in _argument_prog.findall(pattern)] | |
|
209 | ) | |
|
210 | ||
|
211 | def get_routes(): | |
|
212 | # pylons routes | |
|
213 | for route in rhodecode.CONFIG['routes.map'].jsroutes(): | |
|
214 | yield route | |
|
215 | ||
|
216 | # pyramid routes | |
|
217 | for route in mapper.get_routes(): | |
|
218 | if not route.name.startswith('__'): | |
|
219 | yield _extract_route_information(route) | |
|
220 | ||
|
221 | if asbool(registry.settings.get('generate_js_files', 'false')): | |
|
222 | static_path = AssetResolver().resolve('rhodecode:public').abspath() | |
|
223 | jsroutes = get_routes() | |
|
224 | jsroutes_file_content = generate_jsroutes_content(jsroutes) | |
|
225 | jsroutes_file_path = os.path.join( | |
|
226 | static_path, 'js', 'rhodecode', 'routes.js') | |
|
227 | ||
|
228 | with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f: | |
|
229 | f.write(jsroutes_file_content) | |
|
230 | ||
|
231 | ||
|
176 | 232 | class Subscriber(object): |
|
177 | 233 | """ |
|
178 | 234 | Base class for subscribers to the pyramid event system. |
General Comments 0
You need to be logged in to leave comments.
Login now