Skip to content

Commit

Permalink
Set default of parser option "relativeUrls" to "true"
Browse files Browse the repository at this point in the history
This is a breaking change!
In order to get the old behavior back, please set the
"parser.relativeUrls" option to "false".

As ui5 themes usually import other themes (e.g. base) to inherit
variables, mixins and rules it is required to set the "relativeUrls"
option to "true" in order to generate valid URLs (e.g. images/fonts).

The default in LESS 1.6.3 is "false".
  • Loading branch information
matz3 committed Mar 14, 2016
1 parent a9ae99c commit 00d892b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ lib2

Type: `object`

Options for the [less](http://lesscss.org) parser (`less.Parser`).
Options for the [less](http://lesscss.org) parser (`less.Parser`).
**Note:** Default of `relativeUrls` option is changed from `false` to `true`.

##### compiler

Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module.exports.build = function(input, options, callback) {
library: {}
}, options);

// Set default of "relativeUrls" parser option to "true" (less default is "false")
if (!options.parser.hasOwnProperty("relativeUrls")) {
options.parser.relativeUrls = true;
}

var result = {
variables: {},
css: '',
Expand Down
11 changes: 11 additions & 0 deletions test/expected/imports/main-no-relativeUrls.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import "dir3/external.css";
/* dir3/inline.css */

/* dir1/foo.less */
.foo {
background: url("foo.png");
}
/* dir2/bar.less */
.bar {
background: url("bar.png");
}
6 changes: 6 additions & 0 deletions test/expected/imports/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
/* dir3/inline.css */

/* dir1/foo.less */
.foo {
background: url("dir1/foo.png");
}
/* dir2/bar.less */
.bar {
background: url("dir2/bar.png");
}
4 changes: 4 additions & 0 deletions test/fixtures/imports/dir1/foo.less
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/* dir1/foo.less */

.foo {
background: url("foo.png");
}
4 changes: 4 additions & 0 deletions test/fixtures/imports/dir2/bar.less
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/* dir2/bar.less */

.bar {
background: url("bar.png");
}
39 changes: 39 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,45 @@ describe('imports', function() {

});

it('should use "relativeUrls" parser option by default', function(done) {

lessOpenUI5.build(readFile('test/fixtures/imports/main.less'), {
parser: {
filename: 'main.less',
paths: [ 'test/fixtures/imports' ]
}
}, function(err, result) {

assert.ifError(err);

assert.equal(result.css, readFile('test/expected/imports/main.css'), 'css should be correctly generated.');

done();

});

});

it('should not rewrite urls when "relativeUrls" parser option is set to "false"', function(done) {

lessOpenUI5.build(readFile('test/fixtures/imports/main.less'), {
parser: {
filename: 'main.less',
paths: [ 'test/fixtures/imports' ],
relativeUrls: false
}
}, function(err, result) {

assert.ifError(err);

assert.equal(result.css, readFile('test/expected/imports/main-no-relativeUrls.css'), 'css should be correctly generated.');

done();

});

});

});

describe('inline theming parameters', function() {
Expand Down

0 comments on commit 00d892b

Please sign in to comment.