##// END OF EJS Templates
assets: convert pylons static files to pyramid static_url, fixes #3504
dan -
r454:a3b0830f default
parent child Browse files
Show More
@@ -125,8 +125,8 b' rhodecode.api.url = /_admin/api'
125
125
126 full_stack = true
126 full_stack = true
127
127
128 ## Serve static files via RhodeCode, disable to serve them via HTTP server
128 ## Return gzipped responses
129 static_files = true
129 gzip_responses = true
130
130
131 # autogenerate javascript routes file on startup
131 # autogenerate javascript routes file on startup
132 generate_js_files = false
132 generate_js_files = false
@@ -289,23 +289,7 b' def includeme_last(config):'
289 The static file catchall needs to be last in the view configuration.
289 The static file catchall needs to be last in the view configuration.
290 """
290 """
291 settings = config.registry.settings
291 settings = config.registry.settings
292
292 config.add_static_view('_static', path='rhodecode:public')
293 # Note: johbo: I would prefer to register a prefix for static files at some
294 # point, e.g. move them under '_static/'. This would fully avoid that we
295 # can have name clashes with a repository name. Imaging someone calling his
296 # repo "css" ;-) Also having an external web server to serve out the static
297 # files seems to be easier to set up if they have a common prefix.
298 #
299 # Example: config.add_static_view('_static', path='rhodecode:public')
300 #
301 # It might be an option to register both paths for a while and then migrate
302 # over to the new location.
303
304 # Serving static files with a catchall.
305 if settings['static_files']:
306 config.add_route('catchall_static', '/*subpath')
307 config.add_view(
308 static_view('rhodecode:public'), route_name='catchall_static')
309
293
310
294
311 def wrap_app_in_wsgi_middlewares(pyramid_app, config):
295 def wrap_app_in_wsgi_middlewares(pyramid_app, config):
@@ -331,10 +315,7 b' def wrap_app_in_wsgi_middlewares(pyramid'
331 pyramid_app, _ = wrap_in_appenlight_if_enabled(
315 pyramid_app, _ = wrap_in_appenlight_if_enabled(
332 pyramid_app, config.registry._pylons_compat_config)
316 pyramid_app, config.registry._pylons_compat_config)
333
317
334 # TODO: johbo: Don't really see why we enable the gzip middleware when
318 if asbool(settings.get('gzip_responses', 'true')):
335 # serving static files, might be something that should have its own setting
336 # as well?
337 if settings['static_files']:
338 pyramid_app = make_gzip_middleware(
319 pyramid_app = make_gzip_middleware(
339 pyramid_app, settings, compress_level=1)
320 pyramid_app, settings, compress_level=1)
340
321
@@ -377,7 +358,6 b' def sanitize_settings_and_apply_defaults'
377 settings.setdefault('rhodecode.api.url', '/_admin/api')
358 settings.setdefault('rhodecode.api.url', '/_admin/api')
378
359
379 _bool_setting(settings, 'vcs.server.enable', 'true')
360 _bool_setting(settings, 'vcs.server.enable', 'true')
380 _bool_setting(settings, 'static_files', 'true')
381 _bool_setting(settings, 'is_test', 'false')
361 _bool_setting(settings, 'is_test', 'false')
382
362
383 return settings
363 return settings
@@ -85,12 +85,15 b' from rhodecode.model.settings import Iss'
85
85
86 log = logging.getLogger(__name__)
86 log = logging.getLogger(__name__)
87
87
88
88 DEFAULT_USER = User.DEFAULT_USER
89 DEFAULT_USER = User.DEFAULT_USER
89 DEFAULT_USER_EMAIL = User.DEFAULT_USER_EMAIL
90 DEFAULT_USER_EMAIL = User.DEFAULT_USER_EMAIL
90
91
92
91 def url(*args, **kw):
93 def url(*args, **kw):
92 return pylons_url(*args, **kw)
94 return pylons_url(*args, **kw)
93
95
96
94 def pylons_url_current(*args, **kw):
97 def pylons_url_current(*args, **kw):
95 """
98 """
96 This function overrides pylons.url.current() which returns the current
99 This function overrides pylons.url.current() which returns the current
@@ -105,6 +108,19 b' def pylons_url_current(*args, **kw):'
105 url.current = pylons_url_current
108 url.current = pylons_url_current
106
109
107
110
111 def asset(path, ver=None):
112 """
113 Helper to generate a static asset file path for rhodecode assets
114
115 eg. h.asset('images/image.png', ver='3923')
116
117 :param path: path of asset
118 :param ver: optional version query param to append as ?ver=
119 """
120 request = get_current_request()
121 return request.static_url('rhodecode:public/{}'.format(path), ver=ver)
122
123
108 def html_escape(text, html_escape_table=None):
124 def html_escape(text, html_escape_table=None):
109 """Produce entities within text."""
125 """Produce entities within text."""
110 if not html_escape_table:
126 if not html_escape_table:
@@ -7,7 +7,7 b''
7 <div id="header-inner" class="wrapper">
7 <div id="header-inner" class="wrapper">
8 <div id="logo">
8 <div id="logo">
9 <div class="logo-wrapper">
9 <div class="logo-wrapper">
10 <a href="${h.url('home')}"><img src="${h.url('/images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
10 <a href="${h.url('home')}"><img src="${h.asset('images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
11 </div>
11 </div>
12 %if c.rhodecode_name:
12 %if c.rhodecode_name:
13 <div class="branding">- ${h.branding(c.rhodecode_name)}</div>
13 <div class="branding">- ${h.branding(c.rhodecode_name)}</div>
@@ -580,7 +580,7 b''
580 % endif
580 % endif
581
581
582 </script>
582 </script>
583 <script src="${h.url('/js/rhodecode/base/keyboard-bindings.js', ver=c.rhodecode_version_hash)}"></script>
583 <script src="${h.asset('js/rhodecode/base/keyboard-bindings.js', ver=c.rhodecode_version_hash)}"></script>
584 </%def>
584 </%def>
585
585
586 <div class="modal" id="help_kb" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
586 <div class="modal" id="help_kb" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
@@ -23,13 +23,13 b" c.template_context['visual']['default_re"
23 <meta name="robots" content="index, nofollow"/>
23 <meta name="robots" content="index, nofollow"/>
24 </%def>
24 </%def>
25 ${self.robots()}
25 ${self.robots()}
26 <link rel="icon" href="${h.url('/images/favicon.ico', ver=c.rhodecode_version_hash)}" sizes="16x16 32x32" type="image/png" />
26 <link rel="icon" href="${h.asset('images/favicon.ico', ver=c.rhodecode_version_hash)}" sizes="16x16 32x32" type="image/png" />
27
27
28 ## CSS definitions
28 ## CSS definitions
29 <%def name="css()">
29 <%def name="css()">
30 <link rel="stylesheet" type="text/css" href="${h.url('/css/style.css', ver=c.rhodecode_version_hash)}" media="screen"/>
30 <link rel="stylesheet" type="text/css" href="${h.asset('css/style.css', ver=c.rhodecode_version_hash)}" media="screen"/>
31 <!--[if lt IE 9]>
31 <!--[if lt IE 9]>
32 <link rel="stylesheet" type="text/css" href="${h.url('/css/ie.css', ver=c.rhodecode_version_hash)}" media="screen"/>
32 <link rel="stylesheet" type="text/css" href="${h.asset('css/ie.css', ver=c.rhodecode_version_hash)}" media="screen"/>
33 <![endif]-->
33 <![endif]-->
34 ## EXTRA FOR CSS
34 ## EXTRA FOR CSS
35 ${self.css_extra()}
35 ${self.css_extra()}
@@ -42,7 +42,7 b" c.template_context['visual']['default_re"
42
42
43 ## JAVASCRIPT
43 ## JAVASCRIPT
44 <%def name="js()">
44 <%def name="js()">
45 <script src="${h.url('/js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script>
45 <script src="${h.asset('js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script>
46 <script type="text/javascript">
46 <script type="text/javascript">
47 // register templateContext to pass template variables to JS
47 // register templateContext to pass template variables to JS
48 var templateContext = ${h.json.dumps(c.template_context)|n};
48 var templateContext = ${h.json.dumps(c.template_context)|n};
@@ -78,11 +78,11 b" c.template_context['visual']['default_re"
78 </script>
78 </script>
79
79
80 <!--[if lt IE 9]>
80 <!--[if lt IE 9]>
81 <script language="javascript" type="text/javascript" src="${h.url('/js/excanvas.min.js')}"></script>
81 <script language="javascript" type="text/javascript" src="${h.asset('js/excanvas.min.js')}"></script>
82 <![endif]-->
82 <![endif]-->
83 <script language="javascript" type="text/javascript" src="${h.url('/js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script>
83 <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script>
84 <script language="javascript" type="text/javascript" src="${h.url('/js/scripts.js', ver=c.rhodecode_version_hash)}"></script>
84 <script language="javascript" type="text/javascript" src="${h.asset('js/scripts.js', ver=c.rhodecode_version_hash)}"></script>
85 <script>CodeMirror.modeURL = "${h.url('/js/mode/%N/%N.js')}";</script>
85 <script>CodeMirror.modeURL = "${h.asset('js/mode/%N/%N.js')}";</script>
86
86
87 ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates
87 ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates
88 ${self.js_extra()}
88 ${self.js_extra()}
@@ -202,7 +202,7 b''
202 ${c.pagination.pager('$link_previous ~2~ $link_next')}
202 ${c.pagination.pager('$link_previous ~2~ $link_next')}
203 </div>
203 </div>
204
204
205 <script type="text/javascript" src="${h.url('/js/jquery.commits-graph.js')}"></script>
205 <script type="text/javascript" src="${h.asset('js/jquery.commits-graph.js')}"></script>
206 <script type="text/javascript">
206 <script type="text/javascript">
207 var cache = {};
207 var cache = {};
208 $(function(){
208 $(function(){
@@ -9,11 +9,11 b''
9 </%def>
9 </%def>
10
10
11 <%def name="js_extra()">
11 <%def name="js_extra()">
12 <script type="text/javascript" src="${h.url('/js/mergerly.js')}"></script>
12 <script type="text/javascript" src="${h.asset('js/mergerly.js')}"></script>
13 </%def>
13 </%def>
14
14
15 <%def name="css_extra()">
15 <%def name="css_extra()">
16 <link rel="stylesheet" type="text/css" href="${h.url('/css/mergerly.css')}"/>
16 <link rel="stylesheet" type="text/css" href="${h.asset('css/mergerly.css')}"/>
17 </%def>
17 </%def>
18
18
19
19
@@ -507,7 +507,7 b''
507 <td class="td-radio"><input type="radio" value="repository.admin"
507 <td class="td-radio"><input type="radio" value="repository.admin"
508 name="u_perm_1" id="u_perm_1_repositoryadmin"></td>
508 name="u_perm_1" id="u_perm_1_repositoryadmin"></td>
509 <td>
509 <td>
510 <img class="gravatar" src="/images/user30.png" height="16" width="16">
510 <img class="gravatar" src="/_static/images/user30.png" height="16" width="16">
511 <span class="user">default</span>
511 <span class="user">default</span>
512 </td>
512 </td>
513 <td></td>
513 <td></td>
@@ -5,7 +5,7 b''
5 <title>Error - ${c.error_message}</title>
5 <title>Error - ${c.error_message}</title>
6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
6 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
7 <meta name="robots" content="index, nofollow"/>
7 <meta name="robots" content="index, nofollow"/>
8 <link rel="icon" href="${h.url('/images/favicon.ico')}" sizes="16x16 32x32" type="image/png" />
8 <link rel="icon" href="${h.asset('images/favicon.ico')}" sizes="16x16 32x32" type="image/png" />
9
9
10
10
11 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
11 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
@@ -13,20 +13,20 b''
13 <meta http-equiv="refresh" content="${c.redirect_time}; url=${c.url_redirect}"/>
13 <meta http-equiv="refresh" content="${c.redirect_time}; url=${c.url_redirect}"/>
14 %endif
14 %endif
15
15
16 <link rel="stylesheet" type="text/css" href="${h.url('/css/style.css')}" media="screen"/>
16 <link rel="stylesheet" type="text/css" href="${h.asset('css/style.css')}" media="screen"/>
17 <!--[if IE]>
17 <!--[if IE]>
18 <link rel="stylesheet" type="text/css" href="${h.url('/css/ie.css')}" media="screen"/>
18 <link rel="stylesheet" type="text/css" href="${h.asset('css/ie.css')}" media="screen"/>
19 <![endif]-->
19 <![endif]-->
20 <style>body { background:#eeeeee; }</style>
20 <style>body { background:#eeeeee; }</style>
21
21
22 <script type="text/javascript" src="${h.url('/js/scripts.js')}"></script>
22 <script type="text/javascript" src="${h.asset('js/scripts.js')}"></script>
23 </head>
23 </head>
24 <body>
24 <body>
25 <%include file="/base/flash_msg.html"/>
25 <%include file="/base/flash_msg.html"/>
26
26
27 <div class="wrapper error_page">
27 <div class="wrapper error_page">
28 <div class="sidebar">
28 <div class="sidebar">
29 <a href="${h.url('home')}"><img class="error-page-logo" src="${h.url('/images/RhodeCode_Logo_Black.png')}" alt="RhodeCode"/></a>
29 <a href="${h.url('home')}"><img class="error-page-logo" src="${h.asset('images/RhodeCode_Logo_Black.png')}" alt="RhodeCode"/></a>
30 </div>
30 </div>
31 <div class="main-content">
31 <div class="main-content">
32 <h1>
32 <h1>
@@ -4,11 +4,11 b''
4 <%namespace name="diff_block" file="/changeset/diff_block.html"/>
4 <%namespace name="diff_block" file="/changeset/diff_block.html"/>
5
5
6 <%def name="js_extra()">
6 <%def name="js_extra()">
7 <script type="text/javascript" src="${h.url('/js/mergerly.js')}"></script>
7 <script type="text/javascript" src="${h.asset('js/mergerly.js')}"></script>
8 </%def>
8 </%def>
9
9
10 <%def name="css_extra()">
10 <%def name="css_extra()">
11 <link rel="stylesheet" type="text/css" href="${h.url('/css/mergerly.css')}"/>
11 <link rel="stylesheet" type="text/css" href="${h.asset('css/mergerly.css')}"/>
12 </%def>
12 </%def>
13
13
14 <%def name="title()">
14 <%def name="title()">
@@ -14,7 +14,7 b''
14 <div id="header-inner" class="title">
14 <div id="header-inner" class="title">
15 <div id="logo">
15 <div id="logo">
16 <div class="logo-wrapper">
16 <div class="logo-wrapper">
17 <a href="${h.url('home')}"><img src="${h.url('/images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
17 <a href="${h.url('home')}"><img src="${h.asset('images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
18 </div>
18 </div>
19 %if c.rhodecode_name:
19 %if c.rhodecode_name:
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
@@ -25,7 +25,7 b''
25
25
26 <div class="loginwrapper">
26 <div class="loginwrapper">
27 <div class="left-column">
27 <div class="left-column">
28 <img class="sign-in-image" src="${h.url('/images/sign-in.png')}" alt="RhodeCode"/>
28 <img class="sign-in-image" src="${h.asset('images/sign-in.png')}" alt="RhodeCode"/>
29 </div>
29 </div>
30 <%block name="above_login_button" />
30 <%block name="above_login_button" />
31 <div id="login" class="right-column">
31 <div id="login" class="right-column">
@@ -14,7 +14,7 b''
14 <div id="header-inner" class="title">
14 <div id="header-inner" class="title">
15 <div id="logo">
15 <div id="logo">
16 <div class="logo-wrapper">
16 <div class="logo-wrapper">
17 <a href="${h.url('home')}"><img src="${h.url('/images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
17 <a href="${h.url('home')}"><img src="${h.asset('images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
18 </div>
18 </div>
19 %if c.rhodecode_name:
19 %if c.rhodecode_name:
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
@@ -25,7 +25,7 b''
25
25
26 <div class="loginwrapper">
26 <div class="loginwrapper">
27 <div class="left-column">
27 <div class="left-column">
28 <img class="sign-in-image" src="${h.url('/images/sign-in.png')}" alt="RhodeCode"/>
28 <img class="sign-in-image" src="${h.asset('images/sign-in.png')}" alt="RhodeCode"/>
29 </div>
29 </div>
30
30
31 <div id="register" class="right-column">
31 <div id="register" class="right-column">
@@ -14,7 +14,7 b''
14 <div id="header-inner" class="title">
14 <div id="header-inner" class="title">
15 <div id="logo">
15 <div id="logo">
16 <div class="logo-wrapper">
16 <div class="logo-wrapper">
17 <a href="${h.url('home')}"><img src="${h.url('/images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
17 <a href="${h.url('home')}"><img src="${h.asset('images/rhodecode-logo-white-216x60.png')}" alt="RhodeCode"/></a>
18 </div>
18 </div>
19 %if c.rhodecode_name:
19 %if c.rhodecode_name:
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
20 <div class="branding"> ${h.branding(c.rhodecode_name)}</div>
@@ -25,7 +25,7 b''
25
25
26 <div class="loginwrapper">
26 <div class="loginwrapper">
27 <div class="left-column">
27 <div class="left-column">
28 <img class="sign-in-image" src="${h.url('/images/sign-in.png')}" alt="RhodeCode"/>
28 <img class="sign-in-image" src="${h.asset('images/sign-in.png')}" alt="RhodeCode"/>
29 </div>
29 </div>
30 <%block name="above_register_button" />
30 <%block name="above_register_button" />
31 <div id="register" class="right-column">
31 <div id="register" class="right-column">
General Comments 0
You need to be logged in to leave comments. Login now