-
Notifications
You must be signed in to change notification settings - Fork 395
feat(plnkr): Add initial version of openPlunker #26
Conversation
|
||
TAGS: string[] = ['angular', 'material', 'example']; | ||
|
||
description: string = 'Example for Angular Material'; |
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.
Maybe add all of these to some kind of ExampleDescriptor class?
import { PlunkerUtil } from './plnkr-util'; | ||
|
||
@Component({ | ||
selector: 'app-plnkr', |
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.
Maybe "plunker-example"? (also be consistent with plnkr vs plunker, my vote is for everything to be "plunker")
@@ -0,0 +1,104 @@ | |||
<div class="demo-button"> |
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 know these will eventually go in a separate npm package, but maybe for now put them in assets/examples?
@@ -0,0 +1,36 @@ | |||
<!DOCTYPE html> |
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.
can go in assets/plunker
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 still advocate moving the template files to assets, they're not really part of the application source
selector: 'app-plnkr', | ||
templateUrl: 'plnkr.html', | ||
}) | ||
export class Plunker implements OnInit { |
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.
How about calling this PlunkerButton
with selector plunker-button
?
can be found in the LICENSE file at http://angular.io/license`; | ||
|
||
TEMPLATE_PATH = '/app/shared/plnkr/template/'; | ||
TEMPLATE_FILES = ['index.html', 'systemjs.config.js', 'main.ts']; |
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.
We can move these constants outside the class since they're effectively private. That way we don't have to refer to them with this
@@ -0,0 +1,109 @@ | |||
import { Http } from '@angular/http'; | |||
|
|||
export class PlunkerUtil { |
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.
How about something like PlunkerWriter
, PlunkerExporter
, or PlunkerConnector
?
cc @mmalerba
exampleFiles: string[] = ['button-demo.html', 'button-demo.scss', 'button-demo.ts']; | ||
selectorName: string = 'button-demo'; | ||
indexFilename: string = 'button-demo'; | ||
componentName: string = 'ButtonDemo'; |
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.
Would it make sense to have a separate PlunkerData
class that you construct and pass around rather than storing all of these properties directly on the service?
@@ -0,0 +1,109 @@ | |||
import { Http } from '@angular/http'; | |||
|
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.
Can you add a top-level comment here that gives an explanation of the Plunker API since it doesn't seem to be documented anywhere on their site?
return form; | ||
} | ||
|
||
_generateInput(name: string, value: string, isFile = false) { |
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'd call this _createFormInput
if (filename.indexOf('.ts') > -1 || filename.indexOf('.scss') > -1) { | ||
content = content + '/** ' + this.COPYRIGHT + ' */'; | ||
} else if (filename.indexOf('.html') > -1) { | ||
content = content + '<!-- ' + this.COPYRIGHT + ' -->'; |
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.
Use a template string for these:
`${content}\n\n/** ${COPYRIGHT} */`
`${content}\n\n<!-- ${COPYRIGHT} -->`
} | ||
} | ||
|
||
if (filename.indexOf('.ts') > -1 || filename.indexOf('.scss') > -1) { |
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 would break this out into its own method _appendCopyright
} | ||
|
||
_processContent(filename: string, path: string, content: string): string { | ||
if (path == this.TEMPLATE_PATH) { |
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 don't quite follow what these replacements are for.
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.
Added comments
(response) => { | ||
let content = response.text(); | ||
content = this._processContent(filename, path, content); | ||
this._generateInput(filename, content, true); |
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'd break these out into separate handler functions:
this._http.get(path + filename).subscribe(
response => this._addFileToForm(response.text()),
error => console.log(error));
Where _addFileToForm
massages the file content and adds the input. Then you could remove the isFile
argument from _createFormInput
and pass the files[${name}]
as the name (since you know specifically you're processing a file).
Added PlunkerData and changed PlunkerUtil to PlunkerWriter. PTAL. Thanks for review! |
* private: true | ||
* } | ||
*/ | ||
export class PlunkerWriter { |
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.
You can add the @Injectable
decorator to this to turn it into a service and add it to the providers
list of the app's NgModule
. Then PlunkerButton
can inject this (instead of http) and this service can inject Http
directly.
TEMPLATE_PATH = '/app/shared/plnkr/template/'; | ||
TEMPLATE_FILES = ['index.html', 'systemjs.config.js', 'main.ts']; | ||
|
||
TAGS: string[] = ['angular', 'material', 'example']; |
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 think you missed moving these constants out of the class
; they can go right above it (example)
content = this._processTemplateFile(filename, path, content); | ||
} | ||
this._createFormInput(`files[${filename}]`, this._appendCopyright(filename, content)); | ||
this._submitForm(); |
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.
Did you mean to move this _submitForm
call to the end of openPlunker
?
// For example, <material-docs-example></material-docs-exmaple> will be replaced as | ||
// <button-demo></button-demo> | ||
content = content.replace(new RegExp('material-docs-example', 'g'), | ||
this.exampleData.selectorName); |
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.
You could use a regex literal:
content = content.replace(/material-docs-example/g, this.exampleData.selectorName),
this._submitForm(); | ||
} | ||
|
||
_processTemplateFile(filename: string, path: string, content: string): string { |
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.
How about
/**
* The Plunker template assets contain placeholder names for the examples:
* "<material-docs-example>" and "MaterialDocsExample".
* This will replace those placeholders with the names from the example metadata,
* e.g. "<basic-button-example>" and "BasicButtonExample"
*/
_replaceExamplePlaceholderNames(fileName: string, fileContent: string) { ... }
I also noticed that the path
argument seems to not be used in this function.
Comments addressed. Please take another look. Thanks! |
@@ -0,0 +1 @@ | |||
export * from './plunker-button'; |
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.
Change the directory name to plunker
* Plunker data | ||
* with information about Component name, selector, files used in example, and path to examples | ||
*/ | ||
export class PlunkerData { |
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 think this is fine for this CL, but this stuff isn't actually related to plunker at all, it should be called ExampleData and should probably live in the material2 repo eventually.
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.
Changed the name to ExampleData. I think we can extract information (selector, componentName) from example file. I will work on that in another PR.
@@ -0,0 +1,36 @@ | |||
<!DOCTYPE html> |
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 still advocate moving the template files to assets, they're not really part of the application source
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.
Thanks for review. Moved template files to assets/plunker.
* Plunker data | ||
* with information about Component name, selector, files used in example, and path to examples | ||
*/ | ||
export class PlunkerData { |
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.
Changed the name to ExampleData. I think we can extract information (selector, componentName) from example file. I will work on that in another PR.
5884c5b
to
0f81773
Compare
Added test for plunker-writer |
LGTM |
Actually, I just noticed that |
Updated - fixed NavBar and integrated with example view. Moved example-data to a better place |
LGTM, we can update to use the real examples in a follow-up PR. |
R: @jelbourn @mmalerba