Repository navigation
feat(core): provide support for relative assets for components #5634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,30 @@ class StringWrapper { | |
| return s == s2; | ||
| } | ||
|
|
||
| static String stripLeft(String s, String charVal) { | ||
| if (isPresent(s) && s.length > 0) { | ||
| var pos = 0; | ||
| for (var i = 0; i < s.length; i++) { | ||
| if (s[i] != charVal) break; | ||
| pos++; | ||
| } | ||
| s = s.substring(pos); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| static String stripRight(String s, String charVal) { | ||
| if (isPresent(s) && s.length > 0) { | ||
| var pos = s.length; | ||
| for (var i = s.length - 1; i >= 0; i--) { | ||
| if (s[i] != charVal) break; | ||
| pos--; | ||
| } | ||
| s = s.substring(0, pos); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you just do one |
||
| } | ||
| return s; | ||
| } | ||
|
|
||
| static String replace(String s, Pattern from, String replace) { | ||
| return s.replaceFirst(from, replace); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,30 @@ export class StringWrapper { | |
|
|
||
| static equals(s: string, s2: string): boolean { return s === s2; } | ||
|
|
||
| static stripLeft(s: string, charVal: string): string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| if (s && s.length) { | ||
| var pos = 0; | ||
| for (var i = 0; i < s.length; i++) { | ||
| if (s[i] != charVal) break; | ||
| pos++; | ||
| } | ||
| s = s.substring(pos); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| static stripRight(s: string, charVal: string): string { | ||
| if (s && s.length) { | ||
| var pos = s.length; | ||
| for (var i = s.length - 1; i >= 0; i--) { | ||
| if (s[i] != charVal) break; | ||
| pos--; | ||
| } | ||
| s = s.substring(0, pos); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| static replace(s: string, from: string, replace: string): string { | ||
| return s.replace(from, replace); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/testing_internal'; | ||
| import { | ||
| describe, | ||
| it, | ||
| expect, | ||
| beforeEach, | ||
| ddescribe, | ||
| iit, | ||
| xit, | ||
| el, | ||
| inject | ||
| } from 'angular2/testing_internal'; | ||
| import {IS_DART} from 'angular2/src/facade/lang'; | ||
| import {UrlResolver} from 'angular2/src/compiler/url_resolver'; | ||
|
|
||
| export function main() { | ||
|
|
@@ -69,14 +80,50 @@ export function main() { | |
| expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar'); | ||
| expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('corner and error cases', () => { | ||
| it('should encode URLs before resolving', () => { | ||
| expect(resolver.resolve('foo/baz', `<p #p>Hello | ||
| </p>`)) | ||
| .toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E'); | ||
| it('should not resolve urls against the baseUrl when the url contains a scheme', () => { | ||
| resolver = new UrlResolver('my_packages_dir'); | ||
| expect(resolver.resolve("base/", 'package:file')).toEqual('my_packages_dir/file'); | ||
| expect(resolver.resolve("base/", 'http:super_file')).toEqual('http:super_file'); | ||
| expect(resolver.resolve("base/", './mega_file')).toEqual('base/mega_file'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('packages', | ||
| () => { | ||
| it('should resolve a url based on the application package', () => { | ||
| resolver = new UrlResolver('my_packages_dir'); | ||
| expect(resolver.resolve(null, 'package:some/dir/file.txt')) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test where the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test is still missing... |
||
| .toEqual('my_packages_dir/some/dir/file.txt'); | ||
| expect(resolver.resolve(null, 'some/dir/file.txt')).toEqual('some/dir/file.txt'); | ||
| }); | ||
|
|
||
| it('should contain a default value of "/packages" when nothing is provided for DART', | ||
| inject([UrlResolver], (resolver) => { | ||
| if (IS_DART) { | ||
| expect(resolver.resolve(null, 'package:file')).toEqual('/packages/file'); | ||
| } | ||
| })); | ||
|
|
||
| it('should contain a default value of "/" when nothing is provided for TS/ESM', | ||
| inject([UrlResolver], (resolver) => { | ||
| if (!IS_DART) { | ||
| expect(resolver.resolve(null, 'package:file')).toEqual('/file'); | ||
| } | ||
| })); | ||
|
|
||
| it('should resolve a package value when present within the baseurl', () => { | ||
| resolver = new UrlResolver('/my_special_dir'); | ||
| expect(resolver.resolve('package:some_dir/', 'matias.html')) | ||
| .toEqual('/my_special_dir/some_dir/matias.html'); | ||
| }); | ||
| }) | ||
|
|
||
| describe('corner and error cases', () => { | ||
| it('should encode URLs before resolving', () => { | ||
| expect(resolver.resolve('foo/baz', `<p #p>Hello | ||
| </p>`)).toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E'); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| library playground.e2e_test.relative_assets.assets_spec; | ||
|
|
||
| main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just do one
substringat the end of the function?