wedge 0.1.66 → 0.1.67

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cc03dd1e943450e9ac281e2e70c71e119909bac
4
- data.tar.gz: d7066f50276c808748676e32ecb6d740f1b1f4ba
3
+ metadata.gz: 4f648b76e8e443e40be3a210bb3ba8dd3f960dd1
4
+ data.tar.gz: 8aefe262e6c7b0c182ad403658ade6d46217069e
5
5
  SHA512:
6
- metadata.gz: 808548fd23b4324e9dd229004def699ff7d5360bc8cce5082f1953027b31adafa431e2f5969c1a3f4170695cd8b699cfc924f293007996180494b6d6228a6ac0
7
- data.tar.gz: 6211d3ffc026253ffda27ab24bd8cccf0080eae323ef9deecaa2d52982db98a0a95a64ce5f3d6df95410fa86195e2e2e5145a8988d8d45dd24017285a60bc908
6
+ metadata.gz: 0db89b405e950c3c7e12ca6e350275376d5536f78f015bafea62deec0f774f3642ab3e906ec02fe2a6de0020720e85a16e0c49127cc16ddb03e80e1fbd43a62b
7
+ data.tar.gz: 0d55c19a2bfe6ad86a109d91014844e095184baa8ac167931d3ebe84dacc0faea6b7d3619f2221dc1dbcfa0337e9675aa9588fcdd04d6861c831318735af154a
data/lib/wedge/dom.rb CHANGED
@@ -30,11 +30,7 @@ class Wedge
30
30
  if client?
31
31
  node = Wedge::DOM.new dom.find(string)
32
32
  elsif server?
33
- if block_given?
34
- node = Wedge::DOM.new dom.css(string)
35
- else
36
- node = Wedge::DOM.new dom.at(string)
37
- end
33
+ node = Wedge::DOM.new dom.css(string)
38
34
  end
39
35
 
40
36
  if block_given?
@@ -47,52 +43,128 @@ class Wedge
47
43
  end
48
44
 
49
45
  unless RUBY_ENGINE == 'opal'
50
- def prepend d
51
- if n = node.children.first
52
- n.add_previous_sibling d
53
- else
54
- node << d
46
+
47
+ %w'content inner_html'.each do |meth|
48
+ define_method "#{meth}=" do |cont|
49
+ if node.is_a? Nokogiri::XML::NodeSet
50
+ node.each { |n| n.send("#{meth}=", cont) }
51
+ else
52
+ node.send "#{meth}=", cont
53
+ end
55
54
  end
56
55
  end
57
56
 
58
- def append d
59
- if n = node.children.first
60
- def display el, options = {}, &block
61
- d = d.dom if d.is_a? Wedge::DOM
62
-
63
- return if el.data 'wedge-popover'
57
+ %w'add_child replace prepend_child'.each do |meth|
58
+ define_method meth do |*args|
59
+ if node.is_a? Nokogiri::XML::NodeSet
60
+ node.each { |n| n.send(meth, *args) }
61
+ else
62
+ node.send(meth, *args)
63
+ end
64
+ end
65
+ end
64
66
 
65
- el.data 'wedge-popover', true
66
- el = el.to_n
67
+ def []= key, value
68
+ if node.is_a? Nokogiri::XML::NodeSet
69
+ node.each { |n| n[key] = value }
70
+ else
71
+ node[key] = value
72
+ end
73
+ end
67
74
 
68
- options = {
69
- content: 'Loading...',
70
- position: 'right middle',
71
- openOn: 'hover'
72
- }.merge(options)
75
+ def << d
76
+ if node.is_a? Nokogiri::XML::NodeSet
77
+ node.each { |n| n << d }
78
+ else
79
+ node << d
80
+ end
81
+ end
73
82
 
74
- options[:classes] = "drop-theme-arrows #{options[:classes]}"
83
+ # def prepend d
84
+ # if n = node.children.first
85
+ # n.add_previous_sibling d
86
+ # else
87
+ # node << d
88
+ # end
89
+ # end
75
90
 
76
- options = options.to_n
91
+ def prepend d
92
+ if node.is_a? Nokogiri::XML::NodeSet
93
+ node.each do |n|
94
+ if nn = n.children.first
95
+ nn.add_previous_sibling d
96
+ else
97
+ nn << d
98
+ end
99
+ end
100
+ else
101
+ if n = node.children.first
102
+ n.add_previous_sibling d
103
+ else
104
+ node << d
105
+ end
106
+ end
107
+ end
77
108
 
78
- opts = `$.extend(options, { target: el[0] })`
79
- drop = Native(`new Drop(opts)`)
109
+ def append d
110
+ if node.is_a? Nokogiri::XML::NodeSet
111
+ node.each do |n|
112
+ if nn = n.children.last
113
+ nn.add_next_sibling d
114
+ else
115
+ nn << d
116
+ end
117
+ end
118
+ else
119
+ if n = node.children.last
120
+ n.add_next_sibling d
121
+ else
122
+ node.content << d
123
+ end
124
+ end
125
+ end
80
126
 
81
- block.call(Native(opts)) if block_given?
127
+ def hide
128
+ if node.is_a? Nokogiri::XML::NodeSet
129
+ node.each do |n|
130
+ DOM.new(n).style 'display', 'none'
131
+ end
132
+ else
133
+ node.style 'display', 'none'
134
+ end
82
135
 
83
- drop
136
+ node
84
137
  end
85
138
 
86
- def ajax el, options = {}, &block
87
- options = { content: 'loading' }.merge options
88
- display el, options, &block
89
- end
90
- n.add_next_sibling d
139
+ def style *args
140
+ style_object = DOM.new(node).styles
141
+
142
+ if args.length == 1
143
+ style_object[args.first]
91
144
  else
92
- node << d
145
+ style_object[args.first] = args.last
146
+ node['style'] = style_object.map { |k, v| [k, v].join(': ') }.join('; ')
93
147
  end
94
148
  end
95
149
 
150
+ def styles
151
+ style_array = node['style'].to_s.
152
+ split(';').
153
+ reject { |s| s.strip.empty? }.
154
+ map do |s|
155
+ parts = s.split(':', 2)
156
+ return nil if parts.nil?
157
+ return nil if parts.length != 2
158
+ return nil if parts.any? { |s| s.nil? }
159
+ [parts[0].strip, parts[1].strip]
160
+ end.
161
+ reject { |s| s.empty? }
162
+ style_object = {}
163
+ style_array.each { |key, value| style_object[key] = value }
164
+
165
+ style_object
166
+ end
167
+
96
168
  def data key = false, value = false
97
169
  d = Hash[node.xpath("@*[starts-with(name(), 'data-')]").map{|a| [a.name, a.value]}]
98
170
 
@@ -101,29 +173,55 @@ class Wedge
101
173
  elsif key && !value
102
174
  d[key]
103
175
  else
104
- node["data-#{key}"] = value
176
+ key = "data-#{key}"
177
+
178
+ if node.is_a? Nokogiri::XML::NodeSet
179
+ node.each { |n| n[key] = value }
180
+ else
181
+ node[key] = value
182
+ end
105
183
  end
106
184
  end
107
185
 
108
186
  def val value
109
- node.content = value
187
+ if node.is_a? Nokogiri::XML::NodeSet
188
+ node.each { |n| n.content = value }
189
+ else
190
+ node.content = value
191
+ end
110
192
  end
111
193
 
112
194
  def add_class classes
113
195
  classes = (classes || '').split ' ' unless classes.is_a? Array
114
- new_classes = ((node.attr('class') || '').split(' ') << classes).uniq.join(' ')
115
- node['class'] = new_classes
196
+ if node.is_a? Nokogiri::XML::NodeSet
197
+ node.each do |n|
198
+ new_classes = ((n.attr('class') || '').split(' ') << classes).uniq.join(' ')
199
+ n['class'] = new_classes
200
+ end
201
+ else
202
+ new_classes = ((node.attr('class') || '').split(' ') << classes).uniq.join(' ')
203
+ node['class'] = new_classes
204
+ end
116
205
  end
117
206
 
118
207
  def remove_class classes
119
208
  classes = (classes || '').split ' ' unless classes.is_a? Array
120
- (node.attr('class') || '').split(' ').reject { |n| n =~ /active|asc|desc/i }.join(' ')
209
+
210
+ if node.is_a? Nokogiri::XML::NodeSet
211
+ node.each { |n| n['class'] = (n.attr('class') || '').split(' ').reject { |c| classes.include? c }.join(' ') }
212
+ else
213
+ node['class'] = (node.attr('class') || '').split(' ').reject { |c| classes.include? c }.join(' ')
214
+ end
121
215
  end
122
216
 
123
217
  def attr key, value = false
124
218
  if value
125
219
  value = value.join ' ' if value.is_a? Array
126
- node[key] = value
220
+ if node.is_a? Nokogiri::XML::NodeSet
221
+ node.each { |n| n[key] = value }
222
+ else
223
+ node[key] = value
224
+ end
127
225
  else
128
226
  super key
129
227
  end
@@ -132,13 +230,22 @@ class Wedge
132
230
 
133
231
  def html= content
134
232
  if server?
135
- node.inner_html = content
233
+ # if the value is nil nokogiri will not update the dom
234
+ content = '' if content.nil?
235
+
236
+ if node.is_a? Nokogiri::XML::NodeSet
237
+ node.each { |n| n.inner_html = content }
238
+ else
239
+ node.inner_html = content
240
+ end
136
241
  else
137
242
  content = content.dom if content.is_a? Wedge::DOM
138
243
  node.html content
139
244
  end
140
245
 
141
246
  node
247
+ rescue
248
+ binding.pry
142
249
  end
143
250
 
144
251
  if RUBY_ENGINE == 'opal'
@@ -159,6 +266,9 @@ class Wedge
159
266
  end
160
267
 
161
268
  def html content = false
269
+ # if the value is nil nokogiri will not update the dom
270
+ content = '' if content.nil?
271
+
162
272
  if !content
163
273
  if server?
164
274
  node.inner_html
@@ -18,7 +18,7 @@ class Wedge
18
18
  # Declares that the owner can perform `verb` on `class`.
19
19
  def can(verb, klass=nil, columns=[], &block)
20
20
  columns = [columns] unless columns.is_a? Array
21
- rules << [true, verb, get_class_name(klass), columns, block]
21
+ rules << [true, verb, get_class(klass), columns, block]
22
22
  end
23
23
 
24
24
  # Inverse of `can`.
@@ -71,12 +71,19 @@ class Wedge
71
71
  private
72
72
 
73
73
  def get_class_name(klass)
74
- [NilClass, Symbol].include?(klass.class) ? klass : klass.name
74
+ if !klass.is_a?(Symbol) && klass.method_defined?(:original_class_name)
75
+ klass.original_class_name
76
+ else
77
+ [NilClass, Symbol].include?(klass.class) ? klass : klass.name
78
+ end
75
79
  end
76
80
 
77
81
  def get_class(object)
78
- return object.class.original_class_name if object.class.method_defined?(:original_class_name)
79
- [NilClass, Symbol].include?(object.class) ? object : object.class.name
82
+ if object.class.method_defined?(:original_class)
83
+ object.class.original_class
84
+ else
85
+ [NilClass, Symbol, Class].include?(object.class) ? object : object.class
86
+ end
80
87
  end
81
88
  end
82
89
 
@@ -272,6 +272,8 @@ class Wedge
272
272
  end
273
273
 
274
274
  def _set_atts atts
275
+ return unless atts
276
+
275
277
  atts.each do |key, val|
276
278
  # grab the original key if alias is given
277
279
  _atts_keys << (key = _aliases.invert[key] || key)
@@ -52,8 +52,7 @@ if RUBY_ENGINE == 'opal'
52
52
  #
53
53
  # @param item [String] the item to push in the history
54
54
  # @param data [Object] additional state to push
55
- def push(item, data = nil)
56
- data = `null` if data.nil?
55
+ def push(item, data = {})
57
56
 
58
57
  `History.pushState(jQuery.parseJSON(data.$to_json()), null, item)`
59
58
  end
@@ -22,7 +22,7 @@ module Titleize
22
22
  title = title.downcase unless title[/[[:lower:]]/] # assume all-caps need fixing
23
23
 
24
24
  phrases(title).map do |phrase|
25
- words = phrase.split
25
+ words = phrase.gsub(/_/, ' ').split
26
26
  words.map do |word|
27
27
  def word.capitalize
28
28
  # like String#capitalize, but it starts with the first letter
data/lib/wedge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Wedge
2
- VERSION = '0.1.66'
2
+ VERSION = '0.1.67'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.66
4
+ version: 0.1.67
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal-wedge
@@ -264,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  requirements: []
266
266
  rubyforge_project:
267
- rubygems_version: 2.4.5.1
267
+ rubygems_version: 2.2.2
268
268
  signing_key:
269
269
  specification_version: 4
270
270
  summary: Components for the Browser and Server