-
Notifications
You must be signed in to change notification settings - Fork 26.5k
feat(url_resolver): support package: urls (fixes #2991) #3215
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<style>@import "angular2_material/src/components/button/button.css";</style> | ||
<style>@import "package:angular2_material/src/components/button/button.css";</style> | ||
<span class="md-button-wrapper"><ng-content></ng-content></span> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import {Component, View} from 'angular2/angular2'; | ||
|
||
@Component({selector: 'md-progress-circular'}) | ||
@View({templateUrl: 'angular2_material/src/components/progress-circular/progress_circular.html'}) | ||
@View({ | ||
templateUrl: 'package:angular2_material/src/components/progress-circular/progress_circular.html' | ||
}) | ||
export class MdProgressCircular { | ||
constructor() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<style>@import "angular2_material/src/components/radio/radio-group.css";</style> | ||
<style>@import "package:angular2_material/src/components/radio/radio-group.css";</style> | ||
<ng-content></ng-content> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
library angular2_examples.material.demo_common; | ||
|
||
import 'package:angular2/src/dom/browser_adapter.dart'; | ||
import 'package:angular2/src/services/url_resolver.dart'; | ||
|
||
void commonDemoSetup() { | ||
BrowserDomAdapter.makeCurrent(); | ||
} | ||
|
||
class DemoUrlResolver extends UrlResolver { | ||
|
||
@override | ||
String resolve(String baseUrl, String url) { | ||
const MATERIAL_PKG = 'package:angular2_material/'; | ||
|
||
// We run a proxy server in front of pub serve that prepends "example" to | ||
// paths | ||
if (url.startsWith(MATERIAL_PKG)) { | ||
return '/examples/packages/angular2_material/' + url.substring(MATERIAL_PKG.length); | ||
} | ||
return super.resolve(baseUrl, url); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,67 +18,16 @@ export function commonDemoSetup(): void { | |
|
||
@Injectable() | ||
export class DemoUrlResolver extends UrlResolver { | ||
static a; | ||
|
||
isInPubServe: boolean; | ||
|
||
constructor() { | ||
super(); | ||
if (isBlank(DemoUrlResolver.a)) { | ||
DemoUrlResolver.a = DOM.createElement('a'); | ||
} | ||
this.isInPubServe = _isInPubServe(); | ||
} | ||
|
||
resolve(baseUrl: string, url: string): string { | ||
if (isBlank(baseUrl)) { | ||
DOM.resolveAndSetHref(DemoUrlResolver.a, url, null); | ||
return DOM.getHref(DemoUrlResolver.a); | ||
} | ||
|
||
if (isBlank(url) || url == '') { | ||
return baseUrl; | ||
} | ||
|
||
if (url[0] == '/') { | ||
return url; | ||
} | ||
|
||
var m = RegExpWrapper.firstMatch(_schemeRe, url); | ||
|
||
if (isPresent(m[1])) { | ||
return url; | ||
// The standard UrlResolver looks for "package:" templateUrls in | ||
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. If you make the 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. leaving |
||
// node_modules, however in our repo we host material widgets at the root. | ||
if (url.startsWith('package:angular2_material/')) { | ||
return '/' + url.substring(8); | ||
} | ||
|
||
if (StringWrapper.startsWith(url, './')) { | ||
return `${baseUrl}/${url}`; | ||
} | ||
|
||
// Whether the `examples/` dir is being directly served (as the server root). | ||
// For cases when this is not true AND we're in pub-serve, `examples/` needs to be | ||
// prepended to the URL. | ||
var isDirectlyServingExamplesDir = !StringWrapper.contains(baseUrl, 'examples/'); | ||
|
||
if (this.isInPubServe && isDirectlyServingExamplesDir) { | ||
return `/packages/${url}`; | ||
} else if (this.isInPubServe) { | ||
return `/examples/packages/${url}`; | ||
} else { | ||
return `/${url}`; | ||
} | ||
} | ||
} | ||
|
||
var _schemeRe = /^([^:/?#]+:)?/g; | ||
|
||
// TODO: remove this hack when http://dartbug.com/23128 is fixed | ||
function _isInPubServe(): boolean { | ||
try { | ||
int.parse('123'); | ||
print('>> Running in Dart'); | ||
return true; | ||
} catch (_) { | ||
print('>> Running in JS'); | ||
return false; | ||
return super.resolve(baseUrl, url); | ||
} | ||
} |
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.
@yjbanov @sigmundch Bit late to the party on this, but I would argue that we should not add the leading slash here. It should be reading from the packages directory next to the entry point, not the root of the server. Imagine running a server with two completely separate angular apps in two different subfolders for instance.
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.
I did not know this was possible in pub serve. I'll change it to be relative to
AppRootUrl
(which I believe is our entry point URL path) and see what happens.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.
Pub serve can only serve one "package", so it shouldn't be an issue there. Where it would an issue is when running a normal server in a folder which contains two different angular apps in different folders, which were built using pub build but template inlining was turned off. Also in development mode if you wanted to run a simple server in a parent directory of a few angular apps (in dartium).