diff --git a/src/app/shared/stackblitz/stackblitz-writer.ts b/src/app/shared/stackblitz/stackblitz-writer.ts index e159910f9..6506170c6 100644 --- a/src/app/shared/stackblitz/stackblitz-writer.ts +++ b/src/app/shared/stackblitz/stackblitz-writer.ts @@ -87,7 +87,7 @@ export class StackblitzWriter { // TODO(josephperrott): Prevent including assets to be manually checked. if (data.selectorName === 'icon-svg-example') { - this._readFile(form, data, 'assets/img/examples/thumbup-icon.svg', ''); + this._readFile(form, data, 'assets/img/examples/thumbup-icon.svg', '', false); } Promise.all(templateContents.concat(exampleContents)).then(() => { @@ -114,22 +114,42 @@ export class StackblitzWriter { form.appendChild(input); } - /** Reads the file and adds its text to the form */ - _readFile(form: HTMLFormElement, data: ExampleData, filename: string, path: string): void { + /** + * Reads the file and adds its text to the form + * @param form the html form you are appending to + * @param data example metadata about the example + * @param filename file name of the example + * @param path path to the src + * @param prependApp whether to prepend the 'app' prefix to the path + */ + _readFile(form: HTMLFormElement, + data: ExampleData, + filename: string, + path: string, + prependApp = true): void { this._http.get(path + filename).toPromise().then( - response => this._addFileToForm(form, data, response.text(), filename, path), + response => this._addFileToForm(form, data, response.text(), filename, path, prependApp), error => console.log(error)); } - /** Adds the file text to the form. */ + /** + * Adds the file text to the form. + * @param form the html form you are appending to + * @param data example metadata about the example + * @param content file contents + * @param filename file name of the example + * @param path path to the src + * @param prependApp whether to prepend the 'app' prefix to the path + */ _addFileToForm(form: HTMLFormElement, data: ExampleData, content: string, filename: string, - path: string) { + path: string, + prependApp = true) { if (path == TEMPLATE_PATH) { content = this._replaceExamplePlaceholderNames(data, filename, content); - } else { + } else if (prependApp) { filename = 'app/' + filename; } this._appendFormInput(form, `files[${filename}]`, this._appendCopyright(filename, content));