Comparing version 2.0.0-alpha.2 to 2.0.0-alpha.3
@@ -27,3 +27,3 @@ { | ||
"whitespace", "automata", "i", "obj", "anymore", "lexer", "var", "refs", | ||
"serializable", "tis", "twas", "int" | ||
"serializable", "tis", "twas", "int", "args", "unshift", "plugins" | ||
] | ||
@@ -30,0 +30,0 @@ } |
@@ -269,1 +269,21 @@ /*! | ||
} | ||
/** | ||
* Applies a plugin to the index builder. | ||
* | ||
* A plugin is a function that is called with the index builder as its context. | ||
* Plugins can be used to customise or extend the behaviour of the index | ||
* in some way. A plugin is just a function, that encapsulated the custom | ||
* behaviour that should be applied when building the index. | ||
* | ||
* The plugin function will be called with the index builder as its argument, additional | ||
* arguments can also be passed when calling use. The function will be called | ||
* with the index builder as its context. | ||
* | ||
* @param {Function} plugin The plugin to apply. | ||
*/ | ||
lunr.Builder.prototype.use = function (fn) { | ||
var args = Array.prototype.slice.call(arguments, 1) | ||
args.unshift(this) | ||
fn.apply(this, args) | ||
} |
{ | ||
"name": "lunr", | ||
"description": "Simple full-text search in your browser.", | ||
"version": "2.0.0-alpha.2", | ||
"version": "2.0.0-alpha.3", | ||
"author": "Oliver Nightingale", | ||
@@ -6,0 +6,0 @@ "keywords": ["search"], |
@@ -61,2 +61,40 @@ suite('lunr.Builder', function () { | ||
suite('#use', function () { | ||
setup(function () { | ||
this.builder = new lunr.Builder | ||
}) | ||
test('calls plugin function', function () { | ||
var wasCalled = false, | ||
plugin = function () { wasCalled = true } | ||
this.builder.use(plugin) | ||
assert.isTrue(wasCalled) | ||
}) | ||
test('sets context to the builder instance', function () { | ||
var context = null, | ||
plugin = function () { context = this } | ||
this.builder.use(plugin) | ||
assert.equal(context, this.builder) | ||
}) | ||
test('passes builder as first argument', function () { | ||
var arg = null, | ||
plugin = function (a) { arg = a } | ||
this.builder.use(plugin) | ||
assert.equal(arg, this.builder) | ||
}) | ||
test('forwards arguments to the plugin', function () { | ||
var args = null, | ||
plugin = function () { args = [].slice.call(arguments) } | ||
this.builder.use(plugin, 1, 2, 3) | ||
assert.deepEqual(args, [this.builder, 1, 2, 3]) | ||
}) | ||
}) | ||
suite('#build', function () { | ||
@@ -63,0 +101,0 @@ setup(function () { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2156412
24188