shady 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/bin/shady +1 -1
- data/lib/shady.rb +34 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70205012b79f3a043f34e18cfa733f894080bbc0dd8d0eeea3b0e944de19ab12
|
|
4
|
+
data.tar.gz: 0a1bf355e711454d98167342f48ca710d92a11fe7194639c42897106c5c2d0e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d3f77023e247d31b238f13cd228b348aa81159dae8904746607b3bf22beaee69bdd70dffdc2de98e7d0a12ce5c6d3ab1e25d9cbdd6d0dd5b51301f86dba3314
|
|
7
|
+
data.tar.gz: 2ce5fa8802526df3c4a5786f49d84432e920795a34622ca19bdd067b37d3a86eb1ae38796e8f22bb5915031d5c26f7af86626ce32bd164223e8c35eea59d19ff
|
data/bin/shady
CHANGED
data/lib/shady.rb
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
# ==============================================================================
|
|
9
9
|
|
|
10
10
|
require "bindings"
|
|
11
|
+
require "json"
|
|
11
12
|
require "nokogiri"
|
|
12
13
|
require "slim"
|
|
13
14
|
|
|
@@ -162,6 +163,29 @@ module Slim
|
|
|
162
163
|
end
|
|
163
164
|
end
|
|
164
165
|
|
|
166
|
+
def hash_to_xml_builder(xml, hash)
|
|
167
|
+
hash.each do |key, value|
|
|
168
|
+
case value
|
|
169
|
+
when Hash
|
|
170
|
+
xml.send(key) { hash_to_xml_builder(xml, value) }
|
|
171
|
+
when Array
|
|
172
|
+
value.each do |v|
|
|
173
|
+
xml.send(key) do
|
|
174
|
+
v.is_a?(Hash) ? hash_to_xml_builder(xml, v) : xml.text(v)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
else
|
|
178
|
+
xml.send(key, value)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def hash_to_xml(hash, root='root')
|
|
184
|
+
Nokogiri::XML::Builder.new do |xml|
|
|
185
|
+
xml.send(root) { hash_to_xml_builder(xml, hash) }
|
|
186
|
+
end.to_xml
|
|
187
|
+
end
|
|
188
|
+
|
|
165
189
|
class String
|
|
166
190
|
def slim(scope=nil)
|
|
167
191
|
Slim::Template.new(pretty: true, strip: true, format: :xml) { self }.result
|
|
@@ -178,6 +202,16 @@ class String
|
|
|
178
202
|
def xml_to_xml
|
|
179
203
|
Nokogiri.XML(self) {|o| o.default_xml.noblanks}.to_xml(indent:2) rescue self
|
|
180
204
|
end
|
|
205
|
+
|
|
206
|
+
def json_to_xml(root='root')
|
|
207
|
+
hash = JSON.parse(self)
|
|
208
|
+
hash_to_xml(hash)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def json_to_slim(root='root')
|
|
212
|
+
json_to_xml(root).xml_to_slim
|
|
213
|
+
end
|
|
214
|
+
|
|
181
215
|
end
|
|
182
216
|
|
|
183
217
|
def slim(str="")
|