Permalink
Browse files

Updating syntax for constistancy, restyling readme

  • Loading branch information...
1 parent 53d3bfc commit acb0cd23f6a3e50e6f2b06ceecb18e42684ca9b4 @sorensen sorensen committed Jan 17, 2012
Showing with 132 additions and 133 deletions.
  1. +1 −2 Makefile
  2. +37 −29 README.md
  3. +15 −15 lib/basicAuth.js
  4. +4 −4 lib/keywords/index.js
  5. +18 −15 lib/pubsub.js
  6. +20 −22 lib/rest.js
  7. +2 −2 lib/slugify.js
  8. +4 −2 lib/timestamp.js
  9. +4 −4 lib/utils.js
  10. +1 −1 package.json
  11. +0 −1 test/basicAuth.test.js
  12. +0 −1 test/keywords.test.js
  13. +0 −1 test/pubsub.test.js
  14. +0 −1 test/slugify.test.js
  15. +0 −1 test/timestamp.test.js
  16. +26 −32 test/utils.test.js
View
@@ -1,5 +1,4 @@
-
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter spec \
@@ -13,4 +12,4 @@ clean:
./test/support/cleanup.js
-.PHONY: test
+.PHONY: test clean
View
@@ -3,7 +3,7 @@
A collection of handy plugins for mongoose
-### Contents
+## Contents
* <a href="#Troop.acl"> acess control list </a>
* <a href="#Troop.basicAuth"> authentication </a>
* <a href="#Troop.timestamp"> timestamps </a>
@@ -13,10 +13,11 @@ A collection of handy plugins for mongoose
* <a href="#Troop.pubsub"> pubsub </a> (message passing)
* <a href="#Troop.rest"> rest </a> (http or rpc controller)
-## acl <a name="Troop.acl" href="#Troop.acl"><small><sup>link</sup></small></a>
+
+# acl <a name="Troop.acl" href="#Troop.acl"><small><sup>link</sup></small></a>
Simple access control list
-#### Methods
+## Methods
### instance.addAccess(key)
@@ -30,17 +31,18 @@ Remove `key` access to a Model instance
Return or callback a boolean
-## basicAuth <a name="Troop.basicAuth" href="#Troop.basicAuth"><small><sup>link</sup></small></a>
+
+# basicAuth <a name="Troop.basicAuth" href="#Troop.basicAuth"><small><sup>link</sup></small></a>
Simple authentication plugin
-#### Options
+## Options
* `loginPath` schema path for username/login (optional, default `username`)
* `hashPath` schema path to hashed password (optional, default `hash`)
* `workFactor` bcrypt work factor (optional, default `10`)
-#### Methods
+## Methods
### instance.authenticate(password, callback)
@@ -58,7 +60,7 @@ Authenticate a user on the model level
Create a new user with given attributes
-#### Example
+## Example
```javascript
var mongoose = require('mongoose')
@@ -93,17 +95,19 @@ User.findOne({ username: 'foo'}, function(err, doc) {
})
})
````
-## timestamp <a name="Troop.timestamp" href="#Troop.timestamp"><small><sup>link</sup></small></a>
+
+
+# timestamp <a name="Troop.timestamp" href="#Troop.timestamp"><small><sup>link</sup></small></a>
Adds a `created` and `modified` property to the schema, updating the timestamps as expected.
-#### Options
+## Options
* `createdPath` schema path for created timestamp (optional, default `created`)
* `modifiedPath` schema path for modified timestamp (optional, default `modified`)
* `useVirtual` use a virtual path for created timestamp based on ObjectId (optional, default `true`)
-#### Example
+## Example
```javascript
var mongoose = require('mongoose')
@@ -113,19 +117,19 @@ var mongoose = require('mongoose')
FooSchema.plugin(troop.timestamp)
````
-#### Note
+## Note
Using the virtual `created` timestamp you will lose the ability to run queries against it,
as well as a loss in precision, as it will return a timestamp in seconds.
-## slugify <a name="Troop.slugify" href="#Troop.slugify"><small><sup>link</sup></small></a>
+# slugify <a name="Troop.slugify" href="#Troop.slugify"><small><sup>link</sup></small></a>
Turn a string based field into a url friendly slug
Converts `this is a title` to `this-is-a-title`
-#### Options
+## Options
* `target` schema path for slug destination (optional, default `slug`)
* `source` schema path for slug content (optional, default `title`)
@@ -134,7 +138,7 @@ Converts `this is a title` to `this-is-a-title`
* `invalidChar` invalid character replacement (optional, default ``)
* `override` override slug field on source path change (optional, default `false`)
-#### Example
+## Example
```javascript
var mongoose = require('mongoose')
@@ -149,26 +153,26 @@ console.log(instance.slug) // `well-hello-there`
````
-## keywords <a name="Troop.keywords" href="#Troop.keywords"><small><sup>link</sup></small></a>
+# keywords <a name="Troop.keywords" href="#Troop.keywords"><small><sup>link</sup></small></a>
Keyword extraction/creation plugin, can be used as a simple substitute of a full
search indexing package.
Turns `fooed bars` into `['foo', 'bar']`
-#### Options
+## Options
* `target` schema path for keyword destination (optional, default `keywords`)
* `source` schema path for extracting keywords
* `minLength` minimum string length to be used as a keyword (optional, default `2`)
-#### Methods
+## Methods
### instance.extractKeywords(str)
Manually calculate a keyword array with a given string
-#### Example
+## Example
```javascript
var mongoose = require('mongoose')
@@ -197,21 +201,22 @@ fooModel.find({ keywords: { $in: fooModel.extractKeywords(val) }}, function(docs
})
````
-## utils <a name="Troop.utils" href="#Troop.utils"><small><sup>link</sup></small></a>
-### merge
+# utils <a name="Troop.utils" href="#Troop.utils"><small><sup>link</sup></small></a>
+
+## merge
Merge JSON into your object more easily.
```javascript
instance.merge({title:'A new title', description:'A new description'}).save()
````
-#### Options
+### Options
* `debug` verbose logging of current actions (optional, default `false`)
-### getdbrefs
+## getdbrefs
Get the dbrefs from a schema
@@ -224,23 +229,23 @@ instance.getdbrefs(function (refs) {
```
-### removeDefaults
+## removeDefaults
Remove all of the default values from your model instance.
`instance.removeDefaults().save()`
-#### Options
+### Options
* `debug` verbose logging of current actions (optional, default `false`)
-## publish <a name="Troop.publish" href="#Troop.publish"><small><sup>link</sup></small></a>
+# publish <a name="Troop.publish" href="#Troop.publish"><small><sup>link</sup></small></a>
Plugin to publish/subscribe from a model or instance level, also enabling a model
to automatically publish changes on `init`, `save`, and `remove` methods. Both models
and instances can be published/subscribed to.
-#### Options
+## Options
* `auto` attach middleware based on the `hook` for `init`, `save`, and `remove` methods (optional, default `false`)
* `hook` middleware method to attach auto middleware to (optional, default `post`)
@@ -250,7 +255,7 @@ and instances can be published/subscribed to.
* `publish` redis instance to be used for publishing
* `subscribe` redis instance to be used for subscribing
-#### Methods
+## Methods
### instance.publish(options)
@@ -262,6 +267,8 @@ and instances can be published/subscribed to.
### instance.unsubscribe()
+## Example
+
```javascript
var redis = require('redis')
, publish = redis.createClient()
@@ -310,9 +317,10 @@ You can also subscribe on the instance level
instance.subscribe() // channel: 'foo:4d6e5acebcd1b3fac9000007'
````
-## rest <a name="Troop.rest" href="#Troop.rest"><small><sup>link</sup></small></a>
-#### Options
+# rest <a name="Troop.rest" href="#Troop.rest"><small><sup>link</sup></small></a>
+
+## Options
* `debug` verbose logging of current actions (optional, default `false`)
View
@@ -6,7 +6,7 @@
var bcrypt = require('bcrypt')
-function Auth (schema, options) {
+function auth (schema, options) {
options || (options = {})
var loginPath = (options.loginPath || 'username')
@@ -28,42 +28,42 @@ function Auth (schema, options) {
}
schema.add(fields)
- schema.method('authenticate', function(password, next) {
+ schema.method('authenticate', function (password, next) {
if (!password || !this[hashPath]) {
return next('missing parameters')
}
bcrypt.compare(password, this[hashPath], next)
})
- schema.method('setPassword', function(password, next) {
+ schema.method('setPassword', function (password, next) {
var self = this
- bcrypt.genSalt(workFactor, function(err, salt) {
+ bcrypt.genSalt(workFactor, function (err, salt) {
if (err) return next(err)
- bcrypt.hash(password, salt, function(err, hash) {
+ bcrypt.hash(password, salt, function (err, hash) {
if (err) return next(err)
self[hashPath] = hash
next(null)
})
})
})
- schema.static('authenticate', function(username, password, next) {
+ schema.static('authenticate', function (username, password, next) {
query[loginPath] = username
- this.findOne(query, function(err, model) {
+ this.findOne(query, function (err, model) {
if (err) return next(err)
if (!model) return next('model does not exist')
- model.authenticate(password, function(err, valid) {
+ model.authenticate(password, function (err, valid) {
if (err) return next(err)
if (valid) return next(null, model)
return next('invalid password', null)
})
})
})
- schema.static('register', function(attr, next) {
- this.create(attr, function(err, model) {
+ schema.static('register', function (attr, next) {
+ this.create(attr, function (err, model) {
if (err) {
if (/duplicate key/.test(err)) {
return next(loginPath + ' taken')
@@ -76,16 +76,16 @@ function Auth (schema, options) {
schema
.virtual('password')
- .get(function() {
+ .get(function () {
return this[hashPath]
})
- .set(function(password) {
+ .set(function (password) {
this._password = password
})
- schema.pre('save', function(next) {
+ schema.pre('save', function (next) {
if (this._password && !this[hashPath]) {
- this.setPassword(this._password, function() {
+ this.setPassword(this._password, function () {
next()
})
} else {
@@ -94,5 +94,5 @@ function Auth (schema, options) {
})
}
-module.exports = Auth
+module.exports = auth
View
@@ -30,7 +30,7 @@ function keywords (schema, options) {
}
schema.add(fields)
- schema.pre('save', function(next) {
+ schema.pre('save', function (next) {
var words = []
for (var i = 0; i < source.length; i++) {
var add = this.extractKeywords(this[source[i]])
@@ -45,7 +45,7 @@ function keywords (schema, options) {
;['static'
, 'method'
].forEach(function (method) {
- schema[method]('extractKeywords', function(str) {
+ schema[method]('extractKeywords', function (str) {
if (!str) return []
str = str
.replace(/^\s+|\s+$/g, '')
@@ -58,8 +58,8 @@ function keywords (schema, options) {
.replace(/[^a-z0-9 -]/g, invalidChar)
.replace(new RegExp('['+invalidChar+']'+'+', 'g'), invalidChar)
.split(/\s+/)
- .filter(function(v) { return v.length >= minLength })
- .filter(function(v, i, a) { return a.lastIndexOf(v) === i })
+ .filter(function (v) { return v.length >= minLength })
+ .filter(function (v, i, a) { return a.lastIndexOf(v) === i })
if (naturalize) {
str.forEach(function (v, i, arr) {
Oops, something went wrong.

0 comments on commit acb0cd2

Please sign in to comment.