Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

fix(stackblitz): fix svg path getting extra /app #400

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/app/shared/stackblitz/stackblitz-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now would be a good time to add param descriptions, since prependApp is the first really non-obvious one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments. :)

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));
Expand Down