Skip to content

Commit dadf8ec

Browse files
rafaelss95mgechev
authored andcommitted
feat: add support for svg templates (#800)
1 parent bd2a7a8 commit dadf8ec

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/angular/config.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { CodeWithSourceMap } from './metadata';
22

33
export interface StyleTransformer {
4-
(style: string, url?: string): CodeWithSourceMap;
4+
(code: string, url?: string): CodeWithSourceMap;
55
}
66

77
export interface TemplateTransformer {
8-
(template: string, url?: string): CodeWithSourceMap;
8+
(code: string, url?: string): CodeWithSourceMap;
99
}
1010

1111
export interface UrlResolver {
@@ -14,9 +14,11 @@ export interface UrlResolver {
1414

1515
export const LogLevel = { Debug: 0b111, Error: 0b001, Info: 0b011, None: 0 };
1616

17+
type ValueOf<T> = T[keyof T];
18+
1719
export interface Config {
1820
interpolation: [string, string];
19-
logLevel: number;
21+
logLevel: ValueOf<typeof LogLevel>;
2022
predefinedDirectives: DirectiveDeclaration[];
2123
resolveUrl: UrlResolver;
2224
transformStyle: StyleTransformer;
@@ -33,10 +35,17 @@ export interface DirectiveDeclaration {
3335
selector: string;
3436
}
3537

38+
const CSS_FILE_EXTENSION = '.css';
39+
const HTML_FILE_EXTENSION = '.html';
40+
const SVG_FILE_EXTENSION = '.svg';
3641
let BUILD_TYPE = '<%= BUILD_TYPE %>';
3742

38-
const transform = (code: string, extension: '.css' | '.html', url?: string): { code: string; url?: string } => {
39-
return { code: !url || url.endsWith(extension) ? code : '', url };
43+
type FileExtension = typeof CSS_FILE_EXTENSION | typeof HTML_FILE_EXTENSION | typeof SVG_FILE_EXTENSION;
44+
45+
const transform = (code: string, fileExtensions: ReadonlyArray<FileExtension>, url?: string): { code: string; url?: string } => {
46+
const parsedCode = !url || fileExtensions.some(fileExtension => url.endsWith(fileExtension)) ? code : '';
47+
48+
return { code: parsedCode, url };
4049
};
4150

4251
export const Config: Config = {
@@ -71,13 +80,11 @@ export const Config: Config = {
7180
{ selector: 'md-select', exportAs: 'mdSelect' }
7281
],
7382

74-
resolveUrl(url: string | null) {
75-
return url;
76-
},
83+
resolveUrl: (url: string | null) => url,
7784

78-
transformStyle: (code: string, url?: string) => transform(code, '.css', url),
85+
transformStyle: (code: string, url?: string) => transform(code, [CSS_FILE_EXTENSION], url),
7986

80-
transformTemplate: (code: string, url?: string) => transform(code, '.html', url)
87+
transformTemplate: (code: string, url?: string) => transform(code, [HTML_FILE_EXTENSION, SVG_FILE_EXTENSION], url)
8188
};
8289

8390
try {

0 commit comments

Comments
 (0)