grunt-contrib-handlebars icon indicating copy to clipboard operation
grunt-contrib-handlebars copied to clipboard

Rendering HTML directly

Open mehcode opened this issue 12 years ago • 23 comments

I'd like to add support for grunt-contrib-handlebars to allow it to render handlebars templates directly to HTML.

Thoughts on option names ?

handlebars: {
  options: {
    target: 'html',  // Defaults to 'js' ?
    data: {
      // Context goes here
      foo: 3251
    }
  }
}

Something like the above.. unless you have a better idea for the target name.

mehcode avatar Feb 08 '13 06:02 mehcode

Target seems reasonable to me.

/cc @tbranyen @sindresorhus thoughts?

tkellen avatar Feb 08 '13 16:02 tkellen

Sure, I would probably go with type though, since target already is described as task targets, might be confusing, I dunno.

sindresorhus avatar Feb 08 '13 17:02 sindresorhus

Good point, overloading the target term hadn't even occurred to me.

tkellen avatar Feb 08 '13 17:02 tkellen

Perhaps output instead of type? Good point on target.

mehcode avatar Feb 08 '13 17:02 mehcode

How many other types are there? It's not really HTML you're rendering, it's text. I'd say this is a precompile vs. render flag.

tbranyen avatar Feb 08 '13 17:02 tbranyen

render: true ?

sindresorhus avatar Feb 08 '13 17:02 sindresorhus

The only reason I was thinking type or target was because of my https://github.com/concordusapps/grunt-haml project that allows a target of js, coffee, or html.

mehcode avatar Feb 08 '13 17:02 mehcode

But JS and Coffee in this case represent means to the same end, once the coffee is converted to JS they are both precompiled templates, while what you're requesting sits outside of that as completely rendered templates. These feel distinct enough to be treated separately.

Maybe:

// Precompile to JS.
precompile: {} // or true

// Precompile with options.
precompile: {
  coffeescript: true
}

// Render to text (default to html extension).
render: {} // or true

// Rendering with options.
render: {
  ext: "html"
}

This isn't really standard for Grunt, but maybe something along these lines. I could foresee wanting both precompiled and rendered.

tbranyen avatar Feb 08 '13 17:02 tbranyen

But JS and Coffee in this case represent means to the same end

True but in order to properly compile coffee-script and remove as much bloat (all of the duplicate helpers from it, etc.) you need to intelligently concatenate all of your coffee-script before compiling. Not that I do this yet. However as coffee-script provides no way to remove these helpers on a per-file basis this kind of thing will eventually be required as some quick testing on my end shows a 15% reduction in final output size between compiling ~50 coffee then merging or merging then compiling 1 coffee. But that's also not really related to this. I just brought it up as I want the config syntax between this and grunt-haml to be the same-ish.

With that said I'd probably prefer a precompile flag like the following (that way I could extend it in grunt-haml to achieve the coffee thing):

// Precompile
precompile: true // default

precompile: false // render the html

precompile: {
  output: 'js' // default
}

precompile: {
  output: 'coffee'
}

precompile: {
  output: 'livescript'
}

On a completely unrelated note... has any thought about doing grunt-contrib-template? There is a consolidate task out there but it doesn't do pre-compilation.

mehcode avatar Feb 08 '13 17:02 mehcode

There have been several attempts (some by me) to smash every templating engine into the same round hole, but it always winds up being a monolithic mess of configuration options to support each templating engine's unique features. That said, taking the output of a precompiled template and wrapping it with an AMD define call, or assigning it to a JST namespace could definitely be generalized into grunt-lib-contrib. I'd love to see something like that.

tkellen avatar Feb 08 '13 17:02 tkellen

:+1:

outaTiME avatar Mar 26 '13 14:03 outaTiME

there is some work being done on gruntjs/grunt-contrib-jade#19 that could give us a coherent standard for implementing this sort of thing across all of our templating tasks.

tkellen avatar Mar 26 '13 14:03 tkellen

:thumbsup: +1 for this option

tnguyen14 avatar Jun 30 '13 19:06 tnguyen14

What ended up happening with this?

pspeter3 avatar Jul 11 '13 22:07 pspeter3

:+1: +1

mitsuruog avatar Oct 01 '13 13:10 mitsuruog

Any news about this? :confused:

oswaldoacauan avatar Oct 23 '13 19:10 oswaldoacauan

+1

paparomeo avatar Jan 17 '14 07:01 paparomeo

+1

johannesjo avatar Apr 17 '14 21:04 johannesjo

It would be nice to create static sites, +1

rludgero avatar Jul 27 '14 22:07 rludgero

Any news?

rludgero avatar Sep 27 '14 10:09 rludgero

+1

tschiela avatar Apr 28 '15 13:04 tschiela

Hello everybody! Someone is working on it? Any news about this?

rludgero avatar Sep 20 '15 14:09 rludgero

+1

matteoantoci avatar Oct 20 '15 21:10 matteoantoci