Comments (12)
Thanks for the input. I will look more closely into this later, but for now I can say that helpers are at least working.
from node-hbsfy.
That looks ok, although I'm not sure if it doesn't just get that helper somehow from the Handlebars you define up top. Could you possibly paste the precompiled template here, that would give a better insight.
Additionally you should think about running your tests in a more integrated scenario (i.e. with a full bundle executing in the vm like is done here).
That way you would rule these things out.
It will be super nice to have a plug able handlebar transform working, so I hope you'll figure this all out. Very happy to see this!
from node-hbsfy.
Could you possibly paste the precompiled template here
var Handlebars = require('handlebars-runtime');
module.exports = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Handlebars.helpers; data = data || {};
var buffer = "", stack1, options, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
buffer += "<h1>";
options = {hash:{},data:data};
buffer += escapeExpression(((stack1 = helpers.upcase),stack1 ? stack1.call(depth0, depth0.msg, options) : helperMissing.call(depth0, "upcase", depth0.msg, options)))
+ "</h1>\n";
return buffer;
});
Additionally you should think about running your tests in a more integrated scenario (i.e. with a full bundle executing in the vm like is done here). That way you would rule these things out.
Yes, definitely! The current test case was just something I was able to come up with in 2 minutes :)
from node-hbsfy.
I see nothing in that template that builds up the helper. Therefore if you load this into the browser it would most likely break, but I'm not sure. Unless of course you include the helper somewhere else and it initializes itself with the Handlebars
instance, but when using your transform, I shouldn't have to do that.
You could just manually test by actually producing a bundle and loading that into the browser, then requiring the precompiled template and executing it - console logging the result. If it works then, you of course got it made - at least for helpers ;)
from node-hbsfy.
I tested it (again) manually in the browser and yes, it works as expected.
from node-hbsfy.
I think you don't see the helper because it is build in the user code, not in the compiled template.
from node-hbsfy.
Nice, although I'm not sure how the helper would get registered, if it is not itself also part of the bundle. Otherwise, how would Handlebars know what the upcase
function is?
Are you requireing/including the helper somewhere so it initializes itself as a Handlebars
helper browser side?
Bottom line if it works, it works, so great :).
Will have to give this a try soon (given you get partials working as well).
from node-hbsfy.
Checkout this example I just added: https://github.com/epeli/node-hbsfy/tree/master/example
Especially take a look into index-bundle.js
Nice, although I'm not sure how the helper would get registered, if it is not itself also part of the bundle. Otherwise, how would Handlebars know what the upcase function is?
It is part of the bundle. It's just not part of the template.
Are you requireing/including the helper somewhere so it initializes itself as a Handlebars helper browser side?
Yes.
from node-hbsfy.
Got it, somehow it was included.
Actually this only works because the helper is part of your index which is also your entry, so it gets sourced and the helper added to Handlebars.
However it should also work if it wasn't.
I'd like to just give hbsfy a glob path to my helpers, i.e (./helpers/**/*.js
) and it should go from there. I don't however want to somehow include all my helpers manually (i.e. via a big file that requires all of them) and then have to worry about sourcing them before using the template.
So the template should itself require all the helpers it needs.
If all that happens automatically (i.e. when using hbsfy I don't have to do this myself) then that is awesome.
Basically this api is what I'd want (adapted to browserify v2 of course).
from node-hbsfy.
Actually this only works because the helper is part of your index which is also your entry, so it gets sourced and the helper added to Handlebars.
Yes. You have to explicitly require all the code that goes into the bundle. This is not a code injection tool.
However it should also work if it wasn't.
That would require some implicit assumptions about where you store the helpers which is out of the scope for this module.
I'd like to just give hbsfy the path to my helpers and it should go from there.
I don't know if that is even possible when using the browserify
cli tool.
However I think you could build some other tool on top of this to do that. Or even fork this one directly since this has so little code :)
Nevertheless I want to keep this module as the low level hbs module without magic.
from node-hbsfy.
That is certainly an approach and I agree with your points.
Puts responsibility back on the user, but you are right, there could be another tool. I'm thinking of one that you pass a browserify instance to and it adds all templates and helpers to it.
Actually this approach is even better than what I requested since that keeps concerns clearly separate.
The only thing left to figure out is how to handle partials.
from node-hbsfy.
Partials work out of the box too! :)
I've documented it on the readme and the example also uses partials now.
https://github.com/epeli/node-hbsfy/blob/e4f62efa822/example/index.js#L5
from node-hbsfy.
Related Issues (20)
- Show original markup in source map HOT 3
- Errors on comments HOT 4
- comiling templates in the node_modules folder HOT 2
- Doesn't work with handlebars installed locally HOT 1
- example use-cases of hbsfy HOT 4
- Upgrade version of handlebars HOT 10
- How to not include runtime with hbsfy HOT 6
- way to use helpers from another bundle inside another bundle? HOT 1
- peerDep HOT 2
- `ParseError: Unexpected end of input` no matter what 😭 HOT 2
- use global Handlebars HOT 2
- Require hook (server side node). HOT 1
- installs binaries to node_modules instead of node_modules/.bin HOT 2
- hbsfy with --traverse fails with inline partials HOT 12
- Hbsfy fails to use aliases while using --traverse HOT 8
- Using helpers through command-line HOT 3
- Babel plugin HOT 1
- Error: You specified knownHelpersOnly, but used the unknown helper HOT 2
- Quick Templates – compile from string HOT 1
- honor Browserify "paths" when resolving partials? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-hbsfy.