jabs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.gitmodules +3 -0
- data/README +20 -0
- data/Rakefile.rb +66 -0
- data/VERSION +1 -0
- data/build +29 -0
- data/examples/editor.html +22 -0
- data/examples/editor.js +58 -0
- data/examples/input_with_default.html +13 -0
- data/examples/input_with_default.js +19 -0
- data/examples/src/editor.html.haml +19 -0
- data/examples/src/editor.js.jabs +50 -0
- data/examples/src/input_with_default.html.haml +10 -0
- data/examples/src/input_with_default.js.jabs +10 -0
- data/lib/jabs.rb +308 -0
- data/lightning.jabs +33 -0
- data/rspec/fixtures/example.js +36 -0
- data/rspec/fixtures/example.js.jabs +24 -0
- data/rspec/fixtures/mephisto.js +56 -0
- data/rspec/fixtures/mephisto.js.jabl +25 -0
- data/rspec/jabs/jabs_engine_spec.rb +472 -0
- data/rspec/jabs/jabs_precompiler_spec.rb +37 -0
- data/rspec/jabs_spec.rb +15 -0
- data/rspec/jabs_spec_helper.rb +5 -0
- data/vendor/jquery/jquery-1.2.6.pack.js.gz +11 -0
- data/vendor/jquery/jquery-1.3.1.js +4241 -0
- data/vendor/jquery/jquery.simulate.js +152 -0
- metadata +110 -0
data/lightning.jabs
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
get 'http://github.com/githubapi'+window.location.href.match(/~(.*)/)[1]
|
2
|
+
user.repositories.each fun repository
|
3
|
+
$#repositories
|
4
|
+
.append render(:repository, repository)
|
5
|
+
|
6
|
+
def show_messages
|
7
|
+
&.winner
|
8
|
+
.removeClass :winner
|
9
|
+
$.repository:not(.faded)
|
10
|
+
if .siblings.get(0)
|
11
|
+
.addClass :winner
|
12
|
+
$#winners_circle
|
13
|
+
.show
|
14
|
+
.replaceWith render(:winners_circle, ../@repository)
|
15
|
+
else
|
16
|
+
$#winners_circle
|
17
|
+
.hide
|
18
|
+
$.repo
|
19
|
+
&a:click
|
20
|
+
event.stopPropagation()
|
21
|
+
:click
|
22
|
+
.toggleClass :faded
|
23
|
+
.show_messages
|
24
|
+
|
25
|
+
$[href=#show]
|
26
|
+
$.repository
|
27
|
+
.removeClass :faded
|
28
|
+
.show_messages
|
29
|
+
|
30
|
+
$[href=#hide]
|
31
|
+
$.repository
|
32
|
+
.addClass :faded
|
33
|
+
.show_messages
|
@@ -0,0 +1,36 @@
|
|
1
|
+
var check_feed = function() {
|
2
|
+
$('#feed').load("/live/last_item");
|
3
|
+
setTimeout(check_feed, 60000);
|
4
|
+
}
|
5
|
+
|
6
|
+
$(function() {
|
7
|
+
$('input[@default_value]').each(function() {
|
8
|
+
// clear default value when user clicks
|
9
|
+
$(this)
|
10
|
+
.focus(function () {
|
11
|
+
if (this.value == this.getAttribute('default_value')) {
|
12
|
+
$(this)
|
13
|
+
.removeClass("grey")
|
14
|
+
.attr({'value': ''});
|
15
|
+
}
|
16
|
+
})
|
17
|
+
.blur(function() {
|
18
|
+
if(this.value == '') {
|
19
|
+
$(this)
|
20
|
+
.addClass("grey")
|
21
|
+
.attr({'value': this.getAttribute('default_value')})
|
22
|
+
}
|
23
|
+
})
|
24
|
+
.blur()
|
25
|
+
});
|
26
|
+
|
27
|
+
// blank out all elements
|
28
|
+
// submitted without the user modifying the element
|
29
|
+
$('form').submit(function() { $('input[@default_value]').focus(); });
|
30
|
+
|
31
|
+
$('#comments').autolineheight({minWidth:100,ratio:.03});
|
32
|
+
|
33
|
+
// No live feed for the moment
|
34
|
+
// check_feed();
|
35
|
+
});
|
36
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
fun checkFeed
|
2
|
+
$#feed
|
3
|
+
load("/live/last_item")
|
4
|
+
// Setup the timeout
|
5
|
+
setTimeout(checkFeed, 60000)
|
6
|
+
|
7
|
+
:ready
|
8
|
+
checkFeed()
|
9
|
+
|
10
|
+
$input[@default_value]
|
11
|
+
:focus
|
12
|
+
if @value == @default_value
|
13
|
+
this.removeClass("grey")
|
14
|
+
@value = "something"
|
15
|
+
:blur
|
16
|
+
if @value == ''
|
17
|
+
this.addClass("grey")
|
18
|
+
@value = @default_value
|
19
|
+
blur()
|
20
|
+
|
21
|
+
$form
|
22
|
+
:submit
|
23
|
+
$input[@default_value]
|
24
|
+
focus()
|
@@ -0,0 +1,56 @@
|
|
1
|
+
ToolBox = Class.create();
|
2
|
+
ToolBox.current = null;
|
3
|
+
ToolBox.prototype = {
|
4
|
+
initialize: function(element) {
|
5
|
+
this.toolbox = $(element);
|
6
|
+
if(!this.toolbox) return;
|
7
|
+
this.timeout = null;
|
8
|
+
this.tools = this.findTools();
|
9
|
+
|
10
|
+
Event.observe(this.toolbox, 'mouseover', this.onHover.bindAsEventListener(this), true);
|
11
|
+
Event.observe(this.toolbox, 'mouseout', this.onBlur.bindAsEventListener(this), true);
|
12
|
+
Event.observe(this.tools, 'mouseover', this.onHover.bindAsEventListener(this));
|
13
|
+
Event.observe(this.tools, 'mouseout', this.onBlur.bindAsEventListener(this));
|
14
|
+
},
|
15
|
+
|
16
|
+
show: function() {
|
17
|
+
if(this.timeout) {
|
18
|
+
clearTimeout(this.timeout);
|
19
|
+
this.timeout = null;
|
20
|
+
}
|
21
|
+
|
22
|
+
if(ToolBox.current) {
|
23
|
+
ToolBox.current.hideTools();
|
24
|
+
}
|
25
|
+
|
26
|
+
if(this.tools) {
|
27
|
+
Element.show(this.tools);
|
28
|
+
ToolBox.current = this;
|
29
|
+
}
|
30
|
+
},
|
31
|
+
|
32
|
+
onHover: function(event) {
|
33
|
+
this.show();
|
34
|
+
},
|
35
|
+
|
36
|
+
onBlur: function(event) {
|
37
|
+
this.considerHidingTools();
|
38
|
+
},
|
39
|
+
|
40
|
+
considerHidingTools: function() {
|
41
|
+
if(this.timeout) { clearTimeout(this.timeout); }
|
42
|
+
this.timeout = setTimeout(this.hideTools.bind(this), 500);
|
43
|
+
},
|
44
|
+
|
45
|
+
hideTools: function() {
|
46
|
+
clearTimeout(this.timeout);
|
47
|
+
this.timeout = null;
|
48
|
+
Element.hide(this.tools);
|
49
|
+
},
|
50
|
+
|
51
|
+
findTools: function() {
|
52
|
+
var tools = document.getElementsByClassName('tools', this.toolbox)[0];
|
53
|
+
if(!tools) { throw "You called new ToolBox() on an element which has no class=\"tools\" child element"; }
|
54
|
+
return tools;
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
:ready
|
4
|
+
$#toolbox
|
5
|
+
|
6
|
+
fun stopHideTimer
|
7
|
+
if @timeout
|
8
|
+
clearTimeout(@timeout)
|
9
|
+
@timeout = null
|
10
|
+
|
11
|
+
fun startHideTimer
|
12
|
+
stophideTimer()
|
13
|
+
@timeout = setTimeout(disappear, 500)
|
14
|
+
|
15
|
+
fun disappear
|
16
|
+
stopHideTimer()
|
17
|
+
&.tools
|
18
|
+
hide()
|
19
|
+
|
20
|
+
:blur startHideTimer
|
21
|
+
&.tools
|
22
|
+
:hover
|
23
|
+
dissappear()
|
24
|
+
this.show()
|
25
|
+
:blur startHideTimer
|
@@ -0,0 +1,472 @@
|
|
1
|
+
require 'rspec/jabs_spec_helper'
|
2
|
+
require 'colored'
|
3
|
+
# $LOAD_PATH << "~/code/johnson/js" unless $LOAD_PATH.include?("~/code/johnson/js")
|
4
|
+
|
5
|
+
describe Jabs::Engine do
|
6
|
+
def assert_jabs src, target
|
7
|
+
jabsed = Jabs::Engine.new(src).render
|
8
|
+
src = Johnson::Parser.parse(jabsed).to_ecma
|
9
|
+
target = Johnson::Parser.parse(target).to_ecma
|
10
|
+
src.should include(target)
|
11
|
+
rescue Exception => e
|
12
|
+
puts "\n"*2
|
13
|
+
puts description
|
14
|
+
puts Jabs::Engine.new(src).render
|
15
|
+
puts src
|
16
|
+
puts target
|
17
|
+
raise e
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "line" do
|
21
|
+
it "passes through" do
|
22
|
+
assert_jabs "use.real[\"javascript\"] == true;", "use.real[\"javascript\"] == true;"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "renders multiple lines" do
|
26
|
+
assert_jabs "one;\ntwo;", "one;\ntwo;"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "doesn't throw up when given nested lines" do
|
30
|
+
assert_jabs %{var coolio = { val: \"to the store\"};}, %{
|
31
|
+
var coolio = {
|
32
|
+
val: "to the store"
|
33
|
+
};
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "understands function literals across lines" do
|
38
|
+
assert_jabs %{
|
39
|
+
function() {
|
40
|
+
doCall.apply(null);
|
41
|
+
}
|
42
|
+
}, %{function() {doCall.apply(null);}}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "functions" do
|
47
|
+
it "compiles funs with arbirtrary javascript" do
|
48
|
+
assert_jabs %{
|
49
|
+
fun one
|
50
|
+
var a = b
|
51
|
+
fun two
|
52
|
+
}, %{
|
53
|
+
function one() {
|
54
|
+
var a = b;
|
55
|
+
function two() {}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
end
|
60
|
+
it "compiles funs into functions" do
|
61
|
+
assert_jabs "fun do_something", "function do_something() {}"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "compiles with argument lists" do
|
65
|
+
assert_jabs "fun do_something has, arguments", "function do_something(has, arguments) {}"
|
66
|
+
end
|
67
|
+
|
68
|
+
it "compiles on multiple lines" do
|
69
|
+
assert_jabs "fun one\nfun two", "function one() {}; function two() {};"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
it "compiles nesting funs" do
|
74
|
+
assert_jabs %{
|
75
|
+
fun outer
|
76
|
+
fun inner
|
77
|
+
fun inner_two
|
78
|
+
},%{
|
79
|
+
function outer() {
|
80
|
+
function inner() {
|
81
|
+
}
|
82
|
+
function inner_two() {
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
it "compiles REAL javascript" do
|
89
|
+
assert_jabs %{
|
90
|
+
fun real
|
91
|
+
whatever.you['want'] = "Goes here"
|
92
|
+
!stop == true
|
93
|
+
},%{
|
94
|
+
function real() {
|
95
|
+
whatever.you['want'] = "Goes here";
|
96
|
+
!stop == true;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
it "compiles empty functions across lines" do
|
102
|
+
assert_jabs %{function(){\r\n}}, %{function(){}}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "def" do
|
107
|
+
it "adds functions to JQuery.fn" do
|
108
|
+
assert_jabs "def whatever", "jQuery.fn.whatever = function() {var $this = this;}"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "adds functions with arguments to jQuery.fn" do
|
112
|
+
assert_jabs "def whatever you, want", "jQuery.fn.whatever = function(you, want) {var $this = this;}"
|
113
|
+
end
|
114
|
+
|
115
|
+
it "compiles jabs normally within def" do
|
116
|
+
assert_jabs %{
|
117
|
+
def sets_default_value
|
118
|
+
&[default_value]
|
119
|
+
}, %{
|
120
|
+
jQuery.fn.sets_default_value = function() {
|
121
|
+
var $this = this;
|
122
|
+
(function($this) {})($this.find('[default_value]'))
|
123
|
+
}
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "selectors" do
|
129
|
+
before(:each) do
|
130
|
+
@css = "#very .complex, style.selector[value=\"pants\"]"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "makes a query" do
|
134
|
+
assert_jabs "$#{@css}", "(function($this) {})(jQuery('#{@css}'));"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "renders iterator" do
|
138
|
+
assert_jabs "$#{@css}\n this.rules();", "(function($this) {this.rules();})(jQuery('#{@css}'));"
|
139
|
+
end
|
140
|
+
|
141
|
+
# it "wraps with document.ready if not already wrapped" do
|
142
|
+
# assert_jabs "$#{@css}", "jQuery(document).bind(\"ready\", function() {jQuery(\"#{@css}\").each(function() {});});"
|
143
|
+
# end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "events" do
|
147
|
+
it "has a special :ready event" do
|
148
|
+
assert_jabs(":ready", "jQuery(function() {\n (function($this) { })(jQuery(window));\n});")
|
149
|
+
end
|
150
|
+
|
151
|
+
it "has it's own $this" do
|
152
|
+
assert_jabs ":click", "var $this = jQuery(this);"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "binds events to 'this' and preserves namespace" do
|
156
|
+
assert_jabs ":click.awesomely", "$this.live(\"click.awesomely\", function(e){var $this = jQuery(this);});"
|
157
|
+
end
|
158
|
+
|
159
|
+
it "renders callback" do
|
160
|
+
assert_jabs ":click.awesomely\n a()\n b()", "$this.live(\"click.awesomely\", function(e){var $this = jQuery(this);a();b();});"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "compiles nested with anything with arbitraty javascript inbetween" do
|
164
|
+
assert_jabs %{
|
165
|
+
fun test
|
166
|
+
var cat = yum
|
167
|
+
:click
|
168
|
+
},%{
|
169
|
+
function test() {
|
170
|
+
var cat = yum;
|
171
|
+
$this.live( 'click', function(e) {var $this = jQuery(this);});
|
172
|
+
}
|
173
|
+
}
|
174
|
+
end
|
175
|
+
|
176
|
+
it "compiles nested in selector with arbirtary javascript in between" do
|
177
|
+
assert_jabs %{
|
178
|
+
$document
|
179
|
+
cars++
|
180
|
+
:click
|
181
|
+
var cool = "beans"
|
182
|
+
},%{
|
183
|
+
(function($this) {
|
184
|
+
cars++;
|
185
|
+
$this.live('click', function(e) {
|
186
|
+
var $this = jQuery(this);
|
187
|
+
var cool = "beans"
|
188
|
+
});
|
189
|
+
})(jQuery("document"));
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
it "compiles among arbirtary javascript" do
|
194
|
+
assert_jabs %{
|
195
|
+
var cat = poo
|
196
|
+
:click
|
197
|
+
slot++
|
198
|
+
}, %{
|
199
|
+
var cat = poo;
|
200
|
+
$this.live('click', function(e) {
|
201
|
+
var $this = jQuery(this);
|
202
|
+
slot++;
|
203
|
+
});
|
204
|
+
}
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "sub selections" do
|
209
|
+
before(:each) {@css= "#some.convoluted:selector"}
|
210
|
+
it "queries against this" do
|
211
|
+
assert_jabs "&#{@css}", "(function($this) {})($this.find(\"#{@css}\"));"
|
212
|
+
end
|
213
|
+
|
214
|
+
it "renders iterator" do
|
215
|
+
assert_jabs "&#{@css}\n a()\n b()", "(function($this) {a();b();})($this.find(\"#{@css}\"));"
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "conditionals" do
|
220
|
+
it "compiles if statements" do
|
221
|
+
assert_jabs "if 3 == 4", "if(3 == 4) {}"
|
222
|
+
end
|
223
|
+
|
224
|
+
it "compiles unless statements" do
|
225
|
+
assert_jabs "unless 3 == 4", "if(!(3 == 4)) {}"
|
226
|
+
end
|
227
|
+
|
228
|
+
it "compiles nesting conditionals" do
|
229
|
+
assert_jabs %{
|
230
|
+
if 3 === 4
|
231
|
+
unless 4 === 3
|
232
|
+
if 3 === 3
|
233
|
+
}, %{
|
234
|
+
if(3 === 4) {
|
235
|
+
if(!(4 === 3)) {
|
236
|
+
if(3 === 3) {
|
237
|
+
}
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
it "compiles nesting conditionals with arbitrary code" do
|
244
|
+
assert_jabs %{
|
245
|
+
var a = cat
|
246
|
+
if 3 === 4
|
247
|
+
var elk = "3"
|
248
|
+
unless 4 === 3
|
249
|
+
wear.your.pants()
|
250
|
+
if 3 === 3
|
251
|
+
}, %{
|
252
|
+
var a = cat;
|
253
|
+
if(3 === 4) {
|
254
|
+
var elk = "3";
|
255
|
+
if(!(4 === 3)) {
|
256
|
+
wear.your.pants();
|
257
|
+
if(3 === 3) {
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}
|
261
|
+
}
|
262
|
+
end
|
263
|
+
|
264
|
+
it "compiles else branches" do
|
265
|
+
assert_jabs %{
|
266
|
+
if 3 == 4
|
267
|
+
onething
|
268
|
+
else
|
269
|
+
something
|
270
|
+
}, %{
|
271
|
+
if(3 == 4) {onething;}
|
272
|
+
else {something;}
|
273
|
+
}
|
274
|
+
end
|
275
|
+
|
276
|
+
it "compiles else if branches" do
|
277
|
+
assert_jabs %{
|
278
|
+
if 1 == 2
|
279
|
+
yay
|
280
|
+
else if 3 == 4
|
281
|
+
poo
|
282
|
+
else
|
283
|
+
wtf
|
284
|
+
}, "if(1 == 2) {yay;} else if(3 == 4) {poo;} else {wtf;}"
|
285
|
+
end
|
286
|
+
|
287
|
+
it "compiles else unless branches" do
|
288
|
+
assert_jabs %{
|
289
|
+
if true
|
290
|
+
yay
|
291
|
+
else unless 3 == 4
|
292
|
+
yay
|
293
|
+
}, "if(true) { yay } else if(!(3 == 4)) { yay }"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "../.. access" do
|
298
|
+
it "access prevObject" do
|
299
|
+
assert_jabs "..", "$this.prevObject"
|
300
|
+
end
|
301
|
+
|
302
|
+
it "accesses multiple previous objects" do
|
303
|
+
assert_jabs "../..", "$this.prevObject.prevObject"
|
304
|
+
end
|
305
|
+
|
306
|
+
it "provides access to attributes of previous objects" do
|
307
|
+
assert_jabs "..@value", "$this.prevObject.attr('value')"
|
308
|
+
end
|
309
|
+
|
310
|
+
it "sets attributes of previous objects" do
|
311
|
+
assert_jabs "../..@value = 'neat'", %{$this.prevObject.prevObject.attr('value', 'neat')}
|
312
|
+
end
|
313
|
+
|
314
|
+
it "works inline with current object access and attribute setting" do
|
315
|
+
assert_jabs "..@value = @value", "$this.prevObject.attr('value', $this.attr('value'))"
|
316
|
+
end
|
317
|
+
|
318
|
+
it "works inline with current object access and attribute setting reveres" do
|
319
|
+
assert_jabs "@value = ..@value", "$this.attr('value', $this.prevObject.attr('value'))"
|
320
|
+
end
|
321
|
+
|
322
|
+
it "allows method calls" do
|
323
|
+
assert_jabs "...hide()", "$this.prevObject.hide()"
|
324
|
+
end
|
325
|
+
|
326
|
+
it "doesn't preclude auto-calling methods" do
|
327
|
+
assert_jabs "...hide :slow", "$this.prevObject.hide('slow')"
|
328
|
+
end
|
329
|
+
|
330
|
+
it "works within conditionals" do
|
331
|
+
assert_jabs "if ...is('.awesome')", "if($this.prevObject.is('.awesome')) {}"
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe "argument compilation" do
|
336
|
+
it "compiles symbols to strings" do
|
337
|
+
assert_jabs ".addClass :class_name", %{$this.addClass("class_name")}
|
338
|
+
end
|
339
|
+
|
340
|
+
it "doesn't render multiple commas" do
|
341
|
+
assert_jabs ".methodCall 1, 2", %{$this.methodCall(1, 2)}
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe "nested function calls" do
|
346
|
+
it "assumes previous line returns jquery object" do
|
347
|
+
assert_jabs %{
|
348
|
+
.methodA :val
|
349
|
+
.methodB :name
|
350
|
+
},
|
351
|
+
%{
|
352
|
+
(function($this){
|
353
|
+
$this.methodB('name')
|
354
|
+
})($this.methodA('val'))
|
355
|
+
}
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
describe "ajax" do
|
360
|
+
describe "get" do
|
361
|
+
it "makes a basic ajax call" # do
|
362
|
+
# assert_jabs "get", "jQuery.ajax()"
|
363
|
+
# end
|
364
|
+
|
365
|
+
|
366
|
+
it "uses a url passed to it" # do
|
367
|
+
# assert_jabs 'get "http://google.com"', '
|
368
|
+
# jQuery.ajax({
|
369
|
+
# url: "http://google.com"
|
370
|
+
# })
|
371
|
+
# '
|
372
|
+
# end
|
373
|
+
end
|
374
|
+
|
375
|
+
describe "post" do
|
376
|
+
it "makes post requests"
|
377
|
+
end
|
378
|
+
|
379
|
+
describe "put" do
|
380
|
+
it "makes put requests"
|
381
|
+
end
|
382
|
+
|
383
|
+
describe "delete" do
|
384
|
+
it "makes delete requests"
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "dot.access" do
|
389
|
+
it "cheats to $this.whatever" do
|
390
|
+
assert_jabs ".width()", "$this.width()"
|
391
|
+
end
|
392
|
+
|
393
|
+
it "allows method chaining" do
|
394
|
+
assert_jabs ".siblings.get(0)", "$this.siblings().get(0)"
|
395
|
+
end
|
396
|
+
|
397
|
+
it "does not require parenthesis" do
|
398
|
+
assert_jabs ".width", "$this.width()"
|
399
|
+
end
|
400
|
+
|
401
|
+
it "renders children appropriately" do
|
402
|
+
assert_jabs %{
|
403
|
+
.css({
|
404
|
+
a: 1
|
405
|
+
,b: 2
|
406
|
+
})
|
407
|
+
}, "$this.css({a:1, b:2})"
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
describe "@ttribute access" do
|
412
|
+
it "gets attributes from DOM" do
|
413
|
+
assert_jabs "@value", "$this.attr('value')"
|
414
|
+
end
|
415
|
+
|
416
|
+
it "happens anywhere on the line" do
|
417
|
+
assert_jabs "@value && @other", "$this.attr('value') && $this.attr('other')"
|
418
|
+
end
|
419
|
+
|
420
|
+
it "allows for comparison" do
|
421
|
+
assert_jabs "@value == @other", "$this.attr('value') == $this.attr('other')"
|
422
|
+
end
|
423
|
+
|
424
|
+
it "allows for strict comparison" do
|
425
|
+
assert_jabs "@value === @other", "$this.attr('value') === $this.attr('other')"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
describe "@attribute setting" do
|
430
|
+
it "sets attributes" do
|
431
|
+
assert_jabs "@value = 4", "$this.attr('value', 4)"
|
432
|
+
end
|
433
|
+
|
434
|
+
it "sets attributes to other attributes" do
|
435
|
+
assert_jabs "@value = @other", "$this.attr('value', $this.attr('other'))"
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
# it "compiles jabs to js" do
|
440
|
+
# assert_jabs %{
|
441
|
+
# :ready
|
442
|
+
# $input[default_value]
|
443
|
+
# var _default = this.attr('default_value')
|
444
|
+
# :blur
|
445
|
+
# if this.val() === ''
|
446
|
+
# this.val(_default)
|
447
|
+
#
|
448
|
+
# :focus
|
449
|
+
# if this.val() === _default
|
450
|
+
# this.val('')
|
451
|
+
#
|
452
|
+
# this.blur()
|
453
|
+
# },%{
|
454
|
+
# jQuery(function() {
|
455
|
+
# (function() {
|
456
|
+
# var _default = this.attr('default_value');
|
457
|
+
# this.live("blur", function() {
|
458
|
+
# if(this.val() === '') {
|
459
|
+
# this.val(_default);
|
460
|
+
# }
|
461
|
+
# });
|
462
|
+
# this.live("focus", function() {
|
463
|
+
# if(this.val() === _default) {
|
464
|
+
# this.val('');
|
465
|
+
# }
|
466
|
+
# });
|
467
|
+
# this.blur();
|
468
|
+
# })(jQuery("input[default_value]"));
|
469
|
+
# });
|
470
|
+
# }
|
471
|
+
# end
|
472
|
+
end
|