-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
59 lines (52 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var Pagelet = require('pagelet')
, Names = require('./names')
, path = require('path')
, fs = require('fs');
Pagelet.extend({
view: 'view.html', // HTML template.
css: 'css.styl', // Custom CSS.
js: 'client.js', // Front-end magic.
rpc: ['complete'], // Expose method as RPC.
//
// External dependencies that should be included on the page using a regular
// script tag. This dependency is needed for the `client.js` client file.
//
dependencies: [
'//code.jquery.com/jquery-2.1.0.min.js',
path.join(__dirname, '/selectize.default.css'),
path.join(__dirname, '/selectize.js')
],
/**
* Maximum amount of items to show in the auto complete.
*
* @type {Number}
* @public
*/
max: 50,
/**
* The names leveldb database that we're going to use for autocompletion.
*
* @type {Names}
* @private
*/
level: new Names({ refresh: true }),
/**
* [RPC]: Return a list of package names.
*
* @param {Function} reply Send a reply to the client.
* @param {String} query The name of package we're searching for.
* @api public
*/
complete: function complete(reply, query) {
var suffix = this.level.suffix;
this.level.find(query, this.max, function found(err, data) {
reply(err, data.map(function map(row) {
return {
name: row.key,
desc: row.value !== suffix ? row.value : ''
};
}));
});
}
}).on(module);