News for hackers. Stuff that matters.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by crabasa on Wednesday April 03, 2013 @11:30AM (#5486689)
It is worth noting that the OP is calling this tool pithy (terse, meaningful). In an application I'm working on [1] I have several lines of jQuery and string concatenation to build some simple content.

It's probably overkill to use a full-blown client-side templating engine, but my current code leaves much to be desired. I think pithy.js might be a great fit.

[1] https://github.com/crabasa/seattlehacks/blob/gh-pages/calend...

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by sophacles on Wednesday April 03, 2013 @03:16PM (#5488367)
This is almost identical in operation to laconic https://github.com/joestelmach/laconic what advantages does this have?
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by atirip on Wednesday April 03, 2013 @02:08PM (#5487852)
Nope. Avoid. Switch to templates at the moment you think you need this kind of a solution. Use for example super comoact http://archan937.github.com/templayed.js/ Compared to almost full blown mustache implementation, pithy.js, surprise, is a bloat. Sorry of being harsh, as a positive note, the code itself, in abstract way is my liking. Very good. May even steal some snippets.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by sophacles on Wednesday April 03, 2013 @03:13PM (#5488354)
Ahh yes, the old "trusty-hammer" argument. Sometimes this exact sort of library is needed, and quite useful. More than once I've found myself doing single-tag or 2-tag templates and composing them in code, with bits for passing in class name or id, and later selecting them to change some property. Basically the use case for a library like this.

Templates are useful, so are tag generation code snippets. Both go in my toolbox just fine.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by atirip on Wednesday April 03, 2013 @03:35PM (#5488477)
For your case this is all what you need: function replace(str, data) { for( var i in data ) str = str.replace('{'+i+'}', data[i]); return str; }
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by sophacles on Wednesday April 03, 2013 @03:49PM (#5488560)
Oh, now I see the light. I don't even need templates, just dozens of str.replaces littered throughout my code. Now I can throw away all these weird screw things, and just have nails!

/sarcasm

My point still stands, no matter what you think you read in my post, different tools for different jobs is OK, there is no "silver bullet" (or magic-hammer or whatever).

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by atirip on Wednesday April 03, 2013 @04:29PM (#5488827)
whatever
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by jimmytucson on Wednesday April 03, 2013 @03:18PM (#5488381)
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by muxxa on Wednesday April 03, 2013 @11:24AM (#5486632)
Almost identical functionality appears as part of MochiKit, and I've found it very useful for quick and clean DOM creation:

http://mochi.github.com/mochikit/doc/html/MochiKit/DOM.html

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by dropdownmenu on Wednesday April 03, 2013 @11:03AM (#5486466)
Pretty cool project, but I feel kind of dirty having js and html being so tightly bound to each other. Do you have a specific use case where pithy would perform faster or be more cleanly implemented than standard templates?
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by danso on Wednesday April 03, 2013 @11:18AM (#5486588)
From the OP's documentation, I don't think it's intended to be used for large templates where speed of render is important. It's main benefit seems to be as a more readable, less-error-prone alternative to string concatenation, such as in small snippets that are created by client-side-update methods.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by grimtrigger on Wednesday April 03, 2013 @12:21PM (#5487024)
I work on an enterprise platform where I have client side access, but no server side access. My only options for injecting HTML are:

1) cross domain AJAX via CORS

2) Injecting HTML strings constructed in JS

For small amounts of HTML, I'd much rather go with option #2.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by Zelphyr on Wednesday April 03, 2013 @11:29AM (#5486686)
Why is everyone so afraid of HTML that they insist on starting projects like this? I've seen them come and go for 15+ years now and they're never useful. Even less so in the case of using JS to generate HTML because that makes the browser actually work harder.

This isn't a knock against OP or the project creator (if they're not one and the same) because projects like these can be useful exercises. But I would never use something like this in production and I would hope nobody else would either.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by hellerbarde on Wednesday April 03, 2013 @01:07PM (#5487350)
What do you mean by "afraid of HTML"?

I haven't used this yet, so bear that in mind, but to me this seems to be something that is more expressive than html (I meant String) concatenation. That leads, in my experience, to better maintainability and thus less worries in the future.

Whether this impacts JS performance enough to be a problem, I don't know and don't have the time to test right now.

Edit: words are hard... I accidentally a few of them.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by grimtrigger on Wednesday April 03, 2013 @12:24PM (#5487046)
I work on an enterprise platform where I have client side access, but no server side access. My only options for injecting HTML are:

1) cross domain AJAX via CORS

2) Injecting HTML strings constructed in JS

For small amounts of HTML, I'd much rather go with option #2.

ps. Its unfortunately very common for developers to have little or no server side access to the applications they're building.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by crescentfresh on Wednesday April 03, 2013 @12:32PM (#5487090)
Wait, are you rolling up all client templating libraries into 2) or something?
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by grimtrigger on Wednesday April 03, 2013 @12:39PM (#5487148)
My understanding of "client templating libraries" is that they sit on the server, and create code that will be delivered to the client. For example moustache.

If you can easily avoid a call to the server, it might be a good idea.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by bsimpson on Wednesday April 03, 2013 @05:26PM (#5489234)
Client side templating libraries like Handlebars do in the browser what server side libraries like Jinja do in the cloud.

You've described server-side libraries. Client-side do the exact same thing in JS on the client.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by spyder on Wednesday April 03, 2013 @04:01PM (#5488660)
Also there is DOMBuilder https://github.com/insin/DOMBuilder which has separate modes for using HTML mock elements on (node.js) server-side or DOM elements in browsers. The mock elements are implementing only a very small set of the DOM functions, but if you extend it a little then it can be useful to share Backbone-like views between server and client.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by grimtrigger on Wednesday April 03, 2013 @10:51AM (#5486377)
Awesome! Would be useful if there were callbacks for binding events after the node has been created.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by pettazz on Wednesday April 03, 2013 @11:05AM (#5486482)
I suppose it's probably just a matter of trying to keep things as simple as possible. You're already specifying all the attributes of the nodes you're creating, so you can just as easily then bind them yourself. UNIX philosophy and all that.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by grimtrigger on Wednesday April 03, 2013 @12:35PM (#5487111)
Just an argument for why I think its pretty important (maybe your use case is different so this doesn't apply).

With every HTML injection, I'd have to cycle through all relavant nodes, sorting out the ones that have already been binded, and then apply the relevant bindings. With a dynamic app that injects a lot of small HTML parts, this could be quite painful.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by caolanm on Wednesday April 03, 2013 @11:56AM (#5486865)
Currently it generates a HTML string rather than DOM Elements but if it did it would be cool to be able to add onclick handlers etc in the attributes argument.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by ajitk on Wednesday April 03, 2013 @12:50PM (#5487220)
I prefer https://github.com/jed/domo to create DOM elements in browser. Its output is a real DOM element whereas in pithy.js, its string.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by crabasa on Wednesday April 03, 2013 @01:08PM (#5487357)
It might just be me, but I can't stand all of the capitalization.
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by Bjoern on Wednesday April 03, 2013 @12:36PM (#5487124)
This is quite interesting, thank you for open sourcing it.

I can see how this can be helpful cleaning up e.g. common string concatenation snippets in code bases.

Re:Pithy.js - An internal DSL for generating HTML in JavaScript by gohwell on Wednesday April 03, 2013 @02:57PM (#5488262)
Pardon my ignorance... What is a DSL?
Re:Pithy.js - An internal DSL for generating HTML in JavaScript by bchar on Wednesday April 03, 2013 @03:01PM (#5488287)