Show More
@@ -47,7 +47,7 b' var pyroutes = (function() {' | |||||
47 | } |
|
47 | } | |
48 | return str_format.format.call(null, str_format.cache[arguments[0]], arguments); |
|
48 | return str_format.format.call(null, str_format.cache[arguments[0]], arguments); | |
49 | }; |
|
49 | }; | |
50 |
|
50 | |||
51 | str_format.format = function(parse_tree, argv) { |
|
51 | str_format.format = function(parse_tree, argv) { | |
52 | var cursor = 1, |
|
52 | var cursor = 1, | |
53 | tree_length = parse_tree.length, |
|
53 | tree_length = parse_tree.length, | |
@@ -81,7 +81,7 b' var pyroutes = (function() {' | |||||
81 | else { // positional argument (implicit) |
|
81 | else { // positional argument (implicit) | |
82 | arg = argv[cursor++]; |
|
82 | arg = argv[cursor++]; | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if (/[^s]/.test(match[8]) && (get_type(arg) !== 'number')) { |
|
85 | if (/[^s]/.test(match[8]) && (get_type(arg) !== 'number')) { | |
86 | throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); |
|
86 | throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); | |
87 | } |
|
87 | } | |
@@ -108,9 +108,9 b' var pyroutes = (function() {' | |||||
108 | } |
|
108 | } | |
109 | return output.join(''); |
|
109 | return output.join(''); | |
110 | }; |
|
110 | }; | |
111 |
|
111 | |||
112 | str_format.cache = {}; |
|
112 | str_format.cache = {}; | |
113 |
|
113 | |||
114 | str_format.parse = function(fmt) { |
|
114 | str_format.parse = function(fmt) { | |
115 | var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; |
|
115 | var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; | |
116 | while (_fmt) { |
|
116 | while (_fmt) { | |
@@ -161,12 +161,20 b' var pyroutes = (function() {' | |||||
161 | }; |
|
161 | }; | |
162 | return str_format; |
|
162 | return str_format; | |
163 | })(); |
|
163 | })(); | |
164 |
|
164 | |||
165 | var vsprintf = function(fmt, argv) { |
|
165 | var vsprintf = function(fmt, argv) { | |
166 | argv.unshift(fmt); |
|
166 | argv.unshift(fmt); | |
167 | return sprintf.apply(null, argv); |
|
167 | return sprintf.apply(null, argv); | |
168 | }; |
|
168 | }; | |
169 | return { |
|
169 | return { | |
|
170 | 'asset': function(path, ver) { | |||
|
171 | var asset_url = ASSET_URL || '/_static/'; | |||
|
172 | var ret = asset_url + path; | |||
|
173 | if (ver !== undefined) { | |||
|
174 | ret += '?ver=' + ver; | |||
|
175 | } | |||
|
176 | return ret; | |||
|
177 | }, | |||
170 | 'url': function(route_name, params) { |
|
178 | 'url': function(route_name, params) { | |
171 | var result = route_name; |
|
179 | var result = route_name; | |
172 | if (typeof(params) !== 'object'){ |
|
180 | if (typeof(params) !== 'object'){ | |
@@ -179,18 +187,18 b' var pyroutes = (function() {' | |||||
179 | var param_name = route[1][i]; |
|
187 | var param_name = route[1][i]; | |
180 | if (!params.hasOwnProperty(param_name)) |
|
188 | if (!params.hasOwnProperty(param_name)) | |
181 | throw new Error( |
|
189 | throw new Error( | |
182 |
'parameter '+ |
|
190 | 'parameter '+ | |
183 |
param_name + |
|
191 | param_name + | |
184 |
' is missing in route"' + |
|
192 | ' is missing in route"' + | |
185 | route_name + '" generation'); |
|
193 | route_name + '" generation'); | |
186 | } |
|
194 | } | |
187 | result = sprintf(route[0], params); |
|
195 | result = sprintf(route[0], params); | |
188 |
|
196 | |||
189 | var ret = []; |
|
197 | var ret = []; | |
190 | // extra params => GET |
|
198 | // extra params => GET | |
191 | for (var param in params){ |
|
199 | for (var param in params){ | |
192 | if (route[1].indexOf(param) === -1){ |
|
200 | if (route[1].indexOf(param) === -1){ | |
193 |
ret.push(encodeURIComponent(param) + "=" + |
|
201 | ret.push(encodeURIComponent(param) + "=" + | |
194 | encodeURIComponent(params[param])); |
|
202 | encodeURIComponent(params[param])); | |
195 | } |
|
203 | } | |
196 | } |
|
204 | } | |
@@ -202,7 +210,7 b' var pyroutes = (function() {' | |||||
202 | result = APPLICATION_URL + result; |
|
210 | result = APPLICATION_URL + result; | |
203 | } |
|
211 | } | |
204 | } |
|
212 | } | |
205 |
|
213 | |||
206 | return result; |
|
214 | return result; | |
207 | }, |
|
215 | }, | |
208 | 'register': function(route_name, route_tmpl, req_params) { |
|
216 | 'register': function(route_name, route_tmpl, req_params) { |
@@ -56,6 +56,7 b" c.template_context['visual']['default_re" | |||||
56 | var REPO_TYPE = ''; |
|
56 | var REPO_TYPE = ''; | |
57 | %endif |
|
57 | %endif | |
58 | var APPLICATION_URL = "${h.url('home').rstrip('/')}"; |
|
58 | var APPLICATION_URL = "${h.url('home').rstrip('/')}"; | |
|
59 | var ASSET_URL = "${h.asset('')}"; | |||
59 | var DEFAULT_RENDERER = "${h.get_visual_attr(c, 'default_renderer')}"; |
|
60 | var DEFAULT_RENDERER = "${h.get_visual_attr(c, 'default_renderer')}"; | |
60 | var CSRF_TOKEN = "${getattr(c, 'csrf_token', '')}"; |
|
61 | var CSRF_TOKEN = "${getattr(c, 'csrf_token', '')}"; | |
61 | % if getattr(c, 'rhodecode_user', None): |
|
62 | % if getattr(c, 'rhodecode_user', None): |
General Comments 0
You need to be logged in to leave comments.
Login now