dataisland 0.1.7 → 0.1.8
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.
- data/lib/dataisland.rb +58 -30
- metadata +2 -2
data/lib/dataisland.rb
CHANGED
@@ -11,7 +11,7 @@ class DataIsland
|
|
11
11
|
|
12
12
|
attr_reader :html_doc
|
13
13
|
|
14
|
-
# e.g. url = 'http://jamesrobertson.eu/index.html'
|
14
|
+
# e.g. url = 'http://jamesrobertson.eu/index-template.html'
|
15
15
|
#
|
16
16
|
def initialize(location)
|
17
17
|
|
@@ -77,6 +77,11 @@ class DataIsland
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
def add_to_destnodes(dn, raw_key, node)
|
81
|
+
key = raw_key.to_sym
|
82
|
+
dn.has_key?(key) ? dn[key] << node : dn[key] = [node]
|
83
|
+
end
|
84
|
+
|
80
85
|
def render(flat_records, h, node)
|
81
86
|
|
82
87
|
sort_by = h[:sort_by]
|
@@ -86,8 +91,6 @@ class DataIsland
|
|
86
91
|
|
87
92
|
if rec_orig then
|
88
93
|
|
89
|
-
# get a reference to each element containing the datafld attribute
|
90
|
-
dest_nodes = {}
|
91
94
|
|
92
95
|
if (h[:rows_per_page]) then
|
93
96
|
|
@@ -113,52 +116,77 @@ class DataIsland
|
|
113
116
|
recs.each do |record|
|
114
117
|
|
115
118
|
rec = rec_orig.deep_clone
|
119
|
+
|
120
|
+
# get a reference to each element containing the datafld attribute
|
121
|
+
dest_nodes = {}
|
122
|
+
|
116
123
|
a = rec.xpath('.//span[@class]|.//a[@class]')
|
117
124
|
a.each do |e|
|
118
125
|
r = e.attribute(:class)[/\{([^\}]+)\}$/,1]
|
119
|
-
dest_nodes
|
126
|
+
add_to_destnodes(dest_nodes,r,e) if r
|
120
127
|
end
|
121
128
|
|
122
129
|
rec.xpath('.//*[@datafld]').each do |e|
|
123
|
-
dest_nodes
|
130
|
+
add_to_destnodes(dest_nodes,e.attribute(:datafld).downcase,e)
|
124
131
|
end
|
132
|
+
|
133
|
+
a = rec.xpath('.//a[@href]')
|
134
|
+
|
135
|
+
a.each do |e|
|
136
|
+
r = e.attribute(:href)[/\{([^\}]+)\}/,1]
|
137
|
+
add_to_destnodes(dest_nodes,r,e) if r
|
138
|
+
end
|
125
139
|
|
126
140
|
dest_nodes.keys.each do |raw_field|
|
127
141
|
|
128
142
|
field = raw_field.to_sym
|
129
143
|
next if record[field].nil?
|
130
|
-
|
131
|
-
|
144
|
+
|
145
|
+
dest_nodes[field].each do |e2|
|
132
146
|
|
133
|
-
|
147
|
+
case e2.name.downcase.to_sym
|
148
|
+
|
149
|
+
when :span
|
150
|
+
|
151
|
+
classx = e2.attributes[:class]
|
152
|
+
|
153
|
+
if classx then
|
154
|
+
|
155
|
+
if classx[/{#{field}/] then
|
156
|
+
val = record[field]
|
157
|
+
new_class = classx.sub(/\{[^\}]+\}/,val)
|
158
|
+
e2.attributes[:class] = new_class
|
159
|
+
elsif
|
160
|
+
e2.text = record[field]
|
161
|
+
end
|
162
|
+
elsif
|
163
|
+
e2.text = record[field]
|
164
|
+
end
|
165
|
+
|
166
|
+
when :a
|
134
167
|
|
135
|
-
|
168
|
+
classx = e2.attributes[:class]
|
136
169
|
|
137
|
-
|
170
|
+
if classx and classx[/{#{field}/] then
|
138
171
|
|
139
|
-
if classx[/{#{field}/] then
|
140
172
|
val = record[field]
|
141
173
|
new_class = classx.sub(/\{[^\}]+\}/,val)
|
142
|
-
|
143
|
-
elsif
|
144
|
-
dest_nodes[field].text = record[field]
|
174
|
+
e2.attributes[:class] = new_class
|
145
175
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
when :img
|
161
|
-
dest_nodes[field].attributes[:src] = record[field]
|
176
|
+
|
177
|
+
href = e2.attributes[:href]
|
178
|
+
|
179
|
+
if href then
|
180
|
+
|
181
|
+
val = record[field]
|
182
|
+
new_href = href.sub(/\{[^\}]+\}/,val)
|
183
|
+
e2.attributes[:href] = new_href
|
184
|
+
end
|
185
|
+
|
186
|
+
when :img
|
187
|
+
e2.attributes[:src] = record[field]
|
188
|
+
end
|
189
|
+
|
162
190
|
end
|
163
191
|
end
|
164
192
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dataisland
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: dynarex
|