yeoman / generator-polymer

Scaffold out a Polymer project
http://polymer-project.org
926 stars 149 forks source link

Import to new custom element inserted in routes section in elements.html file #192

Closed peterblazejewicz closed 9 years ago

peterblazejewicz commented 9 years ago

When using yo polymer:element my-element the user is asked if she wants to import newly created custom element into elements.html:

? Would you like to include an import in your elements.html file? (y/N) 

If the answer is positive (not default), the import is added - but into routings section - not into elements import section:

diff --git a/app/elements/elements.html b/app/elements/elements.html
index 780a8a1..3b104a5 100755
--- a/app/elements/elements.html
+++ b/app/elements/elements.html
@@ -36,3 +36,4 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
  <!-- Configure your routes here -->
 <link rel="import" href="routing.html">
+<link rel="import" href="my-element/my-element.html">

That is unfortunate I think, especially for user that is starting with framework or routes/imports.

Maybe that can be easily fixed by just moving imports section to the end of elements.html template, as the subgenerator routine just appends newly created element import to the end of the file? Just swap these two sections places (and in original starter kit template): https://github.com/yeoman/generator-polymer/blob/master/el/index.js#L89-L94 https://github.com/yeoman/generator-polymer/blob/master/app/templates/polymer-starter-kit/app/elements/elements.html#L32-L38 https://github.com/PolymerElements/polymer-starter-kit/blob/master/app/elements/elements.html#L32-L38

Thanks!

arthurvr commented 9 years ago

Yeah, that's indeed not really the behaviour people will like. There's really no right way to do that though. We could do some regex magic but that would already break when people start changing the order or tweak the comments.

peterblazejewicz commented 9 years ago

Maybe the issue should be moved to PSK first? The very first (at least public) commit to PSK would have not cause the problem when adding elements, as the last one section was dedicated to custom elements: https://github.com/PolymerElements/polymer-starter-kit/commit/42fa0d6a8fb4ea3872c05e22dd3b2dd7f369790e https://github.com/PolymerElements/polymer-starter-kit/blob/42fa0d6a8fb4ea3872c05e22dd3b2dd7f369790e/app/elements/elements.html

robdodson commented 9 years ago

Hm yeah the easiest option would be for the add your elements to appear after the routing section in PSK. @addyosmani is that an annoying change to make? If so we could add something to the generator to maybe work around it

addyosmani commented 9 years ago

I'm fine with that change being made (it's pretty minimal and really doesn't impact end users negatively afaics). Would someone like to open a corresponding issue on PSK and we'll get that made?

arthurvr commented 9 years ago

=> https://github.com/PolymerElements/polymer-starter-kit/pull/177 should fix this.

peterblazejewicz commented 9 years ago

I you guys are OK with https://github.com/PolymerElements/polymer-starter-kit/pull/177 I could close this one as the change will be added at some point in the future

robdodson commented 9 years ago

sounds good to me :)

arthurvr commented 9 years ago

PR landed.