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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/weby/html.rb +64 -13
  3. data/lib/weby/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c28a1a8448a3196261c4e6240b7ef6fa930d23ea
4
- data.tar.gz: 0ab14325c0b214ba72c24675dd2c41c59c6ac969
3
+ metadata.gz: a7aa19679d1630d8ce0ee9a635451145c3a5fd3d
4
+ data.tar.gz: 647a37fc0b7fb704da6674040b14688e79ab404e
5
5
  SHA512:
6
- metadata.gz: '09689b71c8f4194e6b91620a3ddd72835b050227f16ad0271d0ec694cc5d30ce92a1f6fd61bc71f31b40cfd2e19123f8520e768c2d1955a7f29af82fd3153c6c'
7
- data.tar.gz: 59dc3818e66eea93f462b5ae8fa67e7d34ee201088339b4c70e5c189bb3f3e4443dcdf33065f9035217b849efde45455a605879e7aeb03f753d5a7605f557924
6
+ metadata.gz: 12320e6364fd881ad0749c900dfadf67bf98dd4177ed61895b81b1d0ce6f108e47b9a03163a02f80e6ff71db0a375cf41d357350fe4e5cd166df719db84511d7
7
+ data.tar.gz: 02c2b6676ca7316ab7bff7bd6de4e88853357a6f8a89fa6a5ffeaa15a2090bf23d4a3aea5694c1cc7f197b1c1275a247afef2c0f20cb497ad2b523c2b4f10479
@@ -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
- hash = parse_css css
204
- return hash if argl.zero?
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
- arg.each{|prop, val|
210
- hash[prop] = val
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
- hash[prop] = val
220
- @node['style'] = hash_to_css(hash)
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
- arg.each{|name, val|
249
- @node["data-#{name}"] = val
250
- } if @node
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
- if @node
259
- @node["data-#{name}"] = val
260
- end
308
+ (@nodeset || [@node]).each{|n|
309
+ next if !n
310
+ n["data-#{name}"] = val
311
+ }
261
312
  self
262
313
  end
263
314
  end
@@ -1,3 +1,3 @@
1
1
  module Weby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-07-20 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler