framework/ember/app/helpers/highlight-words.js
2015-01-21 14:29:00 +10:30

19 lines
528 B
JavaScript

import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(text, phrase) {
if (phrase) {
var words = phrase.split(' ');
var replacement = function(matched) {
return '<span class="highlight-keyword">'+matched+'</span>';
};
words.forEach(function(word) {
text = text.replace(
new RegExp("\\b"+word+"\\b", 'gi'),
replacement
);
});
}
return new Ember.Handlebars.SafeString(text);
});