nakajima-elementor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,40 @@
1
1
  module Elementor
2
+
3
+ module NodeSet
4
+ def self.included(base)
5
+ base.class_eval do
6
+ attr_accessor :node_set
7
+ end
8
+ end
9
+
10
+ def initialize(document, array)
11
+ @node_set = Nokogiri::XML::NodeSet.new(document, array)
12
+ end
13
+
14
+ def length
15
+ node_set.length
16
+ end
17
+ alias_method :size, :length
18
+
19
+ def select(&block)
20
+ @node_set.select &block
21
+ end
22
+
23
+ def replace(array)
24
+ @node_set = Nokogiri::XML::NodeSet.new(@node_set.document, array)
25
+ end
26
+
27
+ def search(selector)
28
+ @node_set.search(selector)
29
+ end
30
+ end
31
+
2
32
  # ElementSet objects wrap a Nokogiri #search result and
3
33
  # add additional functionality such as chained filtering.
4
- class ElementSet < Array
34
+ class ElementSet
35
+
36
+ include NodeSet
37
+
5
38
  attr_accessor :result, :selector
6
39
 
7
40
  # A simple filter for selecting only elements with content
@@ -34,7 +67,7 @@ module Elementor
34
67
  alias_method :attrs, :with_attrs
35
68
 
36
69
  def method_missing(sym, *args, &block)
37
- result.respond_to?(sym) ? result.send(sym, doc, *args) : super
70
+ result.respond_to?(sym) ? result.send(sym, self, *args) : super
38
71
  end
39
72
 
40
73
  def respond_to?(sym)
@@ -51,4 +84,4 @@ module Elementor
51
84
  replace(select(&block)) ; return self
52
85
  end
53
86
  end
54
- end
87
+ end
@@ -81,7 +81,7 @@ module Elementor
81
81
  end
82
82
 
83
83
  def make_element_set(name, selector, *filters, &block)
84
- set = ElementSet.new scope(filters).search(selector)
84
+ set = ElementSet.new(doc, scope(filters).search(selector))
85
85
  set.result = self
86
86
  set.selector = selector
87
87
  set = filters.empty? ? set : filters.inject(set) { |result, fn| fn[result] }
@@ -101,4 +101,4 @@ module Elementor
101
101
  @content ||= context.send(opts[:from] || :body)
102
102
  end
103
103
  end
104
- end
104
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nakajima-elementor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima