lib/repos/index.jsView |
---|
57 | 57 | ]) |
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | | -function hiddenInputs(values) { |
62 | | - return Object.keys(values).map(function (key) { |
63 | | - return '<input type="hidden"' + |
64 | | - ' name="' + u.escape(key) + '"' + |
65 | | - ' value="' + u.escape(values[key]) + '"/>' |
66 | | - }).join('') |
67 | | -} |
68 | | - |
69 | 61 | |
70 | 62 | |
71 | 63 | R.serveRepoPage = function (req, repo, path) { |
72 | 64 | var self = this |
259 | 251 | (repo.head == 'refs/heads/' + rev ? '' : '@' + rev) |
260 | 252 | return this.renderRepoPage(req, repo, 'code', rev, title, cat([ |
261 | 253 | pull.once('<section><form action="" method="get">' + |
262 | 254 | '<h3>' + req._t(type) + ': ' + rev + ' '), |
263 | | - revMenu(req, repo, rev), |
| 255 | + this.revMenu(req, repo, rev), |
264 | 256 | pull.once('</h3></form>'), |
265 | 257 | type == 'Branch' && renderRepoLatest(req, repo, rev), |
266 | 258 | pull.once('</section><section>'), |
267 | 259 | renderRepoTree(req, repo, rev, path), |
384 | 376 | } |
385 | 377 | |
386 | 378 | |
387 | 379 | |
388 | | -function formatRevOptions(currentName) { |
| 380 | +R.formatRevOptions = function (currentName) { |
389 | 381 | return function (name) { |
390 | 382 | var htmlName = u.escape(name) |
391 | 383 | return '<option value="' + htmlName + '"' + |
392 | 384 | (name == currentName ? ' selected="selected"' : '') + |
393 | 385 | '>' + htmlName + '</option>' |
394 | 386 | } |
395 | 387 | } |
396 | 388 | |
397 | | -function formatRevType(req, type) { |
| 389 | +R.formatRevType = function(req, type) { |
398 | 390 | return ( |
399 | 391 | type == 'heads' ? req._t('Branches') : |
400 | 392 | type == 'tags' ? req._t('Tags') : |
401 | 393 | type) |
402 | 394 | } |
403 | 395 | |
404 | | -function revMenu(req, repo, currentName) { |
| 396 | +R.revMenu = function (req, repo, currentName) { |
| 397 | + var self = this |
405 | 398 | return u.readOnce(function (cb) { |
406 | 399 | repo.getRefNames(function (err, refs) { |
407 | 400 | if (err) return cb(err) |
408 | 401 | cb(null, '<select name="rev" onchange="this.form.submit()">' + |
409 | 402 | Object.keys(refs).map(function (group) { |
410 | | - return '<optgroup label="' + formatRevType(req, group) + '">' + |
411 | | - refs[group].map(formatRevOptions(currentName)).join('') + |
| 403 | + return '<optgroup ' + |
| 404 | + 'label="' + self.formatRevType(req, group) + '">' + |
| 405 | + refs[group].map(self.formatRevOptions(currentName)).join('') + |
412 | 406 | '</optgroup>' |
413 | 407 | }).join('') + |
414 | 408 | '</select><noscript> ' + |
415 | 409 | '<input type="submit" value="' + req._t('Go') + '"/></noscript>') |
416 | 410 | }) |
417 | 411 | }) |
418 | 412 | } |
419 | 413 | |
420 | | -function branchMenu(repo, name, currentName) { |
421 | | - return cat([ |
422 | | - pull.once('<select name="' + name + '">'), |
423 | | - pull( |
424 | | - repo.refs(), |
425 | | - pull.map(function (ref) { |
426 | | - var m = ref.name.match(/^refs\/([^\/]*)\/(.*)$/) || [,, ref.name] |
427 | | - return m[1] == 'heads' && m[2] |
428 | | - }), |
429 | | - pull.filter(Boolean), |
430 | | - u.pullSort(), |
431 | | - pull.map(formatRevOptions(currentName)) |
432 | | - ), |
433 | | - pull.once('</select>') |
434 | | - ]) |
435 | | -} |
436 | | - |
437 | 414 | |
438 | 415 | |
439 | 416 | function renderRepoLatest(req, repo, rev) { |
440 | 417 | return u.readOnce(function (cb) { |
802 | 779 | (repo.head == 'refs/heads/' + rev ? '' : '@' + rev) |
803 | 780 | cb(null, self.renderRepoPage(req, repo, 'code', rev, title, cat([ |
804 | 781 | pull.once('<section><form action="" method="get">' + |
805 | 782 | '<h3>' + req._t(type) + ': ' + rev + ' '), |
806 | | - revMenu(req, repo, rev), |
| 783 | + self.revMenu(req, repo, rev), |
807 | 784 | pull.once('</h3></form>'), |
808 | 785 | type == 'Branch' && renderRepoLatest(req, repo, rev), |
809 | 786 | pull.once('</section><section class="collapse">' + |
810 | 787 | '<h3>' + req._t('Files') + pathLinks + '</h3>' + |
926 | 903 | var title = req._t('Fork') + ' · %{author}/%{repo}' |
927 | 904 | return this.renderRepoPage(req, repo, null, null, title, pull.once( |
928 | 905 | '<form action="" method="post" onreset="history.back()">' + |
929 | 906 | '<h3>' + req._t('ForkRepoPrompt') + '</h3>' + |
930 | | - '<p>' + hiddenInputs({ id: repo.id }) + |
| 907 | + '<p>' + u.hiddenInputs({ id: repo.id }) + |
931 | 908 | '<button class="btn open" type="submit" name="action" value="fork">' + |
932 | 909 | req._t('Fork') + |
933 | 910 | '</button>' + |
934 | 911 | ' <button class="btn" type="reset">' + |