-
Notifications
You must be signed in to change notification settings - Fork 77
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
Abstracting module definition. #17
Abstracting module definition. #17
Conversation
+1 I am totally in favor of this. |
.pipe(declare({ | ||
namespace: 'MyApp.templates' | ||
.pipe(defineModule('plain', { | ||
wrapper: 'MyApp.templates['<%= name %>'] = <%= handlebars %>' |
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.
gulp-declare
does much more than this -- it splits the template name on dots and defines the namespaces required along the entire path. This is a required and very common use case for gulp-handlebars, so we'll need to add back the same example that exists currently in addition to the gulp-define-module
.
Can you please re-add that example in your pull request?
I like it. Let's merge this after you address the inline comments. Thanks! |
@@ -3,67 +3,64 @@ | |||
|
|||
## Usage | |||
|
|||
First, install `gulp-handlebars` as a development dependency: | |||
First, install _gulp-handlebars_ and [gulp-define-module] as development dependencies: |
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.
Package names should be wrapped in inline code blocks
, not italics.
@lazd hopefully that last commit addresses all of the comments you made. Let me know if you'd like anything else changed. |
@wbyoung, will review shortly. Should we wait on wbyoung/gulp-define-module#1 to simplify the documentation? |
@lazd probably not. I may not get to it until sometime next week, so if you have time now, I'd move forward with this. Then we can perhaps get some feedback and start iterating on the changes if need be. |
@wbyoung, I think it'll be a documentation issue at the end of the day and won't actually affect the code for |
Great! |
var concat = require('gulp-concat'); | ||
|
||
gulp.task('templates', function(){ | ||
gulp.src(['client/templates/*.hbs']) | ||
.pipe(handlebars()) | ||
.pipe(defineModule('plain')) |
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.
Hmm, defineModule('plain')
is only required to add the Handlebars.template
call. If wrapped
was still an option to gulp-handlebars
, then gulp-define-module
would not be required at all for this use case. @wbyoung, thoughts?
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.
Ahh… just lost the comment I typed out… rewriting.
I had the same thought when I just this example. I see it both ways. I approached this trying to abstract as much as possible from these 3 plugins and I may have been a little overzealous.
The case for putting the wrapper in gulp-handlebars
is that it's pretty specific to the plugin and arguably you can't do anything with the output of the plugin if you haven't wrapped it yet. Also, the result is still a function either way.
The case for putting it in gulp-define-module
is that it access Handlebars
, and as you mentioned before, you'd then need a require
in there. Also, it does achieve a little more abstraction. Finally, gulp-handlebars
could be seen only as a compiler, so it should handle just that one thing.
Honestly, I think both are "right" and I have no problem with it either way.
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.
Yeah, I think it makes sense to use gulp-define-module
or gulp-wrap
to add it. We're good here :)
This is looking really good. I'll merge after wbyoung@e2ab0b8 is handled. Feel free to squash your commits and force push back to your branch if you like (not required). |
I commented on that previous change and why I think it should still be there, but please feel free to overrule here. I also squashed the commits. |
Looking pretty good, I have a few minor nitpicks but I'll quickly correct them after merge. Going to check out the branch and pick through it, then will merge. Probably won't have time until tomorrow, though. Thanks for the hard work! |
…tion Use gulp-define-module for module definition
Background
I wanted to create a new plugin, gulp-ember-emblem.
There are multiple forks of gulp-handlebars. They seem to have been forked at a different point in time, and they haven't been pulling in changes from from gulp-handlebars as changes have been made. That got me thinking… how can I abstract this a bit so that some of the functionality can change more independently.
I came up with gulp-define-module.
Request
As you'll see from the request, this is a pretty radical change. I'm hoping that we can somehow either collaborate to get this into each of the plugins that forked from the gulp-handlebars repo. And I think this could end up being a better solution for the gulp community as a whole since it will result in more continuity between each of these plugins.
The basic idea here is that module definition, AMD, Node, CommonJS, or just plain browser can be pulled out into its own module. The resulting gulp flow looks something like this:
This module also has the possibility of replacing gulp-declare, but I'd probably only recommend that for the simple cases (where you know the namespace already exists).