Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

example was a bit out of date with completer

  • Loading branch information...
commit 4a5c455ec38fe0e1c0a3a2aa598de2e91c3bb2b5 1 parent 8afb5a2
@jedp authored
View
2  completer.js
@@ -52,7 +52,7 @@ exports.addFromFile = addFromFile = function(filename) {
if (err) {
return console.log("ERROR: reading " + filename + ": " + err), null;
}
- _.each(buf.toString().split(/\n/), addCompletions);
+ _.each(buf.toString().split(/\n/), function(s) { addCompletions(s)});
});
}
View
3  example/example.js
@@ -6,6 +6,7 @@
var express = require('express');
var nowjs = require('now');
var completer = require('../completer');
+completer.applicationPrefix('demo');
var app = module.exports = express.createServer();
@@ -17,7 +18,7 @@ var r = require('redis').createClient();
r.zcard('compl', function(err, card) {
if (card === 0) {
console.log("Bootstrapping tweet data.");
- addFromFile('./data/tweets.txt');
+ completer.addFromFile('./data/tweets.txt');
console.log("This is asynchronous, so go ahead and do whatever you want.");
}
});
View
23 example/public/javascripts/models.js
@@ -42,30 +42,23 @@ var CompleterAppView = Backbone.View.extend({
el: '#application',
events: {
- 'keydown #search': 'searchKeydown'
+ 'keyup #search': 'searchKeyup'
},
- searchKeydown: function(event) {
+ searchKeyup: function(event) {
// Search for what the user has typed
- //
- // This event handler will get fired before the
- // search-input box receive the character typed,
- // so concatenate the current character onto the
- // end of the contents of the search box.
- //
- // this ends up appending an uppercase letter,
- // which appears to be what event.which and event.keyCode
- // both report. but that doesn't matter in this app.
var text = $('#search-input').val();
- text += String.fromCharCode(event.which);
var self = this;
this.$('.tweet-content').remove();
now.search(text, 10, function(err, results) {
- _.each(results, function(tuple) {
+ _.each(results, function(line) {
+ var match = line.match(/(@\w+)?\s*(.*)/);
+ var username = match[0] || '';
+ var text = match[1] || '';
var tweet = new Tweet(
- {username: tweetToHtml(tuple[0]),
- text: tweetToHtml(tuple[1])});
+ {username: tweetToHtml(username),
+ text: tweetToHtml(text)});
self.addTweet(tweet);
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.