Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Dec 5, 2013
0 parents commit ca65a8d
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
tmp
*.sublime-*
22 changes: 22 additions & 0 deletions LICENSE-MIT
@@ -0,0 +1,22 @@
Copyright (c) 2013 Jon Schlinkert

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
83 changes: 83 additions & 0 deletions README.md
@@ -0,0 +1,83 @@
# {{isActive}} [![NPM version](https://badge.fury.io/js/handlebars-helper-isActive.png)](http://badge.fury.io/js/handlebars-helper-isActive)

> Generate relative links from the "current page" to other dest pages.
## Installation

Use [npm](npmjs.org) to install the package: `npm i handlebars-helper-isActive`.

## Register the helper

In your project's Gruntfile, to register the helper add `handlebars-helper-isActive` to the `helpers` property in the [Assemble](http://assemble.io) task or target options:

```javascript
grunt.initConfig({
assemble: {
options: {
// the 'handlebars-helper-isActive' npm module must also be listed in
// devDependencies for assemble to automatically resolve the helper
helpers: ['handlebars-helper-isActive', 'foo/*.js']
},
files: {
'dist/': ['src/templates/*.hbs']
}
}
});
```
Alternatively, you can avoid defining the helper in the [Assemble](https://github.com/assemble/assemble) task options by adding module to both the `devDependencies` and `keywords` in your project's package.json.

```json
{
"name": "foo",
"version": "0.1.0",
"devDependencies": {
"handlebars-helper-isActive": "*"
},
"keywords": [
"handlebars-helper-isActive"
]
}
```

## Usage

With the helper registered, you may now begin using it in your templates.

_Examples also shows the [{{autolink}} helper](https://github.com/helpers/handlebars-helper-autolink)_.

**In a "page"**

```html
{{#each pages}}
<a href="{{autolink}}" {{isActive}}>{{data.title}}</a>
{{/each}}
```

**In a "layout"**

```html
{{#each pages}}
<a href="{{autolink}}" {{isActive}}>{{../title}}</a>
{{/each}}
```

Renders to:

```html
<a href="foo.html" class="active">Foo</a>
<a href="bar.html">Bar</a>
<a href="baz.html">Baz</a>
```


## Author

**Jon Schlinkert**

+ [github/jonschlinkert](http://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License and Copyright

Licensed under the [MIT License](./LICENSE-MIT)
Copyright (c) Jon Schlinkert, contributors.
35 changes: 35 additions & 0 deletions index.js
@@ -0,0 +1,35 @@
/**
* Handlebars Helpers: {{isActive}}
* Copyright (c) 2013 Jon Schlinkert
* Licensed under the MIT License (MIT).
*/


// Node.js
var _ = require('lodash');


// Export helpers
module.exports.register = function (Handlebars, options) {

'use strict';

var opts = options;

/**
* Add `active` class for current page.
* Customize the class in the options hash.
* @xample: {{isActive class="current"}}
*
* @usage: {{isActive}}
*/
Handlebars.registerHelper('isActive', function(context) {
context = _.extend(context, opts.data, this);
context.hash.class = context.hash.class || 'active';
var active = '';
if(context.isCurrentPage === true) {
active = 'class="' + context.hash.class + '"';
}
return new Handlebars.SafeString(active);
});
};
41 changes: 41 additions & 0 deletions package.json
@@ -0,0 +1,41 @@
{
"name": "handlebars-helper-isActive",
"description": "{{isActive}} handlebars helper. Adds an 'active' class to the 'current page'. Class can be customized.",
"version": "0.1.0",
"homepage": "https://github.com/helpers/handlebars-helper-isActive",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "https://github.com/helpers/handlebars-helper-isActive.git"
},
"bugs": {
"url": "https://github.com/helpers/handlebars-helper-isActive/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/helpers/handlebars-helper-isActive/blob/master/LICENSE-MIT"
}
],
"main": "./index.js",
"dependencies": {
"lodash": "~2.4.0"
},
"keywords": [
"assemble",
"gh button",
"gh buttons",
"gh-button",
"isActive",
"isActive",
"github buttons",
"github",
"github-buttons",
"handlebars helper",
"handlebars",
"helper"
]
}

0 comments on commit ca65a8d

Please sign in to comment.