framework/ember/app/helpers/highlight-words.js
2014-12-20 16:56:46 +10:30

19 lines
531 B
JavaScript

import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(text, phrase, options) {
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 Handlebars.SafeString(text);
});