Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blueprints (formerly generators) #351

Closed
4 tasks
stefanpenner opened this issue Apr 13, 2014 · 48 comments
Closed
4 tasks

blueprints (formerly generators) #351

stefanpenner opened this issue Apr 13, 2014 · 48 comments
Labels

Comments

@stefanpenner
Copy link
Contributor

  • update existing generators blueprints to be idiomatic
  • explore scaffolding
  • tests
  • allow projects to override of custom generator blueprint needs (ala rails generator templates)

see: #43

@stefanpenner
Copy link
Contributor Author

@nathanhammond you mentioned "homework" this one, if you are interesting this one may be a good fit

@nathanhammond
Copy link
Contributor

@stefanpenner I meant in terms of general beta testing. :) I'm trying to avoid volunteering for too much so I can spend more cycles on ember-flows-generator.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 23, 2014

I’m going to put some time into this. If anyone wants to join forces, let me know.

@tonycoco
Copy link

I'd be willing to help @jgwhite

@jgwhite
Copy link
Contributor

jgwhite commented Apr 24, 2014

@tonycoco cool. I'm going to make a start on Sunday. Acceptance tests will be point of entry. Will be in #ember-cli :)

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

Is everyone happy to proceed with the current format for generated modules:

var FooController = Ember.Controller.extend({});

export default FooController;

Does anyone prefer the terser alternative?

export default Ember.Controller.extend({});

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

Couple of decisions after discussing with @rjackson:

  1. We’re going to go with the terser style
  2. The built-in generators will take their cues from those in ember-app-kit-rails

@eccegordo
Copy link

I am not sure what to call it but I am wondering if there is something between a full generator, and something more like a snippet generator that emits common ember code patterns. I would love to have a command along the lines of

ember g controller foo/bar --stub

That writes a file to

app/controllers/foo/bar.js

And stubs out a common dummy example of hypothetical controller. Ideally with a bunch of common stub code.

If not directly supported would be nice if ember cli had the ability to create your own snippets and stubs just by putting source files in a special directory.

The ember-app-kit-rails generators have been super awesome.

By way of example:

The above command could in theory create the file and push something like this inside:

export default Ember.Controller.extend({
  needs: ['foo'],

  myProperty: "bar value",

  cpBar: function() {
    var value = this.get('myProperty') + "bar";
    return value;
  }.property('myProperty'),

  actions: {
    handleAction: function(input){
      var message = "Hello " + input;
      this.send('prompt', message);
    },

    prompt: function(msg){
      alert(msg);
    }
  }

});

This may be hard to generalize but it would be nice if there was a way to store these common snippets and other custom shortcuts in an ember cli config folder somewhere. I am getting super lazy with my typing. :-)

Some of this can be be achieved via text editor commands e.g. "snippets" in sublime text. I started to build something for sublime text and EAK.
https://github.com/eccegordo/eak-sublime-text-snippets

But would love to have a small library of these from the ember cli prompt that were more file based in scope. Or multiple files.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

@eccegordo what you describe is pretty much the goal. Great minds :)

Custom generators will live in a generators/ directory at the top level of the project. They’ll be made available automagically. You’ll also be able to override templates for the built-in generators using the same mechanism.

@MajorBreakfast
Copy link
Contributor

Quick idea: Call generators stencils to avoid confusion with javascript generators? :)

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

@MajorBreakfast interesting thought. I like the term stencil a lot. Though we do already have blueprint. One counterpoint, generators are known and well understood concept for those familiar with Rails.

@MajorBreakfast
Copy link
Contributor

@jgwhite ya, "blueprint" and "template" are taken. That's why I propose "stencil" :)

@stefanpenner
Copy link
Contributor Author

Generate something based on a blueprint seems fine?

@MajorBreakfast
Copy link
Contributor

@stefanpenner We already call the initial project structure "blueprint".

@rwjblue
Copy link
Member

rwjblue commented Apr 28, 2014

@MajorBreakfast - If you think about it these are the exact same thing. A "blueprint" is a number of files used as a template. Both the new "generators" (only used to explain what I mean) and the current blueprint/ directory conform to this definition.

The only change that I think we might need is to move blueprint/ to blueprints/init/ (or something like that).

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

@rjackson Agreed. Blueprints is nicely unambiguous and doesn’t conflict with any other naming conventions (generators, templates).

'ember-cli/blueprints/init' // blueprint for generating project
'ember-cli/blueprints/{controller,route,...}' // blueprints for generating application code
'my-app/blueprints/{foo,bar,baz}' // custom blueprints
'my-app/blueprints/{controller,route,...}' // custom blueprint overrides

@MajorBreakfast
Copy link
Contributor

Hmm good point :) I like it.

I also like that both can be powered by the same logic.(Even the overwrite confirmation stuff)

@jgwhite What about

  • ember-cli/blueprints/init/
    • blueprint.js
    • files/

The blueprint defined in blueprint.js could inherit from Blueprint like we currently do it with Commands and Tasks

@stefanpenner
Copy link
Contributor Author

Yup and now that we have diffing it will be even nicer

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

Props to @mixonic

@tonycoco
Copy link

Just chiming in, instead of blueprint we could call it "bootstrap"... probably a bit more common.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

@tonycoco personally I’d tend to think of “bootstrap” more as a verb. The terminology we seem to be settling upon is using “blueprints” to “generate” projects and files.

@MajorBreakfast
Copy link
Contributor

@tonycoco I agree with @jgwhite, also I already associate "bootstrap" with the css framework.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

@MajorBreakfast good point

@MajorBreakfast MajorBreakfast changed the title generators blueprints (formerly generators) Apr 28, 2014
@MajorBreakfast
Copy link
Contributor

@stefanpenner I changed the issue title and description.

What verb do we use with "blueprint"? To "generate" a "blueprint" seems to imply the wrong thing. It's more like "use", "apply" (not good in js :), "employ" or "utilize". I'd keep ember generate <...>, though.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 28, 2014

I think blueprint and generate work fine together. We’re generating files from blueprints, rather than generating blueprints.

@tonycoco
Copy link

I think that works, @jgwhite

@MajorBreakfast
Copy link
Contributor

@jgwhite you're right. It's as simple as that.

@stefanpenner
Copy link
Contributor Author

@jgwhite anything i can do to help you out on this?

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@stefanpenner yes. I’d love everyone’s opinion on the acceptance tests and blueprints.

The task itself is a placeholder — I plan to write the real implementation following the remaining test TODOs.

@stefanpenner
Copy link
Contributor Author

@jgwhite that looks rad. i skimmed the tests and didn't see:

generate model foo/bar covered, does that scenario work?

Also, it appears I can't open issues on that repo. Do you mind submitting a PR, it would make (even early) review + feedback easier.

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@stefanpenner yup — turns out the existing blueprint.js handled it already without modification. The template test covers it, but can add more of these cases.

@stefanpenner
Copy link
Contributor Author

@jgwhite perfect!

Thoughts on removing more default app/* folders as they will be added on-demand as generators are needed? The reasoning is to try and present something less intimidating.

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@stefanpenner yeah, I was thinking the same. Be interested to get some newcomers’ perspectives on this. Is it more reassuring to see just the essentials, or a clear structure ready and waiting?

@stefanpenner
Copy link
Contributor Author

@jgwhite essentials i think.

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

app
├── app.js
├── components
├── controllers
├── index.html
├── models
├── router.js
├── routes
│   └── index.js
├── styles
│   └── app.css
├── templates
│   └── application.hbs
└── views

or super-skinny?:

app
├── app.js
├── index.html
├── router.js
├── styles
│   └── app.css
└── templates
    └── application.hbs

@MajorBreakfast
Copy link
Contributor

Essentials and I am for encouraging pods! Sorting by type isn't the most logical thing and we know it :)

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@MajorBreakfast would be cool to re-ignite the discussion on discourse.

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

Also: I’m down with adding a service blueprint modelled after @tomdale’s proposal.

@stefanpenner
Copy link
Contributor Author

@jgwhite I think I prefer the middle ground, although the super skinny might be nice as a community blueprint or something.

ember new --blueprint mini (or some URI to the mini blueprint) or something

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@stefanpenner nice idea. We should add that to the roadmap.

@MajorBreakfast
Copy link
Contributor

@jgwhite The resolver already supports pods, we just have to use 'em. We can't really discuss it further unless we have results that show how the current iteration works in practice.

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

@MajorBreakfast I’ve not tried them yet. How are you picturing the generator commands? Something like this?:

ember generate pod foo
ember generate controller pod:foo

Keen to discuss in more detail. I’m in #ember-cli if you wanna take the conversation there.

@MajorBreakfast
Copy link
Contributor

A pods setting in the .ember-cli could determine the default.
ember generate controller foo

To force it:
ember generate controller foo --pods true
ember generate controller foo --pods false

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

So:

ember generate controller foo --pods true  => app/foo/controller.js
ember generate controller foo --pods false => app/controllers/foo.js

@stefanpenner
Copy link
Contributor Author

singular pod flag

@jgwhite
Copy link
Contributor

jgwhite commented May 13, 2014

👍

@coderberry
Copy link

❤️

@stefanpenner
Copy link
Contributor Author

tracking this now on #747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants