datagnan 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datagnan.rb +15 -12
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4abc2c60f6c8ae2c9080a8304ab25feec4aa8eb1
|
4
|
+
data.tar.gz: 69b188a1ff8ef210349a10d3f96d0c1ee15091dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dad826a6a3a5f9571de819e2b2f0558ca745e25f0da031099a393e633aff5111aedb41961cdf8ff91ee1c187749c757de93cdcec9d2eadf502336ac8e17389e8
|
7
|
+
data.tar.gz: 05ca6420a97a40d88dba20c5c5e8d8d41e404e1577268c332aabf71da242f28479d28ddaac6359760630f44c4357b82358cd6d5c84f649354d7836408abdd6c8
|
data/lib/datagnan.rb
CHANGED
@@ -47,7 +47,7 @@ class Datagnan
|
|
47
47
|
vars = @vars if vars.is_a?(Hash) && vars.empty?
|
48
48
|
root = @doc if root.nil?
|
49
49
|
## debug
|
50
|
-
# puts "-- Datagnan.write ( vars = #{vars} )"
|
50
|
+
# puts "-- Datagnan.write ( vars = #{vars.inspect} )"
|
51
51
|
# puts "-- Datagnan.write ( root = #{root.to_xml} )"
|
52
52
|
## replace data-each
|
53
53
|
data_each(vars, root)
|
@@ -60,7 +60,7 @@ class Datagnan
|
|
60
60
|
# puts "-- Datagnan.write after when ( vars = #{vars} )"
|
61
61
|
# puts "-- Datagnan.write after when ( root = #{root.to_xml} )"
|
62
62
|
## replace data-var
|
63
|
-
|
63
|
+
data_var(vars, root)
|
64
64
|
## debug
|
65
65
|
# puts "Datagnan.write after vars ( vars = #{vars} )"
|
66
66
|
# puts "Datagnan.write after vars ( root = #{root.to_xml} )"
|
@@ -76,21 +76,21 @@ class Datagnan
|
|
76
76
|
private
|
77
77
|
|
78
78
|
## node content
|
79
|
-
def
|
79
|
+
def data_var(vars, root)
|
80
80
|
## debug
|
81
|
-
# puts "Datagnan.
|
82
|
-
# puts "Datagnan.
|
81
|
+
# puts "-- Datagnan.data_var ( vars = #{vars} )"
|
82
|
+
# puts "-- Datagnan.data_var ( root.to_xml = #{root.to_xml} )"
|
83
83
|
root.css('*[data-var]').each do |node|
|
84
84
|
## recursive access to property
|
85
85
|
## debug
|
86
|
-
# puts "-- Datagnan.
|
87
|
-
# puts "-- Datagnan.
|
86
|
+
# puts "-- Datagnan.data_var each ( vars = #{vars} )"
|
87
|
+
# puts "-- Datagnan.data_var each ( node.to_xml = #{node.to_xml} )"
|
88
88
|
var = vars
|
89
89
|
node.get('data-var').split('.').each do |key|
|
90
90
|
## var exist
|
91
91
|
var = ( var.is_a?(Hash) ? var[key] : (var.respond_to?(key) ? var.send(key) : nil ) )
|
92
92
|
end
|
93
|
-
# puts "-- Datagnan.
|
93
|
+
# puts "-- Datagnan.data_var each ( var = #{var} )"
|
94
94
|
|
95
95
|
unless var.nil?
|
96
96
|
node.children = Oga.parse_html(var.to_s).children
|
@@ -99,7 +99,7 @@ private
|
|
99
99
|
## TODO: if var not exist remember it (maybe return to model)
|
100
100
|
end
|
101
101
|
## debug
|
102
|
-
# puts "Datagnan.
|
102
|
+
# puts "Datagnan.data_var end ( root = #{root} )"
|
103
103
|
end
|
104
104
|
|
105
105
|
## node attributes
|
@@ -125,7 +125,10 @@ private
|
|
125
125
|
end
|
126
126
|
# puts "-- Datagnan.data_attrs each ( var = #{var} )"
|
127
127
|
unless var.nil?
|
128
|
-
node.
|
128
|
+
node.attributes.insert(
|
129
|
+
node.attributes.index(node.attribute('data-attrs')),
|
130
|
+
Oga::XML::Attribute.new(:name => key, :value => var.to_s)
|
131
|
+
)
|
129
132
|
end
|
130
133
|
# puts "-- Datagnan.data_attrs each ( node.to_xml = #{node.to_xml} )"
|
131
134
|
## TODO: if attr not exist remember it (maybe return to model)
|
@@ -156,7 +159,7 @@ private
|
|
156
159
|
var.each do |item|
|
157
160
|
# puts "-- Datagnan.data_each each ( item = #{item} )"
|
158
161
|
# puts "-- Datagnan.data_each each ( item.inspect = #{item.inspect} )"
|
159
|
-
new_node = Oga.parse_html(node.to_xml)
|
162
|
+
new_node = Oga.parse_html(node.to_xml)
|
160
163
|
# puts "-- Datagnan.data_each each ( node after clone = #{node} )"
|
161
164
|
# puts "-- Datagnan.data_each each ( node.to_xml after clone = #{node.to_xml} )"
|
162
165
|
# puts "-- Datagnan.data_each each ( node.parent.to_xml = #{node.parent.to_xml} )"
|
@@ -167,7 +170,7 @@ private
|
|
167
170
|
# puts "-- Datagnan.data_each each ( new_node.to_xml after write = #{new_node.to_xml} )"
|
168
171
|
# puts "-- Datagnan.data_each each ( node after write= #{node} )"
|
169
172
|
# puts "-- Datagnan.data_each each ( node.to_xml after write= #{node.to_xml} )"
|
170
|
-
node.before(new_node)
|
173
|
+
node.before(new_node.children.pop)
|
171
174
|
# puts "-- Datagnan.data_each each ( node = #{node} )"
|
172
175
|
# puts "-- Datagnan.data_each each ( node.to_xml after insert = #{node.to_xml} )"
|
173
176
|
# puts "-- Datagnan.data_each each ( node.parent = #{node.parent.to_xml} )"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagnan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oga
|
@@ -25,7 +25,8 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
|
-
description:
|
28
|
+
description: HTML-templates engine, without specific (often ugly) tags. Based on 'data-'
|
29
|
+
attributes.
|
29
30
|
email: alex.wayfer@gmail.com
|
30
31
|
executables: []
|
31
32
|
extensions: []
|