Skip to content

Commit

Permalink
Merged branch master into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Oct 28, 2016
2 parents 40cc426 + b212c30 commit 604b533
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 15 deletions.
33 changes: 30 additions & 3 deletions docs/abe-handlebars-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,35 @@ template.html
{{{{/raw}}}}
```

Everything inside raw bloc will be compiled client side and as the reload attribut is on the json that will be used is the one client side (not the one saved inside a json file)
when a new item will be added or removed from abe form *objs* inside the json file won't have changed but as it compiled on the client after reloading the iframe myArray will contains as much item as there is on objs each bloc
Everything inside raw block will be compiled client side and as the reload attribute is on the json that will be used is the one client side (not the one saved inside a json file)
when a new item will be added or removed from abe form *objs* inside the json file won't have changed but as it compiled on the client after reloading the iframe myArray will contains as much item as there is on objs each block

## lowercase

### Example

```html
{{lowercase 'my Text IS THERE'}}
```
Result : 'my text is there'

###Description

This helper... lowercases your text.

## uppercase

### Example

```html
{{uppercase 'my Text IS THERE'}}
```

Result : 'MY TEXT IS THERE'

###Description

This helper... uppercases your text.

## truncate

Expand Down Expand Up @@ -121,4 +148,4 @@ __CAUTION__ : If you want to test a handlebars variable like geocode.code, you'l
## printJson
## testObj
## i18nAbe
## times
## times
10 changes: 10 additions & 0 deletions src/cli/cms/templates/handlebars/lowercase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Handlebars helper, lowercase the str
*/
export default function lowercase(str) {
if(typeof str === 'undefined' || str === null){
return ''
} else {
return str.toLowerCase()
}
}
3 changes: 0 additions & 3 deletions src/cli/cms/templates/handlebars/notEmpty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

/**
*/
export default function notEmpty(variable, block) {
if (typeof variable !== 'undefined' && variable !== null && variable !== '') {
return block.fn(this)
Expand Down
16 changes: 7 additions & 9 deletions src/cli/cms/templates/handlebars/truncate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Handlebars from 'handlebars'

export default function truncate(str, len) {
if (typeof str !== 'undefined' && str.length > len) {
new_str = new Handlebars.SafeString (str)
var new_str = str + ' '
new_str = str.substr (0, len)
new_str = str.substr (0, new_str.lastIndexOf(' '))
new_str = (new_str.length > 0) ? new_str : str.substr (0, len)
if (typeof str !== 'undefined' && str != null) {
if(str.length > len) {
var new_str = str.substr (0, len)

return new_str +'...'
return new_str +'...'
} else {
return str
}
} else {

return ''
Expand Down
10 changes: 10 additions & 0 deletions src/cli/cms/templates/handlebars/uppercase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Handlebars helper, uppercase the str
*/
export default function lowercase(str) {
if(typeof str === 'undefined' || str === null){
return ''
} else {
return str.toUpperCase()
}
}
6 changes: 6 additions & 0 deletions src/cli/cms/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import printJson from './handlebars/printJson'
import translate from './handlebars/translate'
import times from './handlebars/times'
import truncate from './handlebars/truncate'
import lowercase from './handlebars/lowercase'
import uppercase from './handlebars/uppercase'

import * as template from './template'
import * as assets from './assets'
Expand All @@ -37,6 +39,8 @@ Handlebars.registerHelper('printJson', printJson)
Handlebars.registerHelper('i18nAbe', translate)
Handlebars.registerHelper('times', times)
Handlebars.registerHelper('truncate', truncate)
Handlebars.registerHelper('lowercase', lowercase)
Handlebars.registerHelper('uppercase', uppercase)

HandlebarsIntl.registerWith(Handlebars)

Expand All @@ -52,6 +56,8 @@ export {
ifIn,
isTrue,
truncate,
lowercase,
uppercase,
math,
moduloIf,
notEmpty,
Expand Down
56 changes: 56 additions & 0 deletions test/hbs-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var chai = require('chai');
var Handlebars =require('../src/cli').Handlebars

describe("Helpers", function () {
describe("lowercase", function () {
it('properly lowercase string', function() {
var value = 'ThiS IS mY String',
rendered = Handlebars.helpers.lowercase(value),
expected = 'this is my string';
chai.expect(rendered).to.eql(expected);
});
it('properly return empty string', function() {
var value = null,
rendered = Handlebars.helpers.lowercase(value),
expected = '';
chai.expect(rendered).to.eql(expected);
});
});
describe("uppercase", function () {
it('properly uppercase string', function() {
var value = 'ThiS IS mY String',
rendered = Handlebars.helpers.uppercase(value),
expected = 'THIS IS MY STRING';
chai.expect(rendered).to.eql(expected);
});
it('properly return empty string', function() {
var value = null,
rendered = Handlebars.helpers.uppercase(value),
expected = '';
chai.expect(rendered).to.eql(expected);
});
});
describe("truncate", function () {
it('properly truncate string', function() {
var value = 'ThiS IS mY String',
length = 10,
rendered = Handlebars.helpers.truncate(value, length),
expected = 'ThiS IS mY...';
chai.expect(rendered).to.eql(expected);
});
it('properly return full string', function() {
var value = 'ThiS IS mY String',
length = 20,
rendered = Handlebars.helpers.truncate(value, length),
expected = 'ThiS IS mY String';
chai.expect(rendered).to.eql(expected);
});
it('properly return empty string', function() {
var value = null,
length = 10,
rendered = Handlebars.helpers.truncate(value, length),
expected = '';
chai.expect(rendered).to.eql(expected);
});
});
});

0 comments on commit 604b533

Please sign in to comment.