diff --git a/Gruntfile.js b/Gruntfile.js index f2126c0c..233796a8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -72,6 +72,7 @@ module.exports = function (grunt) { {expand: true, src: 'config.js', dest: '<%- sitePath %>/<%- pkg.version %>/'}, {expand: true, src: 'ng2-material/**/*', dest: '<%- sitePath %>/<%- pkg.version %>/'}, {expand: true, src: 'dist/*.*', dest: '<%- sitePath %>/<%- pkg.version %>/'}, + {expand: true, cwd: 'public/font/', flatten: true, src: ['*.*'], dest: '<%- sitePath %>/<%- pkg.version %>/dist/'}, {expand: true, src: 'public/**/*', dest: '<%- sitePath %>/<%- pkg.version %>/'}, {expand: true, src: 'examples/**/*', dest: '<%- sitePath %>/<%- pkg.version %>/'} ] @@ -101,6 +102,7 @@ module.exports = function (grunt) { src: [ "examples/*.scss", "examples/**/*.scss", + "public/font/*.scss", "<%- sourceRoot %>/all.scss", "<%- sourceRoot %>/components/**/*.scss" ], diff --git a/ng2-material/all.ts b/ng2-material/all.ts index 39470960..03c7df31 100644 --- a/ng2-material/all.ts +++ b/ng2-material/all.ts @@ -1,4 +1,5 @@ import {CONST_EXPR, Type} from 'angular2/src/facade/lang'; +import {provide} from 'angular2/core'; import {MdAnchor, MdButton} from './components/button/button'; export * from './components/button/button'; @@ -44,6 +45,7 @@ import {MdToolbar} from './components/toolbar/toolbar'; export * from './components/toolbar/toolbar'; import {MdTabs, MdTab} from './components/tabs/tabs'; +import {UrlResolver} from "angular2/compiler"; export * from './components/toolbar/toolbar'; /** @@ -66,9 +68,47 @@ export const MATERIAL_DIRECTIVES: Type[] = CONST_EXPR([ MdTab, MdTabs ]); + +/** + * Reference to specified base load URL for templates and styles. + * @private + */ +var BASE_URL: string = null; + +/** + * Specify the baseUrl to load templates and styles from. + * @param url + */ +export function setBaseUrl(url: string) { + BASE_URL = url; +} + +/** + * This is a workaround to tell us where to load templates and styles from until + * we have a better template bundling strategy. + */ +export class MaterialTemplateResolver extends UrlResolver { + static RESOURCE_MATCHER: RegExp = /^ng2-material\/.*?\.(html|css)$/; + + resolve(baseUrl: string, url: string): string { + if (!BASE_URL) { + return super.resolve(baseUrl, url); + } + if (baseUrl.startsWith(BASE_URL)) { + baseUrl = baseUrl.substr(0, BASE_URL.length); + } + let result = super.resolve(baseUrl, url); + if (MaterialTemplateResolver.RESOURCE_MATCHER.test(result)) { + return `${BASE_URL}${result}`; + } + return result; + } +} + /** * Collection of Material Design component providers. */ -export const MATERIAL_PROVIDERS: Type[] = CONST_EXPR([ - MdRadioDispatcher -]); +export const MATERIAL_PROVIDERS: any[] = [ + MdRadioDispatcher, + provide(UrlResolver, {useValue: new MaterialTemplateResolver()}) +];