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

helper factories #25

Open
shannonmoeller opened this issue Apr 23, 2015 · 8 comments
Open

helper factories #25

shannonmoeller opened this issue Apr 23, 2015 · 8 comments

Comments

@shannonmoeller
Copy link

There is a need to have template (and thereby Assemble and Verb) optionally provide the rendering engine to helper modules. Several existing helpers expect this behavior already:

I'd love to see an update to the .helper and .helpers methods to support this. Off the top of my head, perhaps something like the following:

// expect `foo-helper` to be a factory function
template.helper('foo', { factory: true }, require('foo-helper'));  
template.helpers({ factory: true }, require('foo-helpers'));

// expect `foo-helper` to export a factory function called `register`
template.helper('foo', { factory: 'register' }, require('foo-helper'));
template.helpers({ factory: 'register' }, require('foo-helpers'));

This would also provide a helper-specific solution to #6:

template.helper('foo', { options: { ... } }, require('foo-helper'));  
@jonschlinkert
Copy link
Owner

@shannonmoeller I might need a little more perspective on use-case to understand what you're asking for. In particular, we wanted to move away from the .register method that was used in 0.4.x since it made registering helpers a chore.

This pattern isn't really idiomatic for assemble 0.6.0, users won't be be able to use the register method with assemble once the handlebars-helpers updates are merged to master.

also, #6 was resolved already, but possibly not by being able to add the options directly to the .helper() method. I guess I'm open to this, I'm just not sure why it's needed yet

@shannonmoeller
Copy link
Author

It's a recommendation for a solution to this pattern that doesn't involve explicitly requiring engine-assemble in addition to the already required assemble:

var assemble = require('assemble');
var engine = require('engine-assemble');
var layouts = require('handlebars-layouts');

assemble.engine('hbs', engine);
assemble.helpers(layouts(engine.Handlebars));

With the proposed pattern, the above becomes:

var assemble = require('assemble');
var layouts = require('handlebars-layouts');

assemble.helpers({ factory: true }, layouts);

@jonschlinkert
Copy link
Owner

I noticed you closed and locked the related issue. You are aware that this is a feature request, and not a bug, correct?

@shannonmoeller
Copy link
Author

Yep! Sorry about the lock. Habit.

That said, I'm not sure that handlebars-layouts is the right repo to continue the discussion.

@jonschlinkert
Copy link
Owner

okay, just making sure. I'm still mulling this over, there might be a different approach.

@shannonmoeller
Copy link
Author

Sounds good! Thanks!

@jonschlinkert
Copy link
Owner

@shannonmoeller we completely refactored this lib (and moved it to templates actually. the plan is to use this lib for the base "view" class). we're finally at the point where I'd love to circle back to some of these issues. I'm not sure if you're still looking for this issue to be resolved, but I'm happy to hear any feedback.

@shannonmoeller
Copy link
Author

I definitely want to make sure that my plugins remain compatible with template and assemble.

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

No branches or pull requests

2 participants