opal-jquery 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,5 +2,6 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
- gem 'opal', :github => 'opal/opal'
5
+ gem 'opal'
6
6
  gem 'opal-spec'
7
+ gem 'opal-sprockets'
data/README.md CHANGED
@@ -8,13 +8,25 @@ opal-jquery is [hosted on github](http://github.com/opal/opal-jquery).
8
8
 
9
9
  See the [website for documentation](http://opalrb.org/jquery).
10
10
 
11
- ### Running Specs
11
+ ## Documentation
12
+
13
+ ### HTTP
14
+
15
+ The `HTTP` class wraps jQuery's ajax request into a ruby class.
16
+
17
+ ```ruby
18
+ HTTP.get("/users/1.json") do |response|
19
+ puts "Got response!"
20
+ end
21
+ ```
22
+
23
+ ## Running Specs
12
24
 
13
25
  Get the dependencies:
14
26
 
15
27
  $ bundle install
16
28
 
17
- #### Browser
29
+ ### Browser
18
30
 
19
31
  You can run the specs in any web browser, by running the `config.ru` rack file:
20
32
 
@@ -22,7 +34,7 @@ You can run the specs in any web browser, by running the `config.ru` rack file:
22
34
 
23
35
  And then visiting `http://localhost:9292` in any web browser.
24
36
 
25
- #### Phantomjs
37
+ ### Phantomjs
26
38
 
27
39
  You will need phantomjs to run the specs outside the browser. It can
28
40
  be downloaded at [http://phantomjs.org/download.html](http://phantomjs.org/download.html)
@@ -35,7 +47,9 @@ Run the tests inside a phantom.js runner:
35
47
 
36
48
  $ bundle exec rake
37
49
 
38
- ### License
50
+ ## License
51
+
52
+ (The MIT License)
39
53
 
40
54
  Copyright (C) 2013 by Adam Beynon
41
55
 
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module JQuery
3
- VERSION = '0.0.11'
3
+ VERSION = '0.0.12'
4
4
  end
5
5
  end
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ['lib']
17
17
 
18
- s.add_runtime_dependency 'opal', '>= 0.4.2'
19
- s.add_development_dependency 'opal-spec', '>= 0.2.15'
18
+ s.add_runtime_dependency 'opal', '>= 0.4.3'
19
+ s.add_development_dependency 'opal-spec', '>= 0.3.0'
20
20
  end
@@ -1,13 +1,20 @@
1
1
  require 'opal-jquery/element'
2
2
 
3
- $document = Element.find($global.document)
3
+ Document = Element.find(`document`)
4
4
 
5
- class << $document
6
- # Use Element.ready? instead
5
+ class << Document
7
6
  def ready?(&block)
8
- ::Element.ready?(&block)
7
+ `$(#{ block })` if block
8
+ end
9
+
10
+ def title
11
+ `document.title`
12
+ end
13
+
14
+ def title=(title)
15
+ `document.title = #{title}`
9
16
  end
10
17
  end
11
18
 
12
19
  # TODO: this will be removed soon (here for compatibility)
13
- Document = $document
20
+ $document = Document
@@ -1,16 +1,19 @@
1
- # Instances of Element are just jquery instances, and wrap 1 or more
2
- # native dom elements.
3
-
4
- %x{
5
- var root = __opal.global, dom_class;
1
+ class Element
2
+ %x{
3
+ var root = __opal.global, dom_class;
6
4
 
7
- if (root.jQuery) { dom_class = jQuery }
8
- else if (root.Zepto) { dom_class = Zepto.zepto.Z; }
9
- }
5
+ if (root.jQuery) {
6
+ dom_class = jQuery
7
+ }
8
+ else if (root.Zepto) {
9
+ dom_class = Zepto.zepto.Z;
10
+ }
10
11
 
11
- Class.bridge_class 'Element', `dom_class`
12
+ #{self}._proto = dom_class.prototype, def = #{self}._proto;
13
+ dom_class.prototype._klass = #{self};
14
+ }
12
15
 
13
- class Element
16
+ include Kernel
14
17
  include Enumerable
15
18
 
16
19
  def self.find(selector)
@@ -41,15 +44,11 @@ class Element
41
44
  `$(str)`
42
45
  end
43
46
 
44
- def self.ready?(&block)
45
- `$(#{ block })` if block
46
- end
47
-
48
47
  def self.expose(*methods)
49
48
  %x{
50
49
  for (var i = 0, length = methods.length, method; i < length; i++) {
51
50
  method = methods[i];
52
- #{self}.prototype['$' + method] = #{self}.prototype[method];
51
+ #{self}._proto['$' + method] = #{self}._proto[method];
53
52
  }
54
53
 
55
54
  return nil;
@@ -102,6 +101,10 @@ class Element
102
101
  super
103
102
  end
104
103
 
104
+ def to_n
105
+ self
106
+ end
107
+
105
108
  def [](name)
106
109
  `#{self}.attr(name) || ""`
107
110
  end
@@ -340,7 +343,7 @@ class Element
340
343
  result.push(str + '>');
341
344
  }
342
345
 
343
- return '[' + result.join(', ') + ']';
346
+ return '#<Element [' + result.join(', ') + ']>';
344
347
  }
345
348
  end
346
349
 
@@ -1,7 +1,16 @@
1
- Class.bridge_class 'Event', `$.Event`
1
+ #Class.bridge_class 'Event', `$.Event`
2
2
 
3
3
  # Wraps native jQuery event objects.
4
4
  class Event
5
+ %x{
6
+ var bridge_class = $.Event;
7
+
8
+ #{self}._proto = bridge_class.prototype, def = #{self}._proto;
9
+ bridge_class.prototype._klass = #{self};
10
+ }
11
+
12
+ include Kernel
13
+
5
14
  def [](name)
6
15
  `#{self}[name]`
7
16
  end
@@ -1,9 +1,5 @@
1
- # Wraps jQuery's ajax request into a ruby class.
2
- #
3
- # HTTP.get("/users/1.json") do |response|
4
- # puts "Got response!"
5
- # end
6
- #
1
+ require 'json'
2
+
7
3
  class HTTP
8
4
  attr_reader :body, :error_message, :method, :status_code, :url, :xhr
9
5
 
@@ -40,7 +36,7 @@ class HTTP
40
36
  if (typeof(payload) === 'string') {
41
37
  settings.data = payload;
42
38
  }
43
- else if (payload != null) {
39
+ else if (payload != nil) {
44
40
  settings.data = payload.$to_json();
45
41
  settings.contentType = 'application/json';
46
42
  }
@@ -1,7 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Document.ready?" do
4
- it "accepts a block" do
5
- $document.ready? { }
3
+ describe Document do
4
+ describe "ready?" do
5
+ it "accepts a block" do
6
+ Document.ready? { }
7
+ end
8
+ end
9
+
10
+ describe "title" do
11
+ it "gets the document title" do
12
+ Document.title.should be_kind_of(String)
13
+ end
14
+ end
15
+
16
+ describe "title=" do
17
+ it "sets the document title" do
18
+ old = Document.title
19
+ Document.title = "foo"
20
+ Document.title.should eq("foo")
21
+ Document.title = old
22
+ end
6
23
  end
7
24
  end
@@ -8,11 +8,11 @@ describe "Element#inspect" do
8
8
  HTML
9
9
 
10
10
  it "should return a string representation of the elements" do
11
- Element.find('#foo').inspect.should == '[<div id="foo">]'
12
- Element.find('.bar').inspect.should == '[<div class="bar">, <p id="lol" class="bar">]'
11
+ Element.find('#foo').inspect.should == '#<Element [<div id="foo">]>'
12
+ Element.find('.bar').inspect.should == '#<Element [<div class="bar">, <p id="lol" class="bar">]>'
13
13
  end
14
14
 
15
15
  it "should return '[]' when called on empty element set" do
16
- Element.find('.inspect-spec-none').inspect.should == '[]'
16
+ Element.find('.inspect-spec-none').inspect.should == '#<Element []>'
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,43 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-jquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Adam Beynon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-07-04 00:00:00.000000000 Z
12
+ date: 2013-07-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: opal
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
- version: 0.4.2
21
+ version: 0.4.3
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
- version: 0.4.2
29
+ version: 0.4.3
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: opal-spec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
- version: 0.2.15
37
+ version: 0.3.0
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
- version: 0.2.15
45
+ version: 0.3.0
41
46
  description: Opal DOM library for jquery
42
47
  email: adam.beynon@gmail.com
43
48
  executables: []
@@ -94,26 +99,27 @@ files:
94
99
  - spec/zepto.js
95
100
  homepage: http://opalrb.org
96
101
  licenses: []
97
- metadata: {}
98
102
  post_install_message:
99
103
  rdoc_options: []
100
104
  require_paths:
101
105
  - lib
102
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
103
108
  requirements:
104
- - - '>='
109
+ - - ! '>='
105
110
  - !ruby/object:Gem::Version
106
111
  version: '0'
107
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
108
114
  requirements:
109
- - - '>='
115
+ - - ! '>='
110
116
  - !ruby/object:Gem::Version
111
117
  version: '0'
112
118
  requirements: []
113
119
  rubyforge_project:
114
- rubygems_version: 2.0.3
120
+ rubygems_version: 1.8.23
115
121
  signing_key:
116
- specification_version: 4
122
+ specification_version: 3
117
123
  summary: Opal access to jquery
118
124
  test_files:
119
125
  - spec/data/simple.txt
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 1a1320ee8ce46da9f6e13f8fae2cf9dc5b062057
4
- data.tar.gz: 68176702723fe79fa9a41b4aa72e9f80a3197055
5
- SHA512:
6
- metadata.gz: c2374379fc2299c09c9102b042d83551031efacd1552a7b56fd1a7575c073e30d8e799abc42998785ddcfb425acc3acfca56696a3f4f48a4a10912257c82bb24
7
- data.tar.gz: b16dbca570cf895d958b0a5a81f65b0aa2d302169b5827b764167ef6e2648e9804685748956fbf402e8c238de2db8b303c253b8bc4e29030f27e65e498e9b402