nakajima-elementor 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/elementor/result.rb +18 -6
- metadata +1 -1
data/lib/elementor/result.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Elementor
|
2
2
|
class Result
|
3
|
+
attr_writer :doc_ready
|
3
4
|
attr_reader :context, :opts
|
4
5
|
|
5
6
|
def initialize(context, opts={}, &block)
|
6
7
|
@opts = opts
|
7
8
|
@context = context
|
9
|
+
@doc_ready = false
|
8
10
|
block.call(naming_context)
|
9
11
|
end
|
10
12
|
|
@@ -21,9 +23,10 @@ module Elementor
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def dispatcher
|
24
|
-
@dispatcher ||= blank_context(:this => self
|
26
|
+
@dispatcher ||= blank_context(:this => self) do
|
25
27
|
def method_missing(sym, *args, &block)
|
26
|
-
@this.
|
28
|
+
@this.doc_ready = true
|
29
|
+
@this.try(sym, *args, &block) || @this.doc.try(sym, *args, &block) || super
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
@@ -41,11 +44,20 @@ module Elementor
|
|
41
44
|
@element_names ||= { }
|
42
45
|
end
|
43
46
|
|
44
|
-
private
|
45
|
-
|
46
47
|
def doc(markup=nil)
|
47
|
-
|
48
|
-
|
48
|
+
if html = markup || content
|
49
|
+
@doc = nil if markup
|
50
|
+
@doc ||= Nokogiri(html)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def content
|
55
|
+
return unless doc_ready?
|
56
|
+
@content ||= context.send(opts[:from] || :body)
|
57
|
+
end
|
58
|
+
|
59
|
+
def doc_ready?
|
60
|
+
@doc_ready
|
49
61
|
end
|
50
62
|
end
|
51
63
|
end
|