Hi Guys,
Not sure if anyone has done this for a while ( I certainly couldn’t find anything ).
I’m balls deep in Blaze right now so when doing a project outside of Meteor I thought it would be nice to be able to preserve the nice reactive/declarative data binding/templating Blaze gives you. However, it seems MDG currently have a standalone on their to-do list but haven’t looked at it for a while.
Also, due to the popularity of of frameworks like React etc right now there doesn’t seem to be much demand for this sort of thing - so I had to do it myself.
Was a bit of a pain having to rip the necessary packages and their dependencies out of a bundled Meteor app (1.2.1) and there’ll be a bit of redundant rubbish in there right now as I haven’t cleaned it up a great deal yet, but it all works at least
Here’s a gist with the file in (minified and unminified for those that want to clean it up a bit). https://gist.github.com/calvin-evans/0bb115030c7785087002
Just include in your page and you’re good to go - you’ll just need to define your templates, could do this by traversing the DOM and looking for <template>
tags or something.
In my app I’m rendering as much as I can server-side with handlebars then injecting Blaze templates in the client. I’m far from an elegant solution, but if anyone is interested I’m currently doing the following… use at your own risk
<script>
var renderFuncCode;
var name;
{{#templates}}
renderFuncCode = SpacebarsCompiler.compile($($.parseHTML("{{template}}")).text(), {isTemplate: true});
name = "{{{name}}}";
{{#if (devEnv)}}console.log("Adding Template: " + name);{{/if}}
// TODO: remove eval()
eval("Template.__define__(" + JSON.stringify(name) + ", " + renderFuncCode + ");");
{{/templates}}
Blaze.Var = ReactiveVar;
</script>