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 +4 -4
- data/lib/wedge/dom.rb +152 -42
- data/lib/wedge/plugins/ability_list.rb +11 -4
- data/lib/wedge/plugins/form.rb +2 -0
- data/lib/wedge/plugins/history.rb +1 -2
- data/lib/wedge/utilis/titleize.rb +1 -1
- data/lib/wedge/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f648b76e8e443e40be3a210bb3ba8dd3f960dd1
|
4
|
+
data.tar.gz: 8aefe262e6c7b0c182ad403658ade6d46217069e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
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
|
-
|
136
|
+
node
|
84
137
|
end
|
85
138
|
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
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
|
-
|
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.
|
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
|
-
|
115
|
-
|
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
|
-
|
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
|
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
|
-
|
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,
|
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
|
-
|
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
|
-
|
79
|
-
|
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
|
|
data/lib/wedge/plugins/form.rb
CHANGED
@@ -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 =
|
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
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.
|
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-
|
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.
|
267
|
+
rubygems_version: 2.2.2
|
268
268
|
signing_key:
|
269
269
|
specification_version: 4
|
270
270
|
summary: Components for the Browser and Server
|