firenze-behavior-slug

0.4.0 • Public • Published

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

Package Sidebar

Install

npm i firenze-behavior-slug

Weekly Downloads

2

Version

0.4.0

License

MIT

Last publish

Collaborators

  • fahad19