nom-xml 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Nom::XML
|
|
22
22
|
|
23
23
|
def set_terminology options = {}, &block
|
24
24
|
@terminology_namespaces = options[:namespaces]
|
25
|
-
@terminology = Nom::XML::Terminology.new(options, &block)
|
25
|
+
@terminology = Nom::XML::Terminology.new(self, options, &block)
|
26
26
|
end
|
27
27
|
|
28
28
|
def terminology_namespaces
|
@@ -30,7 +30,7 @@ module Nom::XML
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def terminology
|
33
|
-
@terminology ||= Nom::XML::Terminology.new
|
33
|
+
@terminology ||= Nom::XML::Terminology.new self
|
34
34
|
end
|
35
35
|
|
36
36
|
def template_registry
|
data/lib/nom/xml/term.rb
CHANGED
@@ -47,6 +47,10 @@ module Nom::XML
|
|
47
47
|
(options[:xmlns] if options) || (self.parent.xmlns if self.parent)
|
48
48
|
end
|
49
49
|
|
50
|
+
def nodes
|
51
|
+
terminology.document.root.xpath(xpath, terminology.namespaces)
|
52
|
+
end
|
53
|
+
|
50
54
|
def method_missing method, *args, &block
|
51
55
|
if in_edit_context?
|
52
56
|
add_term(method, *args, &block)
|
@@ -65,6 +69,10 @@ module Nom::XML
|
|
65
69
|
[self, terms.map { |k,v| v.flatten }].flatten
|
66
70
|
end
|
67
71
|
|
72
|
+
def terminology
|
73
|
+
@terminology ||= parent.terminology
|
74
|
+
end
|
75
|
+
|
68
76
|
protected
|
69
77
|
def add_term method, options = {}, *args, &block
|
70
78
|
terms[method] = Term.new(self, method, options, *args, &block)
|
@@ -73,6 +81,7 @@ module Nom::XML
|
|
73
81
|
def term method, *args, &block
|
74
82
|
terms[method]
|
75
83
|
end
|
84
|
+
|
76
85
|
end
|
77
86
|
|
78
87
|
end
|
data/lib/nom/xml/terminology.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Nom::XML
|
2
2
|
class Terminology < Term
|
3
|
+
attr_reader :document
|
3
4
|
|
4
|
-
def initialize options = {}, *args, &block
|
5
|
+
def initialize document = nil, options = {}, *args, &block
|
5
6
|
@terms = {}
|
6
7
|
@options = options || {}
|
8
|
+
@document = document
|
7
9
|
in_edit_context do
|
8
10
|
yield(self) if block_given?
|
9
11
|
end
|
@@ -13,6 +15,10 @@ module Nom::XML
|
|
13
15
|
options[:namespaces] || {}
|
14
16
|
end
|
15
17
|
|
18
|
+
def terminology
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
16
22
|
def xpath
|
17
23
|
nil
|
18
24
|
end
|
data/lib/nom/xml/version.rb
CHANGED
@@ -83,11 +83,12 @@ describe "Namespaces example" do
|
|
83
83
|
it "should let you go from a terminology to nodes" do
|
84
84
|
subject.terminology.flatten.length.should == 10
|
85
85
|
|
86
|
-
subject.terminology.flatten.select { |x| x.options[:index_as] }.
|
86
|
+
subject.terminology.flatten.select { |x| x.options[:index_as] }.should have(2).terms
|
87
|
+
subject.terminology.flatten.select { |x| x.options[:index_as] }.map { |x| x.nodes }.flatten.should have(2).nodes
|
88
|
+
end
|
87
89
|
|
88
|
-
|
89
|
-
|
90
|
-
end
|
90
|
+
it "should let you go from a term to a terminology" do
|
91
|
+
subject.personal_authors.terms.first.terminology.should == subject.terminology
|
91
92
|
end
|
92
93
|
|
93
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nom-xml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
174
|
version: '0'
|
175
175
|
segments:
|
176
176
|
- 0
|
177
|
-
hash:
|
177
|
+
hash: -3784330826546141673
|
178
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
179
|
none: false
|
180
180
|
requirements:
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
segments:
|
185
185
|
- 0
|
186
|
-
hash:
|
186
|
+
hash: -3784330826546141673
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
189
|
rubygems_version: 1.8.23
|