This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NgBaseCss): Add NgBaseCss, which adds css files to all components
- Loading branch information
Showing
6 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
part of angular.directive; | ||
|
||
@NgDirective( | ||
selector: '[ng-base-css]', | ||
visibility: NgDirective.CHILDREN_VISIBILITY | ||
) | ||
class NgBaseCss { | ||
List<String> _urls = const []; | ||
|
||
@NgAttr('ng-base-css') | ||
set urls(v) => _urls = v is List ? v : [v]; | ||
|
||
List<String> get urls => _urls; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
library ng_base_css_spec; | ||
|
||
import '../_specs.dart'; | ||
|
||
@NgComponent( | ||
selector: 'html-and-css', | ||
templateUrl: 'simple.html', | ||
cssUrl: 'simple.css') | ||
class _HtmlAndCssComponent {} | ||
|
||
main() => describe('NgBaseCss', () { | ||
beforeEachModule((Module module) { | ||
module | ||
..type(_HtmlAndCssComponent); | ||
}); | ||
|
||
it('should load css urls from ng-base-css', async((TestBed _, MockHttpBackend backend) { | ||
backend | ||
..expectGET('base.css').respond('.base{}') | ||
..expectGET('simple.css').respond('.simple{}') | ||
..expectGET('simple.html').respond('<div>Simple!</div>'); | ||
|
||
var element = e('<div ng-base-css="base.css"><html-and-css>ignore</html-and-css></div>'); | ||
_.compile(element); | ||
|
||
backend.flush(); | ||
microLeap(); | ||
|
||
expect(element.children[0].shadowRoot).toHaveHtml( | ||
'<style>.base{}</style><style>.simple{}</style><div>Simple!</div>' | ||
); | ||
})); | ||
|
||
it('ng-base-css should overwrite parent ng-base-csses', async((TestBed _, MockHttpBackend backend) { | ||
backend | ||
..expectGET('base.css').respond('.base{}') | ||
..expectGET('simple.css').respond('.simple{}') | ||
..expectGET('simple.html').respond('<div>Simple!</div>'); | ||
|
||
var element = e('<div ng-base-css="hidden.css"><div ng-base-css="base.css"><html-and-css>ignore</html-and-css></div></div>'); | ||
_.compile(element); | ||
|
||
backend.flush(); | ||
microLeap(); | ||
|
||
expect(element.children[0].children[0].shadowRoot).toHaveHtml( | ||
'<style>.base{}</style><style>.simple{}</style><div>Simple!</div>' | ||
); | ||
})); | ||
|
||
describe('from injector', () { | ||
beforeEachModule((Module module) { | ||
module.value(NgBaseCss, new NgBaseCss()..urls = ['injected.css']); | ||
}); | ||
|
||
it('ng-base-css should be available from the injector', async((TestBed _, MockHttpBackend backend) { | ||
backend | ||
..expectGET('injected.css').respond('.injected{}') | ||
..expectGET('simple.css').respond('.simple{}') | ||
..expectGET('simple.html').respond('<div>Simple!</div>'); | ||
|
||
var element = e('<div><html-and-css>ignore</html-and-css></div></div>'); | ||
_.compile(element); | ||
|
||
backend.flush(); | ||
microLeap(); | ||
|
||
expect(element.children[0].shadowRoot).toHaveHtml( | ||
'<style>.injected{}</style><style>.simple{}</style><div>Simple!</div>' | ||
); | ||
})); | ||
}); | ||
}); |