-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
200 lines (166 loc) · 7.11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html>
<head>
<title>haiku.js</title>
<meta http-equiv='Content-Type' content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="main.css" />
<style type="text/css">
textarea {
background: white;
border: 1px inset gray;
width: 320px; height: 60px;
}
input[type=text] { width: 320px; }
</style>
</head>
<body>
<h1>haiku.js</h1>
<blockquote>
<p>Haiku makes DOM trees
so simple to generate,
I think you'll like it.</p>
</blockquote>
<p>Haiku is a lightweight replacement for the standard DOM method of creating new HTML structures,
when you don't want or need the overhead of a full-blown templating system like
<a href="http://handlebarsjs.com/">Handlebars</a>. Its syntax (and inspiration for its name)
comes from the popular <a href="http://code.google.com/p/zen-coding/">Zen Coding</a>
abbreviation engine, which, in turn, is inspired by the
<a href="http://www.w3.org/TR/CSS2/selector.html">CSS selectors</a> specification.</p>
<p>Know CSS? Then you're about 2 minutes away from knowing Haiku. ;)</p>
<hr/>
<h2>Usage</h2>
<div class="example">Two output options:
<ol>
<li>DOM Fragment (default)</li>
<li>Serialized/string (specify <code>TRUE</code> for the optional second argument to atto.Tao())</li>
</ol>
</div>
<div class="example">“#” operator – specifies the ID for an element <em>(ignores multiple operands; an element can only have one ID)</em>:
<p>
<code>div#main</code>
<span>⇒</span>
<code><div id="main"></div></code>
</p>
<!--
<input type="text" id="src1" value="div#content>h1+p"/>
<button onclick="convert(1);">Parse</button><br/>
<textarea id="tgt1"></textarea>
-->
</div>
<hr/>
<div class="example">“.” operator – specifies the class for an element <em>(multiple operands allowed)</em>:
<p>
<code>blockquote.fancy.gothic</code>
<span>⇒</span>
<code><blockquote class="fancy gothic"></blockquote></code>
</p>
</div>
<hr/>
<div class="example">“>” operator – makes the following element a child of the preceding one:
<p>
<code>ul>li</code>
<span>⇒</span>
<code><ul><br/>
<li></li><br/>
</ul></code>
</p>
</div>
<hr/>
<div class="example">“+” operator – makes the following element a sibling of the preceding one:
<p>
<code>div>p#intro+p#main</code>
<span>⇒</span>
<code><div><br/>
<p id="intro"></p><br/>
<p id="main"></p><br/>
</div></code></p>
</div>
<hr/>
<div class="example">“<” operator – makes the following element a sibling of the preceding one's parent (i.e goes up one level in the tree):
<p>
<code>header>h1<section.main</code>
<span>⇒</span>
<code><header><br/>
<h1></h1><br/>
</header><br/>
<section class="main"></section></code>
</p>
</div>
<hr/>
<div class="example">“{ }” operators – specifies the contents of a text node:
<p>
<code>p>{A }+em{simple}+{ example}</code>
<span>⇒</span>
<code><p><br/>
"A "<br/>
<em>simple</em><br/>
" example"<br/>
</p></code>
</p>
</div>
<hr/>
<div class="example">“[ ]” operators – specifies attributes other than class and id (comma-separated if more than one):
<p>
<code>a#myId.myClass[href=http://foo.com,data-type=permalink]</code>
<span>⇒</span>
<code><a <br/>
href="foo.com"<br/>
data-type="permalink"<br/>
id="myId"<br/>
class="myClass"<br/>
/></code>
</p>
</div>
<hr/>
<h2>Installation</h2>
<p>Haiku is packaged as an AMD module, but it's dependency-free, so it's simple to
install: just drop it in your root JavaScript folder, and <code>require</code> away:</p>
<pre class="example"><code>require(["haiku"], function(haiku) {
document.body.appendChild( haiku.expand("section#main+aside#related") );
});
</code></pre>
<p>So far, this is more or less a subset of Zen Coding's power — I haven't yet added support for
abbreviation groups (<code>body>(header>h1)+(div#main)+(footer>span)</code>),
element multiplication (<code>li*5>a</code>), or item numbering (<code>li#item$*3</code>).
I expect if this project proves useful, I'll probably add those features,
as well as simple Supplant-style templating.</p>
<!--
<p>Thoughts on advanced features:</p>
<ul>
<li>Simple index insertion on loops with $ (as in Zen Coding):<br/>
<code>ul>li#item$*3</code></li>
<li>Element multiplication doesn't have to be in a paren group; it will affect anything downline:<br/>
<code>li*3>a ⇒ li>a<li>a<li>a</code></li>
<li>Complex template logic with element multipliers:<br/>
<code>(li#item\item.id/>a[href=\item.href/):for item in items;</code></li>
<li>:<br/>
<code></code></li>
<li>:<br/>
<code></code></li>
</ul>
-->
<h2>Try your own:</h2>
<input type="text" id="src2" value="div#page>div.logo+ul#navigation>li>a" />
<button onclick="convert(2);">Parse</button><br/>
<textarea id="tgt2"></textarea>
<!--
<h2>Example 3 (element multiplication / item numbering):</h2>
<input type="text" id="src3" value="ul>li#item-$*5>a"/>
<button onclick="convert(3);">Parse</button><br/>
<textarea id="tgt3"></textarea>
<h2>Example 4 (abbreviation groups):</h2>
<input type="text" id="src4" value="div#page>(div#header>ul#nav>li*4>a)+(div#page>(h1>span)+p*2)+div#footer"/>
<button onclick="convert(4);">Parse</button><br/>
<textarea id="tgt4"></textarea>
<h2>Example 5 (text):</h2>
<input type="text" id="src5" value="p>{Click }+a{here}+{ to continue}"/>
<button onclick="convert(5);">Parse</button><br/>
<textarea id="tgt5"></textarea>
-->
<hr/>
<footer>Haiku is released under the <a href="http://www.opensource.org/licenses/MIT">MIT license</a>.<br/>
If you use it in something interesting,
<a href="https://twitter.com/intent/tweet/?text=Hey%20@buyog..." title="Tweet at me, bro!">I'd love to hear about it</a>.
</footer>
</body>
</html>