weby 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/weby/html.rb +64 -13
- data/lib/weby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7aa19679d1630d8ce0ee9a635451145c3a5fd3d
|
4
|
+
data.tar.gz: 647a37fc0b7fb704da6674040b14688e79ab404e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12320e6364fd881ad0749c900dfadf67bf98dd4177ed61895b81b1d0ce6f108e47b9a03163a02f80e6ff71db0a375cf41d357350fe4e5cd166df719db84511d7
|
7
|
+
data.tar.gz: 02c2b6676ca7316ab7bff7bd6de4e88853357a6f8a89fa6a5ffeaa15a2090bf23d4a3aea5694c1cc7f197b1c1275a247afef2c0f20cb497ad2b523c2b4f10479
|
data/lib/weby/html.rb
CHANGED
@@ -7,6 +7,15 @@ module Weby
|
|
7
7
|
|
8
8
|
attr_accessor :node, :nodeset, :document
|
9
9
|
|
10
|
+
%w(ancestors attributes name name= css_path matches?).each{|m|
|
11
|
+
_method = :"#{m}"
|
12
|
+
define_method _method do |*args|
|
13
|
+
if @node
|
14
|
+
@node.send _method, *args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
10
19
|
@@prefix = 'wby'
|
11
20
|
@@evaluation_instance = nil
|
12
21
|
@@evaluation_binding = TOPLEVEL_BINDING
|
@@ -149,6 +158,14 @@ module Weby
|
|
149
158
|
end
|
150
159
|
|
151
160
|
def each(&block)
|
161
|
+
(@nodeset || [@node]).each{|_node|
|
162
|
+
next if !_node
|
163
|
+
element = self.class.new _node
|
164
|
+
yield element
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
def each_node(&block)
|
152
169
|
(@nodeset || [@node]).each &block
|
153
170
|
end
|
154
171
|
|
@@ -169,9 +186,25 @@ module Weby
|
|
169
186
|
def []=(attr, val)
|
170
187
|
if @node
|
171
188
|
@node[attr] = val
|
189
|
+
elsif @nodeset
|
190
|
+
@nodeset.each{|_node|
|
191
|
+
_node[attr] = val
|
192
|
+
}
|
172
193
|
end
|
173
194
|
end
|
174
195
|
|
196
|
+
def text
|
197
|
+
return '' if !@node
|
198
|
+
node.content
|
199
|
+
end
|
200
|
+
|
201
|
+
def text=(txt)
|
202
|
+
@node.content = txt if @node
|
203
|
+
end
|
204
|
+
|
205
|
+
alias_method :content, :text
|
206
|
+
alias_method :content=, :text=
|
207
|
+
|
175
208
|
def inner_html
|
176
209
|
return '' if !@node
|
177
210
|
@node.inner_html
|
@@ -200,30 +233,44 @@ module Weby
|
|
200
233
|
argl = args.length
|
201
234
|
_node = @node || {}
|
202
235
|
css = (_node['style']) || ''
|
203
|
-
|
204
|
-
|
236
|
+
if argl.zero?
|
237
|
+
hash = parse_css css
|
238
|
+
return hash
|
239
|
+
end
|
205
240
|
if argl == 1
|
206
241
|
arg = args[0]
|
207
242
|
if hashlike? arg
|
208
243
|
return if !@node
|
209
|
-
|
210
|
-
|
244
|
+
(@nodeset || [@node]).each{|n|
|
245
|
+
next if !n
|
246
|
+
css = (n['style']) || ''
|
247
|
+
hash = parse_css css
|
248
|
+
arg.each{|prop, val|
|
249
|
+
hash[prop] = val
|
250
|
+
}
|
251
|
+
n['style'] = hash_to_css(hash)
|
211
252
|
}
|
212
|
-
@node['style'] = hash_to_css(hash)
|
213
253
|
return self
|
214
254
|
else
|
255
|
+
hash = parse_css css
|
215
256
|
return hash[arg.to_s]
|
216
257
|
end
|
217
258
|
else
|
218
259
|
prop, val = args
|
219
|
-
|
220
|
-
|
260
|
+
(@nodeset || [@node]).each{|n|
|
261
|
+
next if !n
|
262
|
+
css = (n['style']) || ''
|
263
|
+
hash = parse_css css
|
264
|
+
hash[prop] = val
|
265
|
+
n['style'] = hash_to_css(hash)
|
266
|
+
}
|
221
267
|
return self
|
222
268
|
end
|
223
269
|
end
|
224
270
|
|
225
271
|
def hide
|
226
272
|
(@nodeset || [@node]).each{|n|
|
273
|
+
next if !n
|
227
274
|
css = n['style'] || ''
|
228
275
|
hash = parse_css css
|
229
276
|
hash['display'] = 'none'
|
@@ -245,9 +292,12 @@ module Weby
|
|
245
292
|
elsif argl == 1
|
246
293
|
arg = args[0]
|
247
294
|
if hashlike?(arg)
|
248
|
-
|
249
|
-
|
250
|
-
|
295
|
+
(@nodeset || [@node]).each{|n|
|
296
|
+
next if !n
|
297
|
+
arg.each{|name, val|
|
298
|
+
n["data-#{name}"] = val
|
299
|
+
}
|
300
|
+
}
|
251
301
|
self
|
252
302
|
else
|
253
303
|
return nil if !@node
|
@@ -255,9 +305,10 @@ module Weby
|
|
255
305
|
end
|
256
306
|
else
|
257
307
|
name, val = args
|
258
|
-
|
259
|
-
|
260
|
-
|
308
|
+
(@nodeset || [@node]).each{|n|
|
309
|
+
next if !n
|
310
|
+
n["data-#{name}"] = val
|
311
|
+
}
|
261
312
|
self
|
262
313
|
end
|
263
314
|
end
|
data/lib/weby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- artix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|