Skip to content

Commit 5b58d31

Browse files
sky-codingTheLarkInn
authored andcommitted
Added support for components with spacing after styleUrls and templateUrl properties (#11)
1 parent 220e116 commit 5b58d31

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// using: regex, capture groups, and capture group variables.
2-
var templateUrlRegex = /templateUrl:(.*)$/gm;
3-
var stylesRegex = /styleUrls:(\s*\[[^\]]*?\])/g;
2+
var templateUrlRegex = /templateUrl *:(.*)$/gm;
3+
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
44
var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g;
55

66
function replaceStringsWithRequires(string) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var componentWithSpacing = `
2+
import {Component} from '@angular/core';
3+
4+
@Component({
5+
selector : 'test-component',
6+
templateUrl : './some/path/to/file.html',
7+
styleUrls : ['./app/css/styles.css']
8+
})
9+
export class TestComponent {}
10+
`;
11+
12+
module.exports = componentWithSpacing;

test/fixtures/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ var sampleAngular2ComponentSimpleFixture = require('./sample_angular2_component_
22
var componentWithQuoteInUrls = require('./component_with_quote_in_urls.js');
33
var componentWithMultipleStyles = require('./component_with_multiple_styles.js');
44
var componentWithoutRelPeriodSlash = require('./component_without_relative_period_slash.js');
5+
var componentWithSpacing = require('./component_with_spacing.js');
56

67
exports.simpleAngular2TestComponentFileStringSimple = sampleAngular2ComponentSimpleFixture;
78
exports.componentWithQuoteInUrls = componentWithQuoteInUrls;
89
exports.componentWithMultipleStyles = componentWithMultipleStyles;
910
exports.componentWithoutRelPeriodSlash = componentWithoutRelPeriodSlash;
11+
exports.componentWithSpacing = componentWithSpacing;
1012

test/loader.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,23 @@ describe("loader", function() {
9595
);
9696
});
9797

98+
it("Should convert html and style file strings to require()s regardless of spacing", function(){
99+
100+
loader.call({}, fixtures.componentWithSpacing)
101+
.should
102+
.be
103+
.eql(`
104+
import {Component} from '@angular/core';
105+
106+
@Component({
107+
selector : 'test-component',
108+
template: require('./some/path/to/file.html'),
109+
styles: [require('./app/css/styles.css')]
110+
})
111+
export class TestComponent {}
112+
`
113+
)
114+
115+
});
98116

99117
});

0 commit comments

Comments
 (0)