diff --git a/README.md b/README.md index 9b42853..78de49c 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Ui fixes * current successfully streak icons at project page * ~~don't appear build from other project on project page~~ * ~~update project info changes (avg duration, etc) on the fly - project page~~ -* long commit comment breakes build card makeup +* ~~long commit comment breakes build card makeup~~ * ~~comment start/duration should be on same place during all steps~~ ## Roadmap diff --git a/lib/utils.js b/lib/utils.js index 755c83d..352db2d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,15 +1,9 @@ 'use strict'; -exports.prune = function(str, length) { - var result = '', - words = str.split(' '); +var _ = require('underscore'), + sharedUtils = require('../static/js/shared/utils'); - do { - result += words.shift() + ' '; - } while (words.length && result.length < length); - - return result.replace(/ $/, words.length ? '...' : ''); -}; +_(exports).extend(sharedUtils); exports.lpad = function(str, length, chr) { chr = chr || '0'; diff --git a/static/js/app/components/builds/item.jade b/static/js/app/components/builds/item.jade index 432e662..1578765 100644 --- a/static/js/app/components/builds/item.jade +++ b/static/js/app/components/builds/item.jade @@ -70,7 +70,7 @@ mixin statusText(build) span.build_info i.fa.fa-fw.fa-comment-o | - span= build.scm.rev.comment + span= utils.prune(build.scm.rev.comment, 40) | .build_controls diff --git a/static/js/app/components/builds/item.js b/static/js/app/components/builds/item.js index 3e60ed0..5d44903 100644 --- a/static/js/app/components/builds/item.js +++ b/static/js/app/components/builds/item.js @@ -3,11 +3,13 @@ define([ 'react', 'react-router', 'app/actions/project', 'app/actions/build', 'templates/app/components/builds/item', - 'app/components/terminal/terminal', - 'app/components/common/index' + 'app/components/terminal/terminal', 'app/components/common/index', + 'app/utils' ], function( - React, Router, ProjectActions, BuildActions, template, - TerminalComponent, CommonComponents + React, Router, ProjectActions, + BuildActions, template, + TerminalComponent, CommonComponents, + utils ) { template = template.locals({ DateTime: CommonComponents.DateTime, @@ -15,7 +17,8 @@ define([ Progress: CommonComponents.Progress, Scm: CommonComponents.Scm, Terminal: TerminalComponent, - Link: Router.Link + Link: Router.Link, + utils: utils }); var Component = React.createClass({ diff --git a/static/js/app/utils.js b/static/js/app/utils.js new file mode 100644 index 0000000..03288cb --- /dev/null +++ b/static/js/app/utils.js @@ -0,0 +1,9 @@ +'use strict'; + +define(['underscore', 'shared/utils'], function(_, sharedUtils) { + var utils = {}; + + _(utils).extend(sharedUtils); + + return utils; +}); diff --git a/static/js/shared/utils.js b/static/js/shared/utils.js new file mode 100644 index 0000000..7313d7f --- /dev/null +++ b/static/js/shared/utils.js @@ -0,0 +1,32 @@ +'use strict'; + +(function(root, factory) { + + if (typeof module !== 'undefined' && module.exports) { + // CommonJS + module.exports = factory(); + } else if (typeof define === 'function' && define.amd) { + // AMD + define(function() { + return factory(); + }); + } + +}(this, function() { + + var utils = {}; + + utils.prune = function(str, length) { + var result = '', + words = str.split(' '); + + do { + result += words.shift() + ' '; + } while (words.length && result.length < length); + + return result.replace(/ $/, words.length ? '...' : ''); + }; + + return utils; + +}));