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