opal-jquery 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ gem 'rake'
5
5
  gem 'sprockets'
6
6
 
7
7
  gem 'opal', '~> 0.3.36'
8
- gem 'opal-spec', '~> 0.2.8'
8
+ gem 'opal-spec', '~> 0.2.10'
data/README.md CHANGED
@@ -6,238 +6,24 @@ opal-jquery provides DOM access to opal by wrapping jQuery (or zepto)
6
6
  and providing a nice ruby syntax for dealing with jQuery instances.
7
7
  opal-jquery is [hosted on github](http://github.com/opal/opal-jquery).
8
8
 
9
- jQuery instances are toll-free bridged to instances of the ruby class
10
- `JQuery`, so they can be used interchangeably. The `Document` module also
11
- exists, which provides the simple top level css selector method:
9
+ See the [website for documentation](http://opalrb.org/jquery).
12
10
 
13
- ```ruby
14
- elements = Document['.foo']
15
- # => [<div class="foo">, ...]
16
-
17
- elements.class
18
- # => JQuery
19
-
20
- elements.on(:click) do
21
- alert "element was clicked"
22
- end
23
- ```
24
-
25
- ### Getting Started
26
-
27
- #### Installation
28
-
29
- Install opal-jquery from RubyGems:
30
-
31
- ```
32
- $ gem install opal-jquery
33
- ```
34
-
35
- Or include it in your Gemfile for Bundler:
36
-
37
- ```ruby
38
- gem 'opal-jquery'
39
- ```
40
-
41
- ### Interacting with the DOM
42
-
43
- #### Finding elements
44
-
45
- opal-jquery provides the `Document` module, which is the best way to
46
- find elements by CSS selector:
47
-
48
- ```ruby
49
- Document['#header']
50
- ```
51
-
52
- This method acts just like `$('selector')`, and can use any jQuery
53
- compatible selector:
54
-
55
- ```ruby
56
- Document['#navigation li:last']
57
- ```
58
-
59
- The result is just a jQuery instance, which is toll-free bridged to
60
- instances of the `Element` class in ruby:
61
-
62
- ```ruby
63
- Document['.foo'].class
64
- # => Element
65
- ```
66
-
67
- Instances of `Element` also have the `#find` method available for
68
- finding elements within the scope of each DOM node represented by
69
- the instance:
70
-
71
- ```ruby
72
- el = Document['#header']
73
- el.find '.foo'
74
- # => #<Element .... >
75
- ```
76
-
77
- #### Running code on document ready
78
-
79
- Just like jQuery, opal-jquery requires the document to be ready to
80
- be able to fully interact with the page. Any top level access should
81
- use the `ready?` method:
82
-
83
- ```ruby
84
- Document.ready? do
85
- alert "document is ready to go!"
86
- end
87
- ```
88
-
89
- The `Kernel#alert` method is shown above too.
90
-
91
- #### Event handling
92
-
93
- The `Element#on` method is used to attach event handlers to elements:
94
-
95
- ```ruby
96
- Document['#header'].on :click do
97
- puts "The header was clicked!"
98
- end
99
- ```
100
-
101
- Selectors can also be passed as a second argument to handle events
102
- on certain children:
103
-
104
- ```ruby
105
- Document['#header'].on(:click, '.foo') do
106
- puts "An element with a 'foo' class was clicked"
107
- end
108
- ```
109
-
110
- An `Event` instance is optionally passed to block handlers as well,
111
- which is toll-free bridged to jquery events:
112
-
113
- ```ruby
114
- Document['#my_link'].on(:click) do |evt|
115
- evt.stop_propagation
116
- puts "stopped the event!"
117
- end
118
- ```
119
-
120
- #### CSS styles and classnames
121
-
122
- The various jQuery methods are available on `Element` instances:
123
-
124
- ```ruby
125
- foo = Document['.foo']
126
-
127
- foo.add_class 'blue'
128
- foo.remove_class 'foo'
129
- foo.toggle_class 'selected'
130
- ```
131
-
132
- There are also added convenience methods for opal-jquery:
133
-
134
- ```ruby
135
- foo = Document['#header']
136
-
137
- foo.class_name
138
- # => 'red lorry'
139
-
140
- foo.class_name = 'yellow house'
141
-
142
- foo.class_name
143
- # => 'yellow house'
144
- ```
145
-
146
- `Element#css` also exists for getting/setting css styles:
147
-
148
- ```ruby
149
- el = Document['#container']
150
- el.css 'color', 'blue'
151
- el.css 'color'
152
- # => 'blue'
153
- ```
154
-
155
- ### HTTP/AJAX requests
156
-
157
- jQuery's Ajax implementation is also wrapped in the top level HTTP
158
- class.
159
-
160
- ```ruby
161
- HTTP.get("/users/1.json") do |response|
162
- puts response.body
163
- # => "{\"name\": \"Adam Beynon\"}"
164
- end
165
- ```
166
-
167
- The block passed to this method is used as the handler when the request
168
- succeeds, as well as when it fails. To determine whether the request
169
- was successful, use the `ok?` method:
170
-
171
- ```ruby
172
- HTTP.get("/users/2.json") do |response|
173
- if response.ok?
174
- alert "successful!"
175
- else
176
- alert "request failed :("
177
- end
178
- end
179
- ```
180
-
181
- It is also possible to use a different handler for each case:
182
-
183
- ```ruby
184
- request = HTTP.get("/users/3.json")
185
-
186
- request.callback {
187
- puts "Request worked!"
188
- }
189
-
190
- request.errback {
191
- puts "Request didn't work :("
192
- }
193
- ```
194
-
195
- The request is actually triggered inside the `HTTP.get` method, but due
196
- to the async nature of the request, the callback and errback handlers can
197
- be added anytime before the request returns.
198
-
199
- #### Handling responses
200
-
201
- Web apps deal with JSON responses quite frequently, so there is a useful
202
- `#json` helper method to get the JSON content from a request:
203
-
204
- ```ruby
205
- HTTP.get("/users.json") do |response|
206
- puts response.body
207
- puts response.json
208
- end
11
+ ### Running Specs
209
12
 
210
- # => "[{\"name\": \"Adam\"},{\"name\": \"Ben\"}]"
211
- # => [{"name" => "Adam"}, {"name" => "Ben"}]
212
- ```
13
+ Get the dependencies:
213
14
 
214
- The `#body` method will always return the raw response string.
15
+ $ bundle install
215
16
 
216
- If an error is encountered, then the `#status_code` method will hold the
217
- specific error code from the underlying request:
17
+ #### Browser
218
18
 
219
- ```ruby
220
- request = HTTP.get("/users/3.json")
19
+ You can run the specs in any web browser, by running the `config.ru` rack file:
221
20
 
222
- request.callback { puts "it worked!" }
21
+ $ bundle exec rackup
223
22
 
224
- request.errback { |response|
225
- puts "failed with status #{response.status_code}"
226
- }
227
- ```
23
+ And then visiting `http://localhost:9292` in any web browser.
228
24
 
229
- opal-jquery provides DOM access to opal by wrapping jQuery
230
- and providing a nice ruby syntax for dealing with jQuery instances.
231
- opal-jquery is [hosted on github](http://github.com/opal/opal-jquery).
25
+ #### Phantomjs
232
26
 
233
- See the [website for documentation](http://opal.github.com/opal-jquery).
234
-
235
- ### Running Specs
236
-
237
- Get the dependencies:
238
-
239
- $ bundle install
240
-
241
27
  You will need phantomjs to run the specs outside the browser. It can
242
28
  be downloaded at [http://phantomjs.org/download.html](http://phantomjs.org/download.html)
243
29
 
@@ -247,28 +33,7 @@ On osx you can install through homebrew
247
33
 
248
34
  Run the tests inside a phantom.js runner:
249
35
 
250
- $ rake
251
-
252
- You can also run the tests in the browser by opening spec/index.html.
253
-
254
- ### Development Tips
255
-
256
- The following rake task are pertinent to adding/changing
257
- functionality.
258
-
259
- * opal - builds the following js files:
260
- * opal-jquery - opal jquery
261
- * opal.js - the opal runtime
262
- * opal-spec.js - opal spec framework
263
- * specs.js - the spec
264
- * opal:test - runs the specs. It is the default rake task
265
-
266
- If you TDD, you may want to run
267
-
268
- $ rake opal opal:test
269
-
270
- Or use a guard script that does similar
271
-
36
+ $ bundle exec rake
272
37
 
273
38
  ### License
274
39
 
data/config.ru CHANGED
@@ -1,31 +1,10 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
- html = <<-HTML
5
- <!DOCTYPE html>
6
- <html>
7
- <head>
8
- <title>opal-jquery specs</title>
9
- </head>
10
- <body>
11
- <script src="/assets/autorun.js"></script>
12
- </body>
13
- </html>
14
- HTML
4
+ require 'opal/spec/server'
15
5
 
16
- map '/assets' do
17
- env = Opal::Environment.new
18
- env.append_path 'vendor' # for jquery
19
- env.append_path 'spec'
20
- run env
21
- end
6
+ # Run in non-debug mode (faster, all files concatenated into 1 file)
7
+ run Opal::Spec::Server.new(false)
22
8
 
23
- map '/' do
24
- run lambda { |env|
25
- if env['PATH_INFO'] == '/'
26
- [200, {'Content-Type' => 'text/html'}, [html]]
27
- else
28
- Rack::Directory.new('spec').call(env)
29
- end
30
- }
31
- end
9
+ # Run in debug mode - all files loaded seperately, but slower
10
+ # run Opal::Spec::Server.new
@@ -0,0 +1 @@
1
+ require 'opal/jquery'
@@ -29,10 +29,7 @@ module Document
29
29
  return nil;
30
30
  }
31
31
 
32
- $(function() {
33
- #{ block.call };
34
- });
35
-
32
+ $(block);
36
33
  return nil;
37
34
  }
38
35
  end
@@ -10,6 +10,7 @@ class Event < `$.Event`
10
10
 
11
11
  alias_native :default_prevented?, :isDefaultPrevented
12
12
 
13
+ # Stops propagation and prevents default action.
13
14
  def kill
14
15
  stop_propagation
15
16
  prevent_default
@@ -5,11 +5,7 @@
5
5
  # end
6
6
  #
7
7
  class HTTP
8
- attr_reader :body
9
- attr_reader :error_message
10
- attr_reader :method
11
- attr_reader :status_code
12
- attr_reader :url
8
+ attr_reader :body, :error_message, :method, :status_code, :url
13
9
 
14
10
  def self.get(url, opts={}, &block)
15
11
  self.new(url, :GET, opts, block).send!
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module JQuery
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
5
5
  end
File without changes
@@ -2,7 +2,7 @@ require 'jquery'
2
2
  require 'opal-spec'
3
3
  require 'opal-jquery'
4
4
 
5
- module OpalSpec
5
+ module Spec
6
6
  class ExampleGroup
7
7
 
8
8
  # Add some html code to the body tag ready for testing. This will
@@ -24,13 +24,11 @@ module OpalSpec
24
24
  def html(html_string='')
25
25
  html = '<div id="opal-jquery-test-div">' + html_string + '</div>'
26
26
  before do
27
- @__html = Document.parse(html)
28
- @__html.append_to_body
27
+ @_spec_html = Document.parse(html)
28
+ @_spec_html.append_to_body
29
29
  end
30
30
 
31
- after { @__html.remove }
31
+ after { @_spec_html.remove }
32
32
  end
33
33
  end
34
34
  end
35
-
36
- Opal::Spec::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.5
4
+ version: 0.0.6
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: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Opal DOM library for jquery
15
15
  email: adam.beynon@gmail.com
@@ -24,7 +24,7 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - config.ru
27
- - lib/assets/javascripts/opal-jquery.js.erb
27
+ - lib/assets/javascripts/opal-jquery.rb
28
28
  - lib/assets/javascripts/opal/jquery.rb
29
29
  - lib/assets/javascripts/opal/jquery/document.rb
30
30
  - lib/assets/javascripts/opal/jquery/element.rb
@@ -36,7 +36,6 @@ files:
36
36
  - lib/opal/jquery.rb
37
37
  - lib/opal/jquery/version.rb
38
38
  - opal-jquery.gemspec
39
- - spec/autorun.rb
40
39
  - spec/data/simple.txt
41
40
  - spec/data/user.json
42
41
  - spec/document_spec.rb
@@ -57,9 +56,9 @@ files:
57
56
  - spec/element_spec.rb
58
57
  - spec/event_spec.rb
59
58
  - spec/http_spec.rb
59
+ - spec/jquery.js
60
60
  - spec/local_storage_spec.rb
61
61
  - spec/spec_helper.rb
62
- - vendor/jquery.js
63
62
  homepage: http://opalrb.org
64
63
  licenses: []
65
64
  post_install_message:
@@ -85,7 +84,6 @@ signing_key:
85
84
  specification_version: 3
86
85
  summary: Opal access to jquery
87
86
  test_files:
88
- - spec/autorun.rb
89
87
  - spec/data/simple.txt
90
88
  - spec/data/user.json
91
89
  - spec/document_spec.rb
@@ -106,5 +104,6 @@ test_files:
106
104
  - spec/element_spec.rb
107
105
  - spec/event_spec.rb
108
106
  - spec/http_spec.rb
107
+ - spec/jquery.js
109
108
  - spec/local_storage_spec.rb
110
109
  - spec/spec_helper.rb
@@ -1,3 +0,0 @@
1
- //= require opal/jquery
2
-
3
- Opal.jquery_version = <%= Opal::JQuery::VERSION.inspect %>;
@@ -1,3 +0,0 @@
1
- #= require opal
2
- #= require opal-spec
3
- #= require_tree .