-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pod blueprints for generators #1619
Comments
|
I've just started looking at pods, and wanted a generator for it. The way I thought it could work would be something like I did
This requires the name passed to the generator to include the pods folder prefix, and then the route folder names: It would be nice if the generator was aware of the applications podModulePrefix, and would only run if this has been set sensibly, and use the value after the first / It would be interesting to explore the options you could pass to the pod generator, --no-controller, --no-route, --no-template, maybe. Having some way to include or exclude particular files from the generation. |
I had a great conversation with @trabus on IRC about pod support for generators. I believe he’s made some progress already. |
I've just been experimenting with ideas, nothing quite working yet, but I noticed the I was thinking that The blueprints would require some file folder renaming, so the folder/path name and the file name were both tokens, and could be interchangeable for both structures:
We'd need to do some sort of checking to make sure files aren't overwritten, but this would allow the core blueprints to be reused for both standard modules and pods. It would also allow pod based nested routes to be generated by defining the path as suggested by @peterchoo. We could also make use of the I really like the -s pods idea as well, calling the type of blueprint you want makes more sense to me than calling a pod blueprint. We could just setup the options for generating the pod, then call That's pretty much what I have so far, I was going to start writing some tests to support the idea tonight at the Seattle Ember meetup. |
I've got a rough pass at the mapFile rewrite, still working on building up some good tests for it, but it works for the existing tests and the basic ones I wrote for it. Blueprint.prototype.mapFile = function(file, locals) {
var pattern, i;
var fileMap = locals.fileMap || {__name__: locals.dasherizedModuleName};
file = Blueprint.renamedFiles[file] || file;
for(i in fileMap){
pattern = new RegExp(i, 'g');
file = file.replace(pattern, fileMap[i]);
}
return file;
}; This pattern allows you to pass a fileMap object in the options for installBlueprint (which still needs to be extracted into a blueprint method), which would allow more than just the default |
I was thinking about what I wrote earlier, and I'm not sure there even needs to be a separate pods blueprint at all. Also the multiple The pod structure setup could be a simple method of the blueprint model that transforms the paths into pod structure and gets executed somewhere towards the beginning of the install method (if the pod structure is passed). The fileMap would be in place already, so then there's no need for There would be very little modification needed for existing blueprints, and most of it would consist of adding the necessary tokens into the file folder structure (i.e. Anyhow, just some more thoughts I wanted to dump before falling asleep. Would love to hear input on whether this sounds like I'm heading in the right direction. |
I'm going to create a method on the Blueprint prototype called I am also going to begin writing some tests that will check several permutations of resolvable paths that are generated by this method. |
I made some pretty good progress today, I ended up creating a couple methods (and hooks) to generate the Regarding tests, I ended up getting stuck trying to write some tests, and decided to go forward with the prototyping before I lost the idea. Now that I have something working fairly well, I'm going to write some tests next before I polish it up for a PR. The work in its current state is here: |
I found a better solution for the Default __name__: function(options) {
if (options.pods) {
return options.name;
}
return options.dasherizedModuleName;
},
__path__: function(options) {
if (options.pods) {
return options.podPath+options.dasherizedModuleName;
}
return options.name+'s'; // TODO: use inflector pluralize(options.name);
},
__test__: function(options) {
return options.dasherizedModuleName;
} The standard tokens are module.exports = Blueprint.extend({
fileMapTokens: function() {
return {
__token__: function(options) {
// this could be a series of checks and returns
// as long as it returns a value
return 'value';
}
};
}, The Some fileMapOptions are defined in locals and passed to var fileMapOptions = {
pods: options.pods,
podPath: options.podPath,
name: this.name,
dasherizedModuleName: stringUtils.dasherize(moduleName)
}; Now that I have something I'm happy with, I'm going to finally write some tests this week, including a suite of pods- generate and destroy tests. |
+1 I've been following the updates on here, and I've gotta say thank you for your work on something that's gone way deeper than my prototype blueprint :) can't wait to see this in the CLI! |
Sounds like it’s really coming together. Can’t wait for it to land. |
+1 |
I have been thinking about the flag for pods, and unless another structure other than default and pods is expected to come about, |
just opening this here for some discussion on having generators for the pod structure. Since it's supported we should likely have the option of the default generators supporting this structure. With that said, the question is how?
Proposed solutions:
it could even be a setting in
.ember-cli
and then the normal generator commands would work and the blueprint would have to implement a normal structure and a pod one.My thoughts
I'm leaning towards number 2. It's clear in exactly what it's doing and doesn't confuse blueprint options with the style of structure you want. It should be as easy as adding some more blueprints and no unnecessary code debt or complexity would be added.
Thoughts?
The text was updated successfully, but these errors were encountered: