Coder Social home page Coder Social logo

Comments (12)

esamattis avatar esamattis commented on June 23, 2024

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.

thlorenz avatar thlorenz commented on June 23, 2024

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.

esamattis avatar esamattis commented on June 23, 2024

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.

thlorenz avatar thlorenz commented on June 23, 2024

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.

esamattis avatar esamattis commented on June 23, 2024

I tested it (again) manually in the browser and yes, it works as expected.

from node-hbsfy.

esamattis avatar esamattis commented on June 23, 2024

I think you don't see the helper because it is build in the user code, not in the compiled template.

from node-hbsfy.

thlorenz avatar thlorenz commented on June 23, 2024

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.

esamattis avatar esamattis commented on June 23, 2024

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.

thlorenz avatar thlorenz commented on June 23, 2024

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.

esamattis avatar esamattis commented on June 23, 2024

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.

thlorenz avatar thlorenz commented on June 23, 2024

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.

esamattis avatar esamattis commented on June 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.