Giter VIP home page Giter VIP logo

Comments (12)

pstephens avatar pstephens commented on August 27, 2024

I currently use vash templates to generate static content. It doesn't seem that this is currently a supported scenario, but I was able to make it work by using some undocumented functions.

For example, currently I do this at the global level:

vash.config.settings = vash.config.settings || {};
vash.config.settings.views = path.resolve('./views');

And then when I render the template I do it like this:

var rendered = tpl(model, function sealLayout(err, ctx) {
    ctx.finishLayout(); // TODO: undocumented
});

from vash.

UweKeim avatar UweKeim commented on August 27, 2024

Me too! I'm also planning on using it inside a product (Windows desktop application) to generate static HTML files to be later uploaded to a webserver (through a completely other component).

Altough I'm just starting to evaluate your engine, I would love to have everthing that makes generating static files for local disk storing easier 👍

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@pstephens, that's awesome, and although undocumented, is pretty much how it's supposed to work. One thing I might change in 0.8 is that the layout helpers may become a separate package, but should keep the api the same.

@UweKeim if you do find things working or not, please let me know so I can try to make it easier. Right now static files are pretty easy, although when you start using the layout helpers they get a bit more complex.

You should be able to do something like:

$ vash --json '{ "settings": { "views": "path/to/views/root/" } }' --file main-static-entry.vash --render --out index.html

from vash.

UweKeim avatar UweKeim commented on August 27, 2024

Thanks, @kirbysayshi! Being new to GitHub, I've put a feature request here since I did not find a "real" discussion forum. Is this the correct way of doing it?

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

Yes, vash's GH issues area also functions as a discussion forum. I thought it best to keep things consolidated.

from vash.

dizlexik avatar dizlexik commented on August 27, 2024

Hey @kirbysayshi, any ETA on when 0.8 might be rolling out? I'm starting a new project soon'ish and would love to have 0.8 included from the start. I'm mostly interested in the streaming support because I'd like to build my response pipeline around streams.

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@dizlexik Contrary to what I said above, the next version will likely not have streaming support, as it's already taken too long to get out and I haven't actually implemented it yet. But in the meantime, you can probably do something like this to "fake" stream, depending on what you actually want streaming to mean:

(warning, untested code)

var vash = require('vash');
var through = require('through2');

somestream.pipe(vashstream()).on('data', function(tpl) {
  tpl({ blah: 'ok?' });
});

function vashstream() {
  var buf = '';
  return through(function(chunk, enc, cb) {
    buf += chunk;
    cb();
  }, function(cb) {
    this.push(vash.compile(buf));
    cb();
  });
}

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

btw @dizlexik, what does streaming support mean to you? The parsing/compilation of the template, or the rendering? I'm guessing only the parsing/compilation is doable as a stream.

from vash.

dizlexik avatar dizlexik commented on August 27, 2024

Thanks for the stopgap code. I'll be using Koa and was hoping for something to the effect of this.body = tpl.stream(mymodel). My goal is to start sending my response immediately and not have to buffer the entire thing into memory first. Although the more I think about it the more I'm not even sure that makes sense with vash since there's really no concept of async operations within a template as far as I'm aware.

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

That's where my thinking has been leading as well: I'm not sure streaming has a significant value for a template that is essentially synchronous.

One thing I haven't experimented with at all is generators within a template, which would then blow the entire synchronous model apart. Perhaps a future version of vash...

~ Drew

On Mar 2, 2015, at 2:21 PM, Joe Lutz [email protected] wrote:

Thanks for the stopgap code. I'll be using Koa and was hoping for something to the effect of this.body = tpl.stream(mymodel). My goal is to start sending my response immediately and not have to buffer the entire thing into memory first. Although the more I think about it the more I'm not even sure that makes sense with vash since there's really no concept of async operations within a template as far as I'm aware.


Reply to this email directly or view it on GitHub.

from vash.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

Going to close, as 0.8.0 has been released with a mostly unchanged api.

from vash.

lyphtec avatar lyphtec commented on August 27, 2024

I've been looking into Koa recently, and came across the Marko template engine that does streamed template rendering and supports async rendering of HTML fragments as it leverages progressive rendering in the browser. Check out this short screencast about it.

This looks interesting and maybe can provide some inspiration for Vash to support similar features :)

from vash.

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.