0.4.0 • Published 8 years ago

firenze-behavior-slug v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

firenze-behavior-slug

Build Status Coverage Status npm Join the chat at https://gitter.im/fahad19/firenze

Slug behavior for firenze.js.

Automatically generate slugs (SEO friendly strings) when creating new records.

Install it with npm or Bower:

$ npm install --save firenze-behavior-slug

$ bower install --save firenze-behavior-slug

Contents

What it does

When saving a new model, it will automatically generate a slug and set it to specified field for you.

For example, when saving a post with the title Hello World:

var posts = new Posts();
var post = posts.model({
  title: 'Hello World'
});

post.save().then(function (model) {
  var slug = model.get('slug'); // `hello-world`
});

It will also save the value hello-world in slug field.

Usage

Node.js

With npm:

$ npm install --save firenze-behavior-slug

Now you can require it as follows:

var SlugBehavior = require('firenze-behavior-slug');

// create your Database instance...

db.createCollection({
  behaviors: [
    SlugBehavior
  ]
});

If you want to pass extra configuration options:

db.createCollection({
  behaviors: [
    {
      'class': SlugBehavior
      options: {
        source: 'title', // field to convert
        field: 'slug', // field to store the slug in
        separator: '-',
      }
    }
  ]
});

Browser

Or Bower:

$ bower installl --save firenze-behavior-slug

Can be loaded in your HTML page as follows:

<script src="bower_components/lodash/lodash.min.js"></script>
<script src="bower_components/async/lib/async.js"></script>
<script src="bower_components/bluebird/js/browser/bluebird.min.js"></script>
<script src="bower_components/validator-js/validator.min.js"></script>

<script src="bower_components/firenze/dist/firenze.min.js"></script>
<script src="bower_components/firenze-behavior-slug/dist/firenze-behavior-slug.min.js"></script>

<script>
  // Slug behavior is available in `firenze.SlugBehavior`
</script>

Testing

Tests are written with mocha, and can be run via npm:

$ npm test

License

MIT © Fahad Ibnay Heylaal

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

9 years ago

0.1.0

9 years ago