summaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/common/handlebars-extensions.js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-02-02 16:29:04 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-02-02 16:51:32 +0100
commit3daa25c3f9a23158046fb56418c9ca403d7db425 (patch)
tree1d153051c425dc5495577e0e4ac8dcfa1d651219 /server/sonar-web/src/main/js/common/handlebars-extensions.js
parent3f0a5c9fa81eeebcdb9554ecceb96007ccd959fc (diff)
downloadsonarqube-3daa25c3f9a23158046fb56418c9ca403d7db425.tar.gz
sonarqube-3daa25c3f9a23158046fb56418c9ca403d7db425.zip
SONAR-6040 improve display of file path
Diffstat (limited to 'server/sonar-web/src/main/js/common/handlebars-extensions.js')
-rw-r--r--server/sonar-web/src/main/js/common/handlebars-extensions.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/common/handlebars-extensions.js b/server/sonar-web/src/main/js/common/handlebars-extensions.js
index eb3af1e038d..679f23af31e 100644
--- a/server/sonar-web/src/main/js/common/handlebars-extensions.js
+++ b/server/sonar-web/src/main/js/common/handlebars-extensions.js
@@ -440,6 +440,47 @@
return component.projectName + (component.subProjectName ? (' / ' + component.subProjectName) : '');
});
+ Handlebars.registerHelper('dirFromPath', function (path) {
+ if (typeof path === 'string') {
+ var tokens = path.split('/');
+ return tokens.length > 1 ? _.initial(tokens).join('/') + '/' : '';
+ } else {
+ return null;
+ }
+ });
+
+ Handlebars.registerHelper('collapsedDirFromPath', function (path) {
+ var limit = 30;
+ if (typeof path === 'string') {
+ var tokens = _.initial(path.split('/'));
+ if (tokens.length > 2) {
+ var head = _.first(tokens),
+ tail = _.last(tokens),
+ middle = _.initial(_.rest(tokens)),
+ cut = false;
+ while (middle.join().length > limit && middle.length > 0) {
+ middle.shift();
+ cut = true;
+ }
+ var body = [].concat(head, cut ? ['...'] : [], middle, tail);
+ return body.join('/') + '/';
+ } else {
+ return tokens.join('/') + '/';
+ }
+ } else {
+ return null;
+ }
+ });
+
+ Handlebars.registerHelper('fileFromPath', function (path) {
+ if (typeof path === 'string') {
+ var tokens = path.split('/');
+ return _.last(tokens);
+ } else {
+ return null;
+ }
+ });
+
Handlebars.registerHelper('repeat', function (number, options) {
var ret = '';
for (var i = 0; i < number; i++) {