-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.haml
160 lines (133 loc) · 5.67 KB
/
index.haml
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
flkhlfgl gyf
!!! Strict
%html
%head
%script{:src=>"/jquery.js", :type=>"text/javascript"}
%script{:src=>"/json.js", :type=>"text/javascript"}
%script{:src=>"/baconl.js", :type=>"text/javascript"}
%script{:src=>"/qunit.js", :type=>"text/javascript"}
:javascript
jQuery.baconl = function( template ) {
return jQuery( baconl( template ) );
}
<link rel="stylesheet" type="text/css" href="/qunit.css">
%style
:plain
%body
%h1 Baconl tests
%h2#userAgent
%ol#tests
#main
:javascript
test("Binding to jQuery", function() {
ok( jQuery.baconl , "jQuery binding exists.");
});
module("Selector Parser");
test("Simple selector", function() {
var node = baconl.parse( "%h2#element.class-1.class-2" );
equals( "h2", node.tag );
equals( "element", node.id );
equals( ["class-1","class-2"].join(" "), node.classes.join(" ") );
});
test("Attributes" , function() {
equals( baconl.parse('%a{"href":"/index.html"}').attributes.href, "/index.html" , "Extracting single attribute");
equals( baconl.parse('%a{"href":"/ind\\"ex.html"}').attributes.href ,"/ind\"ex.html" , "Attribute value with escaped characters");
equals( baconl.parse('%a{"href":"/index}.html"}').attributes.href , "/index}.html" , "Attribute value with escaped bracket");
} );
test("Selector with default values" , function(){
var node = baconl.parse( ".class-1.class-2" );
equals( "div", node.tag );
equals( undefined , node.id );
equals( ["class-1","class-2"].join(" "), node.classes.join(" ") );
});
test("Selector with body" , function(){
var node = baconl.parse( ".classes body");
equals( "div" , node.tag );
equals( "classes" , node.classes.join(" ") );
equals( "body" , node.innerHTML );
});
test("Tagless strings" , function(){
var node = baconl.parse("simple string");
equals( undefined , node.tag );
equals( "" , node.classes.join(" ") );
equals( "simple string" , node.innerHTML );
});
test( "Construct node" , function() {
equals( "<div></div>" , baconl.node( "%div" ).html() )
equals( "<div></div>" , baconl.node(baconl.node( "%div" )).html() )
equals( "<div>body</div>" , baconl.node( "%div body" ).html() )
equals( "<div class='home'>body</div>" , baconl.node( "%div.home body" ).html());
});
module("HTML generator");
test("Simple selector", function() {
var node = baconl( "%h2#element.class-1.class-2" );
equals( "<h2 id='element' class='class-1 class-2'></h2>", node );
});
test("Selector with default values" , function(){
var node = baconl( ".class-1.class-2" );
equals( "<div class='class-1 class-2'></div>", node );
});
test("Selector with body" , function() {
var node = baconl( ".class-1.class-2 hello" );
equals( "<div class='class-1 class-2'>hello</div>", node );
});
test("Text node" , function(){
var node = baconl("simple string");
equals( "simple string" , node );
});
test("HAML" , function(){
equals("<h1>The cat in the hat</h1>" , baconl('%h1 The cat in the hat') );
equals("<h1>The cat in the hat</h1>\n<h2>by <span>Dr. Seuss</span></h2>" ,
baconl('%h1 The cat in the hat\n%h2 by \n %span Dr. Seuss') );
}) ;
module("Node Manipulation" );
test("Prepend Node" , function(){
var node = baconl.node( "%div" )
.prepend( baconl.node("%h1 Welcome!") )
.html();
equals( "<div><h1>Welcome!</h1></div>" , node );
var doc = baconl.node( "%div" )
.prepend( baconl.node("%h1 Second") )
.prepend( baconl.node("%h2 first") )
.html();
equals( "<div><h2>first</h2>\n<h1>Second</h1></div>" , doc );
});
test("Appending node" , function(){
var node = baconl.node( "%div" ).append( "%h1 Welcome!" ).html();
equals( "<div><h1>Welcome!</h1></div>" , node );
});
test("Setting html" , function(){
var list = baconl.node("%ul");
list.html(
baconl.node("%li 1"),
baconl.node("%li 2"),
baconl.node("%li 3")
);
equals("<ul><li>1</li>\n<li>2</li>\n<li>3</li></ul>" , list.html() );
});
test("Manipulate classes" , function(){
var node = baconl.node("%div.cute");
node.addClass("left right").removeClass("right center");
equals("<div class='cute left'></div>" , node.html() );
});
test("Remove node" , function(){
var item = baconl.node("%li 1");
var list = baconl.node("%ul");
list.html(
item,
baconl.node("%li 2"),
baconl.node("%li 3")
);
item.remove();
equals( "<ul><li>2</li>\n<li>3</li></ul>" , list.html() )
});
test("Empty node" , function(){
var list = baconl.node("%ul");
list.html(
baconl.node("%li 1"),
baconl.node("%li 2")
);
equals( "<ul><li>1</li>\n<li>2</li></ul>" , list.html() );
list.empty();
equals( "<ul></ul>" , list.html() );
});