opal-jquery 0.3.0.beta1 → 0.3.0.beta2

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.
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'opal-jquery/local_storage'
2
+ require 'opal/jquery/local_storage'
3
3
 
4
4
  describe LocalStorage do
5
5
  before { subject.clear }
data/spec/spec_helper.rb CHANGED
@@ -1,35 +1,13 @@
1
1
  require 'opal-rspec'
2
- require 'opal-jquery'
2
+ require 'opal/jquery'
3
+ require 'opal/jquery/rspec'
3
4
 
4
- module JqueryHelpers
5
- # Add some html code to the body tag ready for testing. This will
6
- # be added before each test, then removed after each test. It is
7
- # convenient for adding html setup quickly. The code is wrapped
8
- # inside a div, which is directly inside the body element.
9
- #
10
- # describe "DOM feature" do
11
- # html <<-HTML
12
- # <div id="foo"></div>
13
- # HTML
14
- #
15
- # it "foo should exist" do
16
- # Document["#foo"]
17
- # end
18
- # end
19
- #
20
- # @param [String] html_string html content to add
21
- def html(html_string='')
22
- html = %Q{<div id="opal-jquery-test-div">#{html_string}</div>}
23
-
24
- before do
25
- @_spec_html = Element.parse(html)
26
- @_spec_html.append_to_body
27
- end
28
-
29
- after { @_spec_html.remove }
5
+ module JQueryTestHelpers
6
+ def find(selector)
7
+ Element.find selector
30
8
  end
31
9
  end
32
10
 
33
11
  RSpec.configure do |config|
34
- config.extend JqueryHelpers
12
+ config.include JQueryTestHelpers
35
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-jquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta1
4
+ version: 0.3.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0.beta1
19
+ version: 0.7.0.beta3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.0.beta1
26
+ version: 0.7.0.beta3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opal-rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.0.beta2
33
+ version: 0.4.0.beta4
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.0.beta2
40
+ version: 0.4.0.beta4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - ".gitignore"
76
76
  - ".travis.yml"
77
+ - ".yardopts"
77
78
  - CHANGELOG.md
78
79
  - Gemfile
79
80
  - LICENSE
@@ -88,17 +89,17 @@ files:
88
89
  - examples/rake/index.html
89
90
  - lib/opal-jquery.rb
90
91
  - lib/opal/jquery.rb
92
+ - lib/opal/jquery/constants.rb
93
+ - lib/opal/jquery/document.rb
94
+ - lib/opal/jquery/element.rb
95
+ - lib/opal/jquery/event.rb
96
+ - lib/opal/jquery/http.rb
97
+ - lib/opal/jquery/kernel.rb
98
+ - lib/opal/jquery/local_storage.rb
99
+ - lib/opal/jquery/rspec.rb
91
100
  - lib/opal/jquery/version.rb
101
+ - lib/opal/jquery/window.rb
92
102
  - opal-jquery.gemspec
93
- - opal/opal-jquery.rb
94
- - opal/opal-jquery/constants.rb
95
- - opal/opal-jquery/document.rb
96
- - opal/opal-jquery/element.rb
97
- - opal/opal-jquery/event.rb
98
- - opal/opal-jquery/http.rb
99
- - opal/opal-jquery/kernel.rb
100
- - opal/opal-jquery/local_storage.rb
101
- - opal/opal-jquery/window.rb
102
103
  - spec/document_spec.rb
103
104
  - spec/element/after_spec.rb
104
105
  - spec/element/animations_spec.rb
@@ -115,6 +116,7 @@ files:
115
116
  - spec/element/iterable_spec.rb
116
117
  - spec/element/length_spec.rb
117
118
  - spec/element/method_missing_spec.rb
119
+ - spec/element/to_s_spec.rb
118
120
  - spec/element/traversing_spec.rb
119
121
  - spec/element_spec.rb
120
122
  - spec/event_spec.rb
@@ -147,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
149
  version: 1.3.1
148
150
  requirements: []
149
151
  rubyforge_project:
150
- rubygems_version: 2.2.2
152
+ rubygems_version: 2.4.3
151
153
  signing_key:
152
154
  specification_version: 4
153
155
  summary: Opal access to jquery
@@ -168,6 +170,7 @@ test_files:
168
170
  - spec/element/iterable_spec.rb
169
171
  - spec/element/length_spec.rb
170
172
  - spec/element/method_missing_spec.rb
173
+ - spec/element/to_s_spec.rb
171
174
  - spec/element/traversing_spec.rb
172
175
  - spec/element_spec.rb
173
176
  - spec/event_spec.rb
data/opal/opal-jquery.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'opal-jquery/window'
2
- require 'opal-jquery/document'
3
- require 'opal-jquery/element'
4
- require 'opal-jquery/event'
5
- require 'opal-jquery/http'
6
- require 'opal-jquery/kernel'
@@ -1,31 +0,0 @@
1
- require 'opal-jquery/constants'
2
- require 'opal-jquery/element'
3
-
4
- Document = Element.find(`document`)
5
-
6
- class << Document
7
- `var $ = #{JQUERY_SELECTOR.to_n}` # cache $ for SPEED
8
-
9
- def ready?(&block)
10
- `$(#{ block })` if block
11
- end
12
-
13
- def title
14
- `document.title`
15
- end
16
-
17
- def title=(title)
18
- `document.title = #{title}`
19
- end
20
-
21
- def head
22
- Element.find(`document.head`)
23
- end
24
-
25
- def body
26
- Element.find(`document.body`)
27
- end
28
- end
29
-
30
- # TODO: this will be removed soon (here for compatibility)
31
- $document = Document
@@ -1,339 +0,0 @@
1
- require 'native'
2
- require 'opal-jquery/constants'
3
-
4
- class Element < `#{JQUERY_CLASS.to_n}`
5
- `var $ = #{JQUERY_SELECTOR.to_n}` # cache $ for SPEED
6
-
7
- include Enumerable
8
-
9
- def self.find(selector)
10
- `$(#{selector})`
11
- end
12
-
13
- def self.[](selector)
14
- `$(#{selector})`
15
- end
16
-
17
- def self.id(id)
18
- %x{
19
- var el = document.getElementById(id);
20
-
21
- if (!el) {
22
- return nil;
23
- }
24
-
25
- return $(el);
26
- }
27
- end
28
-
29
- def self.new(tag = 'div')
30
- `$(document.createElement(tag))`
31
- end
32
-
33
- def self.parse(str)
34
- `$(str)`
35
- end
36
-
37
- def self.expose(*methods)
38
- method = nil
39
- %x{
40
- for (var i = 0, length = methods.length, method; i < length; i++) {
41
- method = methods[i];
42
- #{alias_native method, method}
43
- }
44
-
45
- return nil;
46
- }
47
- end
48
-
49
- attr_reader :selector
50
-
51
- # Bridged functions - we just expose all core jquery functions as ruby
52
- # methods on this class.
53
- expose :after, :before, :parent, :parents, :prepend, :prev, :remove
54
- expose :hide, :show, :toggle, :children, :blur, :closest, :detach
55
- expose :focus, :find, :next, :siblings, :text, :trigger, :append
56
- expose :serialize, :is, :filter, :last, :first
57
- expose :wrap, :stop, :clone, :empty
58
- expose :get, :attr, :prop
59
-
60
- # We alias some jquery methods to common ruby method names.
61
- alias succ next
62
- alias << append
63
-
64
- # Here we map the remaining jquery methods, but change their names to
65
- # snake_case to be more consistent with ruby.
66
- alias_native :[]=, :attr
67
- alias_native :add_class, :addClass
68
- alias_native :append_to, :appendTo
69
- alias_native :has_class?, :hasClass
70
- alias_native :html=, :html
71
- alias_native :remove_attr, :removeAttr
72
- alias_native :remove_class, :removeClass
73
- alias_native :text=, :text
74
- alias_native :toggle_class, :toggleClass
75
- alias_native :value=, :val
76
- alias_native :scroll_top=, :scrollTop
77
- alias_native :scroll_top, :scrollTop
78
- alias_native :scroll_left=, :scrollLeft
79
- alias_native :scroll_left, :scrollLeft
80
- alias_native :remove_attribute, :removeAttr
81
- alias_native :slide_down, :slideDown
82
- alias_native :slide_up, :slideUp
83
- alias_native :slide_toggle, :slideToggle
84
- alias_native :fade_toggle, :fadeToggle
85
- alias_native :height=, :height
86
- alias_native :width=, :width
87
-
88
- def to_n
89
- self
90
- end
91
-
92
- def [](name)
93
- `self.attr(name) || ""`
94
- end
95
-
96
- def add_attribute name
97
- self[name] = ''
98
- end
99
-
100
- def has_attribute? name
101
- `!!self.attr(name)`
102
- end
103
-
104
- def append_to_body
105
- `self.appendTo(document.body)`
106
- end
107
-
108
- def append_to_head
109
- `self.appendTo(document.head)`
110
- end
111
-
112
- # Returns the element at the given index as a new `DOM` instance.
113
- # Negative indexes can be used and are counted from the end. If the
114
- # given index is outside the range then `nil` is returned.
115
- def at(index)
116
- %x{
117
- var length = self.length;
118
-
119
- if (index < 0) {
120
- index += length;
121
- }
122
-
123
- if (index < 0 || index >= length) {
124
- return nil;
125
- }
126
-
127
- return $(self[index]);
128
- }
129
- end
130
-
131
- # Returns the CSS class name of the firt element in self collection.
132
- # If the collection is empty then an empty string is returned. Only
133
- # the class name of the first element will ever be returned.
134
- def class_name
135
- %x{
136
- var first = self[0];
137
- return (first && first.className) || "";
138
- }
139
- end
140
-
141
- # Sets the CSS class name of every element in self collection to the
142
- # given string. self does not append the class names, it replaces
143
- # the entire current class name.
144
- def class_name=(name)
145
- %x{
146
- for (var i = 0, length = self.length; i < length; i++) {
147
- self[i].className = name;
148
- }
149
- }
150
- self
151
- end
152
-
153
- # Get or set css properties on each element in self collection. If
154
- # only the `name` is given, then that css property name is read from
155
- # the first element in the collection and returned. If the `value`
156
- # property is also given then the given css property is set to the
157
- # given value for each of the elements in self collection. The
158
- # property can also be a hash of properties and values.
159
- def css(name, value=nil)
160
- if value.nil? && name.is_a?(String)
161
- return `self.css(name)`
162
- else
163
- name.is_a?(Hash) ? `self.css(#{name.to_n})` : `self.css(name, value)`
164
- end
165
- self
166
- end
167
-
168
- # Set css values over time to create animations. The first parameter is a
169
- # set of css properties and values to animate to. The first parameter
170
- # also accepts a special :speed value to set animation speed. If a block
171
- # is given, the block is run as a callback when the animation finishes.
172
- def animate(params, &block)
173
- speed = params.has_key?(:speed) ? params.delete(:speed) : 400
174
- %x{
175
- self.animate(#{params.to_n}, #{speed}, function() {
176
- #{block.call if block_given?}
177
- })
178
- }
179
- end
180
-
181
- def data(*args)
182
- %x{
183
- var result = self.data.apply(self, args);
184
- return result == null ? nil : result;
185
- }
186
- end
187
-
188
- # Start a visual effect (e.g. fadeIn, fadeOut, …) passing its name.
189
- # Underscored style is automatically converted (e.g. `effect(:fade_in)`).
190
- # Also accepts additional arguments and a block for the finished callback.
191
- def effect(name, *args, &block)
192
- name = name.gsub(/_\w/) { |match| match[1].upcase }
193
- args = args.map { |a| a.to_n if a.respond_to? :to_n }.compact
194
- args << `function() { #{block.call if block_given?} }`
195
- `self[#{name}].apply(self, #{args})`
196
- end
197
-
198
- def visible?
199
- `self.is(':visible')`
200
- end
201
-
202
- def offset
203
- Native(`self.offset()`)
204
- end
205
-
206
- def each
207
- `for (var i = 0, length = self.length; i < length; i++) {`
208
- yield `$(self[i])`
209
- `}`
210
- self
211
- end
212
-
213
- def first
214
- `self.length ? self.first() : nil`
215
- end
216
-
217
- def html(content = undefined)
218
- %x{
219
- if (content != null) {
220
- return self.html(content);
221
- }
222
-
223
- return self.html() || '';
224
- }
225
- end
226
-
227
- def id
228
- %x{
229
- var first = self[0];
230
- return (first && first.id) || "";
231
- }
232
- end
233
-
234
- def id=(id)
235
- %x{
236
- var first = self[0];
237
-
238
- if (first) {
239
- first.id = id;
240
- }
241
-
242
- return self;
243
- }
244
- end
245
-
246
- def tag_name
247
- `self.length > 0 ? self[0].tagName.toLowerCase() : #{nil}`
248
- end
249
-
250
- def inspect
251
- %x{
252
- if (self[0] === document) return '#<Element [document]>'
253
- else if (self[0] === window ) return '#<Element [window]>'
254
-
255
- var val, el, str, result = [];
256
-
257
- for (var i = 0, length = self.length; i < length; i++) {
258
- el = self[i];
259
- str = "<" + el.tagName.toLowerCase();
260
-
261
- if (val = el.id) str += (' id="' + val + '"');
262
- if (val = el.className) str += (' class="' + val + '"');
263
-
264
- result.push(str + '>');
265
- }
266
-
267
- return '#<Element [' + result.join(', ') + ']>';
268
- }
269
- end
270
-
271
- def length
272
- `self.length`
273
- end
274
-
275
- def any?
276
- `self.length > 0`
277
- end
278
-
279
- def empty?
280
- `self.length === 0`
281
- end
282
-
283
- alias empty? none?
284
-
285
- def on(name, sel = nil, &block)
286
- %x{
287
- var wrapper = function(evt) {
288
- if (evt.preventDefault) {
289
- evt = #{Event.new `evt`};
290
- }
291
-
292
- return block.apply(null, arguments);
293
- };
294
-
295
- block._jq_wrap = wrapper;
296
-
297
- if (sel == nil) {
298
- self.on(name, wrapper);
299
- }
300
- else {
301
- self.on(name, sel, wrapper);
302
- }
303
- }
304
-
305
- block
306
- end
307
-
308
- def off(name, sel, block = nil)
309
- %x{
310
- if (sel == null) {
311
- return self.off(name);
312
- }
313
- else if (block === nil) {
314
- return self.off(name, sel._jq_wrap);
315
- }
316
- else {
317
- return self.off(name, sel, block._jq_wrap);
318
- }
319
- }
320
- end
321
-
322
- alias size length
323
-
324
- def value
325
- `self.val() || ""`
326
- end
327
-
328
- def height
329
- `self.height() || nil`
330
- end
331
-
332
- def width
333
- `self.width() || nil`
334
- end
335
-
336
- def position
337
- Native(`self.position()`)
338
- end
339
- end