This is just plain awesome. Using the project to generate the page's HTML is brilliant, if not an exercise in depravity. However, it seriously needs a better name. Since you've built it as a jQuery plguin and not as its own library, I recommend that it be renamed to something like jQuery.create.
For those who didn't know, Zen Coding is a tool for creating html with a same kind of syntax, available for many editors: http://code.google.com/p/zen-coding/
There are probably several other use-cases, but the one I've run into was where there is a naive implementation of alphabetic sorting (basically character by character sorting), zero padding allows proper numerical sorting to work:
001
002
010
022
Instead of:
1
10
2
22
If you think you might have a thousand items, you'd probably zero pad by 3 digits.
0001
0010
0100
1000
1001
Edit: of course, one area you're guaranteed to have trouble with numerical sorting is when your number is prefixed by a letter. Zero-padding mitigates that problem: M001, M002, M020, M023.
Instead of prefixing protected attributes with underscore (_class) i would instead just wrap those in quotes (valid js, no extra logic), e.g. 'class': 'foo'.
Interestingly I used JavaScript(Jquery) to generate a majority of the html for a site I did in the past to keep it free from page refreshes. In retrospect I thought it was bad practice, but maybe it will come into style with libraries like this.
Instead of generating markup on the server side, generate it on the client side. Why?
1) The client side knows more about the client (screen width, device, scroll position)
2) Save yourself an AJAX call
3) Make your code more modular by templating jQuery and HTML at the same time. I plan on writing a whole blog post about this, but currently writing web apps seems to follow 1)Create DOM, 2) find relevant DOM with jQuery, 3) apply jQuery. This will combine steps 1 and 3 into the same template, and make 2 unnecessary.
OMG!!! Generating html with javascript is just soo stupid. It has the same problem as writing javascript in html ( I think html in js is even worse! ).
The way you separate out logic from presentation in html ( proponents of unobtrusive js?) you SHOULD separate out html from js. Or it starts becoming a mess. Please dont make writing html in js easy because stupid ppl will use it and start making our lives harder.
I like how you included the underscore prefix to make it easier to use keys like "class", but wouldn't it be nicer to encourage people to learn the reserved words and escape them properly?
34 comments
[ 5.3 ms ] story [ 78.2 ms ] threadI've never used it, any feedback on their syntax? I was planning on using a `space` instead of a `>` when I do inline hierarchy.
Also, what is zero padding? (`li.item$$$`)
edit: What is the purpose of zero padding?
Stick to ">". That's the standard CSS for indicating a child element.
e.g. "div.myclass > h1" indicates a div with class "myclass" and a child h1 element. In zen, it outputs:
http://www.w3.org/TR/CSS2/selector.html#pattern-matching001
002
010
022
Instead of:
1
10
2
22
If you think you might have a thousand items, you'd probably zero pad by 3 digits.
0001
0010
0100
1000
1001
Edit: of course, one area you're guaranteed to have trouble with numerical sorting is when your number is prefixed by a letter. Zero-padding mitigates that problem: M001, M002, M020, M023.
1) The client side knows more about the client (screen width, device, scroll position) 2) Save yourself an AJAX call 3) Make your code more modular by templating jQuery and HTML at the same time. I plan on writing a whole blog post about this, but currently writing web apps seems to follow 1)Create DOM, 2) find relevant DOM with jQuery, 3) apply jQuery. This will combine steps 1 and 3 into the same template, and make 2 unnecessary.
`.uiji('p.greeting.earthling"Hello World!"')
The way you separate out logic from presentation in html ( proponents of unobtrusive js?) you SHOULD separate out html from js. Or it starts becoming a mess. Please dont make writing html in js easy because stupid ppl will use it and start making our lives harder.