Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper functions for jade #248

Closed
jamesknelson opened this issue Feb 14, 2014 · 12 comments
Closed

Helper functions for jade #248

jamesknelson opened this issue Feb 14, 2014 · 12 comments

Comments

@jamesknelson
Copy link

How hard would it be to allow harp.json to actually be a harp.js, where functions can be assigned to globals, as well as standard JSON - so that helper functions could be created? Is there an existing way to get helpers in a jade template (without placing the functions in the actual jade files)?

@cfjedimaster
Copy link

Any reason why this would need to be for Jade only?

@jamesknelson
Copy link
Author

Not really, I guess it could be for EJS too.

@kennethormandy
Copy link
Collaborator

Right now about the only thing you can do is place the functions in the actual Jade (or EJS) files, or possibly use partial to bring in a different Jade file the functions there, which can be kind of unpredictable. I think I finally understand the use case for supporting _data.js as well as _data.json! sintaxi/terraform#8

Edit
Actually, it might be worth trying something with Jade mixins, too. I haven’t played with them enough to know, but they could be helpful here. There’ also a PR open on Jade that will hopefully help making writing the functions inline easier (this is covered in EJS since it’s not dependant on whitespace.)

@jamesknelson
Copy link
Author

The mixins unfortunately don't do what I'd like to do (I'd like to make a function which generates URLs, instead of hard-coding all my URLs). I've already tried just writing it inline, but its a mess.

The Jade pull request sounds interesting though. I had a quick look, but couldn't find it - do you know which one it is?

@kennethormandy
Copy link
Collaborator

@jamesknelson pugjs/pug#1397 was what I was thinking of. Sounds like your use case might overlap with #149, though?

@wulftone
Copy link

I'd like to see this as well--been trying to figure out how to get a function inside the #{} syntax. I don't think harp has a way for us to pass objects to templates, it's all hidden.

@philholden
Copy link

I am using minification to put JS on a single line in a Jade template and then include where needed:

//- Underscore.js 1.6.0
//- http://underscorejs.org
//- (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
//- Underscore may be freely distributed under the MIT license.
- (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.pro ...

In our templates we can include it where needed:

include ../_underscore.jade
- var a = {b:1, c:2}
!= _.clone(a)

It is a bit clumsy so I would love to have the ability to load JS into a Jade layout or specify it in the _data.json.

{
  "index": {"helpers":["underscore.js"]}
}

@jamlfy
Copy link

jamlfy commented Jan 21, 2015

+1

1 similar comment
@suisho
Copy link

suisho commented Feb 5, 2015

+1

@lunelson
Copy link

I made a PR to terraform to expose lodash to templates

@sintaxi
Copy link
Owner

sintaxi commented Oct 1, 2015

I dig it. Just merged into terraform. Will likely be in next release of harp.

@sintaxi sintaxi closed this as completed Oct 1, 2015
@cfjedimaster
Copy link

So what exactly is being added - harp.hs? Or the helpers thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants