opal-jquery 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -2,10 +2,5 @@ source :rubygems
2
2
 
3
3
  gem 'rake'
4
4
 
5
- gem 'opal', :git => 'git://github.com/opal/opal.git'
6
- gem 'opal-spec', :git => 'git://github.com/opal/opal-spec.git'
7
-
8
- group :docs do
9
- gem 'redcarpet'
10
- gem 'albino'
11
- end
5
+ gem 'opal'
6
+ gem 'opal-spec'
data/Rakefile CHANGED
@@ -6,52 +6,4 @@ Opal::RakeTask.new do |t|
6
6
  t.dependencies = ['opal-spec']
7
7
  end
8
8
 
9
- task :default => :'opal:test'
10
-
11
- namespace :docs do
12
- desc "Build docs"
13
- task :build do
14
- require 'redcarpet'
15
- require 'albino'
16
-
17
- klass = Class.new(Redcarpet::Render::HTML) do
18
- def block_code(code, language)
19
- Albino.new(code, language || :text).colorize
20
- end
21
- end
22
-
23
- markdown = Redcarpet::Markdown.new(klass, :fenced_code_blocks => true)
24
-
25
- File.open('gh-pages/index.html', 'w+') do |o|
26
- puts " * index.html"
27
- # remove first 2 lines (header/build status), as pre.html has a docs version
28
- src = File.read("README.md").sub(/^(?:[^\n]*\n){4}/, '')
29
-
30
- o.write File.read('docs/pre.html')
31
- o.write markdown.render(src)
32
- o.write File.read('docs/post.html')
33
- end
34
- end
35
-
36
- desc "Clone repo"
37
- task :clone do
38
- if File.exists? 'gh-pages'
39
- Dir.chdir('gh-pages') { sh 'git pull origin gh-pages' }
40
- else
41
- FileUtils.mkdir_p 'gh-pages'
42
- Dir.chdir('gh-pages') do
43
- sh 'git clone git@github.com:/opal/opal-jquery.git .'
44
- sh 'git checkout gh-pages'
45
- end
46
- end
47
- end
48
-
49
- desc "commit and push"
50
- task :push do
51
- Dir.chdir('gh-pages') do
52
- sh "git add ."
53
- sh "git commit -a -m \"Documentation update #{Time.new}\""
54
- sh "git push origin gh-pages"
55
- end
56
- end
57
- end
9
+ task :default => [:opal, :'opal:test']
@@ -44,4 +44,5 @@ module Document
44
44
  def self.title=(title)
45
45
  `document.title = title`
46
46
  end
47
- end
47
+ end
48
+
@@ -241,6 +241,30 @@ class Element < `jQuery`
241
241
  self
242
242
  end
243
243
 
244
+ # return an opal array mapped with block yielded for any element
245
+ #
246
+ # @example
247
+ #
248
+ # list = Document.find('table.players td.surname').map {|el| el.html }
249
+ #
250
+ # @return an Array
251
+ def map
252
+ list = []
253
+ each {|el| list << yield(el) }
254
+ list
255
+ end
256
+
257
+ # return an opal Array of elements
258
+ #
259
+ # @example
260
+ #
261
+ # Document.find('table.players td.surname').to_a.last
262
+ #
263
+ # @return an Array
264
+ def to_a
265
+ map {|el| el }
266
+ end
267
+
244
268
  # Find all the elements that match the given `selector` within the
245
269
  # scope of elements in #{self} given collection. Might return an empty
246
270
  # collection if no elements match.
@@ -316,6 +340,8 @@ class Element < `jQuery`
316
340
 
317
341
  alias_native :next, :next
318
342
 
343
+ alias_native :siblings, :siblings
344
+
319
345
  def off(event_name, selector, handler=nil)
320
346
  %x{
321
347
  if (handler === nil) {
@@ -333,8 +359,13 @@ class Element < `jQuery`
333
359
  def on(event_name, selector=nil, &block)
334
360
  return unless block_given?
335
361
 
362
+ # The choice of allowing a maximum of four parameters is arbitrary. arg1 is typically the
363
+ # event object and the rest are parameters passed by trigger(). For example, Rails 3 AJAX
364
+ # event handlers get passed up to three additional parameters in addition to the event object.
336
365
  %x{
337
- var handler = function(e) { return #{ block.call `e` } };
366
+ var handler = function(arg1, arg2, arg3, arg4) {
367
+ return #{ block.call `arg1, arg2, arg3, arg4` }
368
+ };
338
369
  block._jq = handler;
339
370
 
340
371
  if (selector === nil) {
@@ -24,7 +24,7 @@ class Event < `$.Event`
24
24
  if (#{self}._opalTarget) {
25
25
  return #{self}._opalTarget;
26
26
  }
27
-
27
+
28
28
  return #{self}._opalTarget = $(#{self}.target);
29
29
  }
30
30
  end
@@ -36,4 +36,5 @@ class Event < `$.Event`
36
36
  def which
37
37
  `#{self}.which`
38
38
  end
39
- end
39
+ end
40
+
@@ -10,7 +10,7 @@ class HTTP
10
10
  attr_reader :method
11
11
  attr_reader :status_code
12
12
  attr_reader :url
13
-
13
+
14
14
  def self.get(url, opts={}, &block)
15
15
  self.new(url, :GET, opts, block).send!
16
16
  end
@@ -110,4 +110,5 @@ class HTTP
110
110
  def succeed
111
111
  @callback.call self if @callback
112
112
  end
113
- end
113
+ end
114
+
data/opal-jquery.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'opal-jquery'
5
- s.version = '0.0.1'
5
+ s.version = '0.0.2'
6
6
  s.author = 'Adam Beynon'
7
7
  s.email = 'adam.beynon@gmail.com'
8
8
  s.homepage = 'http://opalrb.org'
@@ -13,4 +13,4 @@ Gem::Specification.new do |s|
13
13
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  s.require_paths = ['lib']
16
- end
16
+ end
@@ -1,20 +1,14 @@
1
- describe Document do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="foo" class="bar"></div>
5
- <div class="woosh"></div>
6
- <div class="woosh"></div>
7
- <div class="find-foo"></div>
8
- <div class="find-bar"></div>
9
- <div class="find-foo"></div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
1
+ require "spec_helper"
14
2
 
15
- after do
16
- @div.remove
17
- end
3
+ describe Document do
4
+ html <<-HTML
5
+ <div id="foo" class="bar"></div>
6
+ <div class="woosh"></div>
7
+ <div class="woosh"></div>
8
+ <div class="find-foo"></div>
9
+ <div class="find-bar"></div>
10
+ <div class="find-foo"></div>
11
+ HTML
18
12
 
19
13
  describe ".[]" do
20
14
  it "should be able to find elements with given id" do
@@ -88,4 +82,4 @@ describe Document do
88
82
  Document.title = current
89
83
  end
90
84
  end
91
- end
85
+ end
@@ -1,20 +1,12 @@
1
- describe "Element#after" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="after-spec">
5
- <div id="some-header" class="kapow"></div>
6
- <div id="foo" class="after-spec-first"></div>
7
- <div id="bar" class="after-spec-first"></div>
8
- <div id="baz"></div>
9
- </div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
1
+ require "spec_helper"
14
2
 
15
- after do
16
- @div.remove
17
- end
3
+ describe "Element#after" do
4
+ html <<-HTML
5
+ <div id="some-header" class="kapow"></div>
6
+ <div id="foo" class="after-spec-first"></div>
7
+ <div id="bar" class="after-spec-first"></div>
8
+ <div id="baz"></div>
9
+ HTML
18
10
 
19
11
  it "should insert the given html string after each element" do
20
12
  el = Document['.after-spec-first']
@@ -30,4 +22,4 @@ describe "Element#after" do
30
22
  Document.id('baz').after Document.id('some-header')
31
23
  Document.id('baz').next.id.should == "some-header"
32
24
  end
33
- end
25
+ end
@@ -1,17 +1,9 @@
1
- describe "Element animation methods" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="animate-foo"></div>
5
- HTML
6
-
7
- @div.append_to_body
8
-
9
- Document.id("animate-foo").css("width", "0px")
10
- end
1
+ require "spec_helper"
11
2
 
12
- after do
13
- @div.remove
14
- end
3
+ describe "Element animation methods" do
4
+ html <<-HTML
5
+ <div id="animate-foo"></div>
6
+ HTML
15
7
 
16
8
  describe "#animate" do
17
9
  ### HACKY
@@ -1,20 +1,12 @@
1
- describe "Element#append" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="append-spec">
5
- <div id="foo" class="first-append"></div>
6
- <div id="bar" class="first-append"></div>
7
- <div id="baz"></div>
8
- <div id="buz"></div>
9
- </div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
1
+ require "spec_helper"
14
2
 
15
- after do
16
- @div.remove
17
- end
3
+ describe "Element#append" do
4
+ html <<-HTML
5
+ <div id="foo" class="first-append"></div>
6
+ <div id="bar" class="first-append"></div>
7
+ <div id="baz"></div>
8
+ <div id="buz"></div>
9
+ HTML
18
10
 
19
11
  it "should insert the HTML string to the end of each element" do
20
12
  Document.find('.first-append').append '<p class="woosh"></p>'
@@ -33,4 +25,4 @@ describe "Element#append" do
33
25
  baz.children.size.should == 1
34
26
  baz.children.id.should == "buz"
35
27
  end
36
- end
28
+ end
@@ -1,17 +1,11 @@
1
- describe "Element#append_to" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="foo"></div>
5
- <div id="bar"></div>
6
- <div id="baz"></div>
7
- HTML
8
-
9
- @div.append_to_body
10
- end
1
+ require "spec_helper"
11
2
 
12
- after do
13
- @div.remove
14
- end
3
+ describe "Element#append_to" do
4
+ html <<-HTML
5
+ <div id="foo"></div>
6
+ <div id="bar"></div>
7
+ <div id="baz"></div>
8
+ HTML
15
9
 
16
10
  it "should insert the receiver into the target element" do
17
11
  Document.id('foo').children.size.should == 0
@@ -22,4 +16,4 @@ describe "Element#append_to" do
22
16
  Document.id('bar').append_to Document.id('baz')
23
17
  Document.id('baz').children.id.should == "bar"
24
18
  end
25
- end
19
+ end
@@ -1,19 +1,11 @@
1
- describe "Element#at" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="at-spec">
5
- <div class="foo" id="blah"></div>
6
- <div class="foo" id="bleh"></div>
7
- <div class="foo" id="bluh"></div>
8
- </div>
9
- HTML
10
-
11
- @div.append_to_body
12
- end
1
+ require "spec_helper"
13
2
 
14
- after do
15
- @div.remove
16
- end
3
+ describe "Element#at" do
4
+ html <<-HTML
5
+ <div class="foo" id="blah"></div>
6
+ <div class="foo" id="bleh"></div>
7
+ <div class="foo" id="bluh"></div>
8
+ HTML
17
9
 
18
10
  it "returns the element at the given index" do
19
11
  foos = Document.find '.foo'
@@ -38,4 +30,4 @@ describe "Element#at" do
38
30
  foos.at(-4).should == nil
39
31
  foos.at(4).should == nil
40
32
  end
41
- end
33
+ end
@@ -1,52 +1,44 @@
1
- describe Element do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="attributes-spec">
5
- <div id="foo"></div>
6
- <div id="bar" class="apples"></div>
7
- <div id="baz" class="lemons"></div>
1
+ require "spec_helper"
8
2
 
9
- <div id="attr-foo" title="Hello there!"></div>
10
- <div id="attr-bar"></div>
11
- <div id="attr-baz" title=""></div>
12
- <div id="attr-woosh"></div>
13
- <div id="attr-kapow" title="Apples"></div>
3
+ describe Element do
4
+ html <<-HTML
5
+ <div id="foo"></div>
6
+ <div id="bar" class="apples"></div>
7
+ <div id="baz" class="lemons"></div>
14
8
 
15
- <div id="has-foo" class="apples"></div>
16
- <div id="has-bar" class="lemons bananas"></div>
9
+ <div id="attr-foo" title="Hello there!"></div>
10
+ <div id="attr-bar"></div>
11
+ <div id="attr-baz" title=""></div>
12
+ <div id="attr-woosh"></div>
13
+ <div id="attr-kapow" title="Apples"></div>
17
14
 
18
- <div id="html-foo">Hey there</div>
19
- <div id="html-bar"><p>Erm</p></div>
15
+ <div id="has-foo" class="apples"></div>
16
+ <div id="has-bar" class="lemons bananas"></div>
20
17
 
21
- <div class="html-bridge">Hello</div>
22
- <div class="html-bridge">Hello as well</div>
18
+ <div id="html-foo">Hey there</div>
19
+ <div id="html-bar"><p>Erm</p></div>
23
20
 
24
- <div id="remove-foo"></div>
21
+ <div class="html-bridge">Hello</div>
22
+ <div class="html-bridge">Hello as well</div>
25
23
 
26
- <div id="remove-bar" class="lemons"></div>
27
- <div id="remove-baz" class="apples oranges"></div>
28
- <div id="remove-buz" class="pineapples mangos"></div>
24
+ <div id="remove-foo"></div>
29
25
 
30
- <div id="remove-bleh" class="fruit"></div>
26
+ <div id="remove-bar" class="lemons"></div>
27
+ <div id="remove-baz" class="apples oranges"></div>
28
+ <div id="remove-buz" class="pineapples mangos"></div>
31
29
 
32
- <select id="value-foo">
33
- <option selected="selected">Hello</option>
34
- <option>World</option>
35
- </select>
30
+ <div id="remove-bleh" class="fruit"></div>
36
31
 
37
- <input id="value-bar" type="text" value="Blah"></input>
38
- <div id="value-baz"></div>
32
+ <select id="value-foo">
33
+ <option selected="selected">Hello</option>
34
+ <option>World</option>
35
+ </select>
39
36
 
40
- <input type="text" id="value-woosh" value=""></input>
41
- </div>
42
- HTML
37
+ <input id="value-bar" type="text" value="Blah"></input>
38
+ <div id="value-baz"></div>
43
39
 
44
- @div.append_to_body
45
- end
46
-
47
- after do
48
- @div.remove
49
- end
40
+ <input type="text" id="value-woosh" value=""></input>
41
+ HTML
50
42
 
51
43
  describe '#[]' do
52
44
  it 'should retrieve the attr value from the element' do
@@ -199,4 +191,4 @@ describe Element do
199
191
  foo.value.should == "There"
200
192
  end
201
193
  end
202
- end
194
+ end
@@ -1,20 +1,12 @@
1
- describe "Element#before" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="before-spec">
5
- <div id="some-header" class="kapow"></div>
6
- <div id="foo" class="before-spec-first"></div>
7
- <div id="bar" class="before-spec-first"></div>
8
- <div id="baz"></div>
9
- </div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
1
+ require "spec_helper"
14
2
 
15
- after do
16
- @div.remove
17
- end
3
+ describe "Element#before" do
4
+ html <<-HTML
5
+ <div id="some-header" class="kapow"></div>
6
+ <div id="foo" class="before-spec-first"></div>
7
+ <div id="bar" class="before-spec-first"></div>
8
+ <div id="baz"></div>
9
+ HTML
18
10
 
19
11
  it "should insert the given html string before each element" do
20
12
  el = Document['.before-spec-first']
@@ -30,4 +22,4 @@ describe "Element#before" do
30
22
  Document['#baz'].before Document['#some-header']
31
23
  Document['#baz'].prev.id.should == "some-header"
32
24
  end
33
- end
25
+ end
@@ -1,23 +1,15 @@
1
- describe "Element#class_name" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="class-name-spec">
5
- <div id="foo" class="whiskey"></div>
6
- <div id="bar" class="scotch brandy"></div>
7
- <div id="baz" class=""></div>
8
- <div id="buz"></div>
9
-
10
- <div class="red dark"></div>
11
- <div class="red light"></div>
12
- </div>
13
- HTML
1
+ require "spec_helper"
14
2
 
15
- @div.append_to_body
16
- end
3
+ describe "Element#class_name" do
4
+ html <<-HTML
5
+ <div id="foo" class="whiskey"></div>
6
+ <div id="bar" class="scotch brandy"></div>
7
+ <div id="baz" class=""></div>
8
+ <div id="buz"></div>
17
9
 
18
- after do
19
- @div.remove
20
- end
10
+ <div class="red dark"></div>
11
+ <div class="red light"></div>
12
+ HTML
21
13
 
22
14
  it "should return the elements' class name" do
23
15
  Document.id('foo').class_name.should == "whiskey"
@@ -79,4 +71,4 @@ describe "Element#class_name=" do
79
71
  Document.id('baz').class_name.should == "pop"
80
72
  Document.id('buz').class_name.should == "pop"
81
73
  end
82
- end
74
+ end
@@ -1,19 +1,11 @@
1
- describe "Element#css" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="css-spec">
5
- <div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
6
- <div id="bar"></div>
7
- <div id="hash"></div>
8
- </div>
9
- HTML
10
-
11
- @div.append_to_body
12
- end
1
+ require "spec_helper"
13
2
 
14
- after do
15
- @div.remove
16
- end
3
+ describe "Element#css" do
4
+ html <<-HTML
5
+ <div id="foo" style="background-color:rgb(15,99,30); color:;"></div>
6
+ <div id="bar"></div>
7
+ <div id="hash"></div>
8
+ HTML
17
9
 
18
10
  describe "with a given name" do
19
11
  it "returns the value of the CSS property for the given name" do
@@ -1,18 +1,10 @@
1
- describe "Element display methods" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="css-spec">
5
- <div id="shown"></div>
6
- <div id="hidden" style="display: none"></div>
7
- </div>
8
- HTML
9
-
10
- @div.append_to_body
11
- end
1
+ require "spec_helper"
12
2
 
13
- after do
14
- @div.remove
15
- end
3
+ describe "Element display methods" do
4
+ html <<-HTML
5
+ <div id="shown"></div>
6
+ <div id="hidden" style="display: none"></div>
7
+ HTML
16
8
 
17
9
  it "hides an element" do
18
10
  element = Document.id('shown')
@@ -41,5 +33,4 @@ describe "Element display methods" do
41
33
  element.toggle
42
34
  element.css('display').should == 'none'
43
35
  end
44
-
45
36
  end
@@ -1,19 +1,11 @@
1
- describe "Element#inspect" do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="insert-spec">
5
- <div id="foo"></div>
6
- <div class="bar"></div>
7
- <p id="lol" class="bar"></div>
8
- </div>
9
- HTML
10
-
11
- @div.append_to_body
12
- end
1
+ require "spec_helper"
13
2
 
14
- after do
15
- @div.remove
16
- end
3
+ describe "Element#inspect" do
4
+ html <<-HTML
5
+ <div id="foo"></div>
6
+ <div class="bar"></div>
7
+ <p id="lol" class="bar"></div>
8
+ HTML
17
9
 
18
10
  it "should return a string representation of the elements" do
19
11
  Document.id('foo').inspect.should == '[<div id="foo">]'
@@ -23,4 +15,4 @@ describe "Element#inspect" do
23
15
  it "should return '[]' when called on empty element set" do
24
16
  Document['.inspect-spec-none'].inspect.should == '[]'
25
17
  end
26
- end
18
+ end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ describe Element do
4
+ html <<-HTML
5
+ <table class="players">
6
+ <tr class="player">
7
+ <td class="name">mario</td>
8
+ <td class="surname">rossi</td>
9
+ </tr>
10
+ <tr class="player">
11
+ <td class="name">paolo</td>
12
+ <td class="surname">bianchi</td>
13
+ </tr>
14
+
15
+ </table>
16
+ HTML
17
+
18
+ describe '#each' do
19
+ it "should change all td to pippa" do
20
+ Document.find('table.players td').each do |el|
21
+ el.html = "pippa"
22
+ end
23
+
24
+ Document.find('table.players td').first.html.should == 'pippa'
25
+ #Document.find('table.players td').last.html.should == 'pippa'
26
+ end
27
+ end
28
+
29
+ describe '#map' do
30
+ it "should change all td.surname as array of stirng" do
31
+ lst=Document.find('table.players td.surname').map {|el| el.html }
32
+
33
+ lst.should == ['rossi','bianchi']
34
+ end
35
+ end
36
+
37
+ describe "#to_a" do
38
+ it "should return a list of class Array" do
39
+ Document.find('table.players td.surname').to_a.class.should == Array
40
+ end
41
+
42
+ it "should check first and last element" do
43
+ Document.find('table.players td.surname').to_a.first.html == "rossi"
44
+ Document.find('table.players td.surname').to_a.last.html == "bianchi"
45
+ end
46
+
47
+ it "should get only element with class surname" do
48
+ Document.find('table.players td').to_a.select {|el| el.has_class?('surname') }.
49
+ map {|el| el.class }.uniq == ['surname']
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,7 @@
1
+ require "spec_helper"
2
+
1
3
  describe "Element#length" do
2
4
  it "should report the number of elements in the instance" do
3
5
  Element.new.length.should == 1
4
6
  end
5
- end
7
+ end
@@ -1,3 +1,5 @@
1
+ require "spec_helper"
2
+
1
3
  describe Element do
2
4
  before do
3
5
  @div = Document.parse <<-HTML
@@ -147,4 +149,42 @@ describe "Element#succ" do
147
149
  it "should return an empty instance when no next element" do
148
150
  Document.id('bar').succ.size.should == 0
149
151
  end
150
- end
152
+ end
153
+
154
+ describe "Element#siblings" do
155
+ before do
156
+ @div = Document.parse <<-HTML
157
+ <div id="siblings-spec">
158
+ <div>
159
+ <div id="foo"></div>
160
+ <div id="bar"></div>
161
+ <div id="baz" class="special"></div>
162
+ </div>
163
+ <div>
164
+ <div id="uno"></div>
165
+ </div>
166
+ </div>
167
+ HTML
168
+
169
+ @div.append_to_body
170
+ end
171
+
172
+ after do
173
+ @div.remove
174
+ end
175
+
176
+ it "should return all siblings" do
177
+ Document.id('bar').siblings.size.should == 2
178
+ Document.id('bar').siblings.at(0).id.should == "foo"
179
+ Document.id('bar').siblings.at(1).id.should == "baz"
180
+ end
181
+
182
+ it "should return all siblings that match the selector" do
183
+ Document.id('bar').siblings('.special').size.should == 1
184
+ Document.id('bar').siblings('.special').at(0).id.should == "baz"
185
+ end
186
+
187
+ it "should return an empty instance when there are no siblings" do
188
+ Document.id('uno').siblings.size.should == 0
189
+ end
190
+ end
data/spec/element_spec.rb CHANGED
@@ -1,20 +1,12 @@
1
- describe Element do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="on-spec">
5
- <div id="foo">
6
- <div id="bar" class="apples"></div>
7
- </div>
8
- <div id="baz"></div>
9
- </div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
1
+ require "spec_helper"
14
2
 
15
- after do
16
- @div.remove
17
- end
3
+ describe Element do
4
+ html <<-HTML
5
+ <div id="foo">
6
+ <div id="bar" class="apples"></div>
7
+ </div>
8
+ <div id="baz"></div>
9
+ HTML
18
10
 
19
11
  describe '#on' do
20
12
  it 'adds an event listener onto the elements' do
@@ -67,11 +59,23 @@ describe Element do
67
59
 
68
60
  it 'has an Event instance passed to the handler' do
69
61
  foo = Document['#foo']
70
- foo.on :click do |evt|
71
- evt.should be_kind_of(Event)
62
+ foo.on :click do |event|
63
+ event.should be_kind_of(Event)
72
64
  end
73
65
  foo.trigger(:click)
74
66
  end
67
+
68
+ it 'has an Event instance, plus up to three additional parameters passed to the handler' do
69
+ foo = Document['#foo']
70
+ foo.on :bozo do |event, foo, bar, baz, buz|
71
+ event.should be_kind_of(Event)
72
+ foo.should == 'foo'
73
+ bar.should == 'bar'
74
+ baz.should == 'baz'
75
+ buz.should be_nil
76
+ end
77
+ foo.trigger(:bozo, ['foo', 'bar', 'baz', 'buz'])
78
+ end
75
79
  end
76
80
 
77
81
  describe '#off' do
@@ -104,4 +108,4 @@ describe Element do
104
108
  count.should == 1
105
109
  end
106
110
  end
107
- end
111
+ end
data/spec/event_spec.rb CHANGED
@@ -1,20 +1,14 @@
1
+ require "spec_helper"
2
+
1
3
  describe Event do
2
- before do
3
- @div = Document.parse <<-HTML
4
- <div id="on-spec">
5
- <div id="foo">
6
- <div id="bar"></div>
7
- </div>
8
- <div id="baz"></div>
4
+ html <<-HTML
5
+ <div id="on-spec">
6
+ <div id="foo">
7
+ <div id="bar"></div>
9
8
  </div>
10
- HTML
11
-
12
- @div.append_to_body
13
- end
14
-
15
- after do
16
- @div.remove
17
- end
9
+ <div id="baz"></div>
10
+ </div>
11
+ HTML
18
12
 
19
13
  it '#current_target returns the current element in the bubbling' do
20
14
  foo = Document['#foo']
@@ -63,4 +57,4 @@ describe Event do
63
57
  bar.trigger(:click)
64
58
  target.should == 'bar'
65
59
  end
66
- end
60
+ end
data/spec/http_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "spec_helper"
2
+
1
3
  describe HTTP do
2
4
  describe '#body' do
3
5
  async 'returns the response body as a string' do
@@ -46,4 +48,4 @@ describe HTTP do
46
48
  end
47
49
  end
48
50
  end
49
- end
51
+ end
@@ -1,3 +1,5 @@
1
+ describe "spec_helper"
2
+
1
3
  describe LocalStorage do
2
4
  before do
3
5
  LocalStorage.clear
@@ -48,4 +50,4 @@ describe LocalStorage do
48
50
  LocalStorage.delete('deletable').should == 'Hey there'
49
51
  end
50
52
  end
51
- end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,32 @@
1
- OpalSpec::Runner.autorun
1
+ module OpalSpec
2
+ class ExampleGroup
3
+
4
+ # Add some html code to the body tag ready for testing. This will
5
+ # be added before each test, then removed after each test. It is
6
+ # convenient for adding html setup quickly. The code is wrapped
7
+ # inside a div, which is directly inside the body element.
8
+ #
9
+ # describe "DOM feature" do
10
+ # html <<-HTML
11
+ # <div id="foo"></div>
12
+ # HTML
13
+ #
14
+ # it "foo should exist" do
15
+ # Document["#foo"]
16
+ # end
17
+ # end
18
+ #
19
+ # @param [String] html_string html content to add
20
+ def html(html_string='')
21
+ html = '<div id="opal-jquery-test-div">' + html_string + '</div>'
22
+ before do
23
+ @__html = Document.parse(html)
24
+ @__html.append_to_body
25
+ end
26
+
27
+ after { @__html.remove }
28
+ end
29
+ end
30
+ end
31
+
32
+ OpalSpec::Runner.autorun
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-jquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-27 00:00:00.000000000Z
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Opal DOM library for jquery
15
15
  email: adam.beynon@gmail.com
@@ -23,8 +23,6 @@ files:
23
23
  - LICENSE
24
24
  - README.md
25
25
  - Rakefile
26
- - docs/post.html
27
- - docs/pre.html
28
26
  - lib/opal-jquery.rb
29
27
  - lib/opal-jquery/document.rb
30
28
  - lib/opal-jquery/element.rb
@@ -47,6 +45,7 @@ files:
47
45
  - spec/element/css_spec.rb
48
46
  - spec/element/display_spec.rb
49
47
  - spec/element/inspect_spec.rb
48
+ - spec/element/iterable_spec.rb
50
49
  - spec/element/length_spec.rb
51
50
  - spec/element/traversing_spec.rb
52
51
  - spec/element_spec.rb
@@ -76,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
75
  version: '0'
77
76
  requirements: []
78
77
  rubyforge_project:
79
- rubygems_version: 1.8.11
78
+ rubygems_version: 1.8.24
80
79
  signing_key:
81
80
  specification_version: 3
82
81
  summary: Opal access to jquery
@@ -95,6 +94,7 @@ test_files:
95
94
  - spec/element/css_spec.rb
96
95
  - spec/element/display_spec.rb
97
96
  - spec/element/inspect_spec.rb
97
+ - spec/element/iterable_spec.rb
98
98
  - spec/element/length_spec.rb
99
99
  - spec/element/traversing_spec.rb
100
100
  - spec/element_spec.rb
data/docs/post.html DELETED
@@ -1,3 +0,0 @@
1
- </div>
2
- </body>
3
- </html>
data/docs/pre.html DELETED
@@ -1,18 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>opal-jquery</title>
5
- <link rel="stylesheet" href="css/bootstrap.css" type="text/css">
6
- <link rel="stylesheet" href="css/pygment_trac.css" type="text/css">
7
- <style>
8
- body {
9
- padding-top: 42px;
10
- }
11
- </style>
12
- </head>
13
- <body>
14
- <a href="https://github.com/opal/opal-jquery"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
15
- <div class="container">
16
- <div class="page-header">
17
- <h1>opal-jquery <small>jquery wrapper for opal</small></h1>
18
- </div>