Skip to content

Commit

Permalink
Cleanup and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronAsAChimp committed Mar 21, 2016
1 parent d161523 commit cde6044
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ Default value: `true`
Enable or disable the use of `@import` in generated CSS files. This feature was
added in bless.js 3.0.3.

#### options.root ####

Type: `String`
Default value: `''`

Add a path or domain to the `@import` statements in the generated CSS files. By
default the generated CSS files are relative to the output file.

#### options.logCount ####

Type: `Boolean | String`
Expand Down
3 changes: 2 additions & 1 deletion src/lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export function imports(options) {
while (current > 0) {
let _name = name(options.output, current, options.suffix, EXTENSION),
_splitted = _name.split('/');

_name = _splitted[_splitted.length - 1];
statements += '@import "' + options.rootPath + _name + '";' + options.linefeed;
statements += '@import "' + options.root + _name + '";' + options.linefeed;

current--;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/bless.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function(grunt) {
failOnLimit: false,
suffix: DEFAULT_SUFFIX,
sourceMaps: false,
rootPath:''
root:''
});

//grunt.log.writeflags(options, 'options');
Expand Down Expand Up @@ -131,7 +131,7 @@ module.exports = function(grunt) {
output: outPutfileName,
suffix: suffix,
linefeed: (options.compress ? '' : grunt.util.linefeed),
rootPath: options.rootPath
root: options.root
});

header += grunt.util.linefeed;
Expand Down
49 changes: 42 additions & 7 deletions test/lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('A library of file utilities', function () {
FILE_SUFFIX = 'suffix-',
FILE_EXTENSION = 'ext';

it('should return a file name with no suffix when its the fist file', function () {
it('should return a file name with no suffix when its the first file', function () {
var filename = file_utils.name(FILE_BASE, 0, FILE_SUFFIX, FILE_EXTENSION);

assert.equal('base.ext', filename);
Expand All @@ -23,12 +23,6 @@ describe('A library of file utilities', function () {
assert.equal('base.suffix-1.ext', filename);
});

it('should return a path that is relative to the stylesheet not the root', function () {
var filename = file_utils.name('tmp/' + FILE_BASE, 1, FILE_SUFFIX, FILE_EXTENSION);

assert.equal('base.suffix-1.ext', filename);
});

it('should throw an error if file number is negative', function () {
assert.throws(function () {
file_utils.name(FILE_BASE, -1, FILE_SUFFIX, FILE_EXTENSION);
Expand Down Expand Up @@ -66,4 +60,45 @@ describe('A library of file utilities', function () {
assert.equal('base.css.ext', base);
});
});

describe('A function that generate a list of imports', function () {
var FILE_BASE = 'base',
FILE_SUFFIX = 'suffix-';

it('should return no imports if the file is not split', function () {
var filename = file_utils.imports({
'numFiles': 1,
'output': FILE_BASE,
'suffix': FILE_SUFFIX,
'root': '',
'linefeed': '\n'
});

assert.equal('', filename);
});

it('should return imports that are relative to the stylesheet not the root', function () {
var filename = file_utils.imports({
'numFiles': 2,
'output': 'tmp/' + FILE_BASE,
'suffix': FILE_SUFFIX,
'root': '',
'linefeed': '\n'
});

assert.equal('@import "base.suffix-1.css";\n', filename);
});

it('should return imports with a domain and path if a root is specified', function () {
var filename = file_utils.imports({
'numFiles': 2,
'output': FILE_BASE,
'suffix': FILE_SUFFIX,
'root': '//example.com/example/path/',
'linefeed': '\n'
});

assert.equal('@import "//example.com/example/path/base.suffix-1.css";\n', filename);
});
});
});

0 comments on commit cde6044

Please sign in to comment.