Skip to content

Commit

Permalink
Merge pull request #21 from Budibase/lorem
Browse files Browse the repository at this point in the history
Lorem Ipsum Generator
  • Loading branch information
mikesealey authored Jul 4, 2024
2 parents fab2b5b + 83afe46 commit a6bda6c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/lorem.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var util = require('handlebars-utils');
var utils = require('./utils');
var helpers = module.exports;
let lorem = require('./lorem.js');

/**
* Append the specified `suffix` to the given string.
Expand Down Expand Up @@ -802,3 +803,27 @@ helpers.uppercase = function(str) {
if (typeof(str) !== 'string') return '';
return str.toUpperCase();
};

/**
* Takes a number and returns that many charaters of Lorem Ipsum
*
* ```handlebars
* {{lorem 11}}
* <!-- results in: 'Lorem Ipsum' -->
* ```
* @param {Number} `num` The string to uppercase
* @return {String}
* @block
* @inline
* @api public
* @example {{lorem 11}} -> Lorem ipsum
*/

helpers.lorem = function(num) {
// Sad Path - Not a number, or not greater than 1, or not truthy
if (isNaN(num) || num < 1 || !num) {
num = 11;
}

return lorem.substring(0, num);
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"node": ">=10.12.0"
},
"scripts": {
"lint": "eslint *.js lib/**/*.js test/**/*.js",
"lint": "eslint *.js lib/*.js lib/**/*.js lib/*.js test/*.js test/*/*.js",
"test": "mocha",
"update:readmemd": "verb"
},
Expand Down Expand Up @@ -179,4 +179,4 @@
}
}
}
}
}
47 changes: 46 additions & 1 deletion test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('..');
helpers.string({handlebars: hbs});
helpers.string({ handlebars: hbs });

describe('string', function() {
describe('camelcase', function() {
Expand Down Expand Up @@ -397,5 +397,50 @@ describe('string', function() {
assert.equal(fn(), 'BENDER SHOULD NOT BE ALLOWED ON TV');
});
});

describe('lorem', function() {
// Bad parameters
it('Should return "Lorem ipsum" only, if passed no parameters', function() {
var fn = hbs.compile('{{ lorem }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return "Lorem ipsum" only, if passed a non-number (string)', function() {
var fn = hbs.compile('{{ lorem a }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return "Lorem ipsum" only, if passed a non-number (array)', function() {
var fn = hbs.compile('{{ lorem [1,2,3] }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return "Lorem ipsum" only, if passed a number less than 1', function() {
var fn = hbs.compile('{{ lorem -1 }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return "Lorem ipsum" only, if passed a number less than 1', function() {
var fn = hbs.compile('{{ lorem 0 }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return "Lorem ipsum" only, if passed a number less than 1', function() {
var fn = hbs.compile('{{ lorem -999 }}');
assert.equal(fn(), 'Lorem ipsum');
});
// Good parameters
it('Should return a string of "Lorem ipsum" if passed 11', function() {
var fn = hbs.compile('{{ lorem 11 }}');
assert.equal(fn(), 'Lorem ipsum');
});
it('Should return a string of "Lorem" if passed 5', function() {
var fn = hbs.compile('{{ lorem 5 }}');
assert.equal(fn(), 'Lorem');
});
it('Should return a string of "Lorem ipsum dolor sit amet, consectetur adipiscing" if passed 50', function() {
var fn = hbs.compile('{{ lorem 50 }}');
assert.equal(fn(), 'Lorem ipsum dolor sit amet, consectetur adipiscing');
});
it('Should return a string of length 8032 if passed 8032', function() {
var fn = hbs.compile('{{ lorem 8032 }}');
assert.equal(fn().length, 8032);
});
});
});

0 comments on commit a6bda6c

Please sign in to comment.