translate-rails3-plus 0.0.13 → 0.0.14
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/lib/translate/file.rb +39 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c043e84b415c650f3dfef85e24b3168eec5a52b
|
4
|
+
data.tar.gz: 9c517e1544f964b3c587b63e62f2a6527b5fa2c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15858ad7c7b9df6802162e8810bae29b75651967f99f25112574576d1adcc4c8f6d7a7c33d5c0f575f65fd3aff9ea1dadfb109fded1b49cf6df5a14ce64b4741
|
7
|
+
data.tar.gz: a34d3807117ae17b051f829f757c7e2cb5a3304e3bfae63de68bf2696ddacc8a5827334501441c37a6b16a2eb29a0bcab9c55902a4d9816bfdfeb80e7b6ae6ca
|
data/lib/translate/file.rb
CHANGED
@@ -9,8 +9,9 @@ class Translate::File
|
|
9
9
|
|
10
10
|
def write(keys)
|
11
11
|
FileUtils.mkdir_p File.dirname(path)
|
12
|
-
File.
|
13
|
-
|
12
|
+
yml_keys = keys_to_yaml( Translate::File.deep_stringify_keys(keys) )
|
13
|
+
File.open(path, "w") do |file|
|
14
|
+
file.write yml_keys
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -28,8 +29,41 @@ class Translate::File
|
|
28
29
|
end
|
29
30
|
|
30
31
|
private
|
32
|
+
|
31
33
|
def keys_to_yaml(keys)
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
|
35
|
+
yaml = YAML.dump(keys)
|
36
|
+
|
37
|
+
ast = Psych.parse_stream yaml
|
38
|
+
|
39
|
+
# First pass, quote everything
|
40
|
+
ast.grep(Psych::Nodes::Scalar).each do |node|
|
41
|
+
node.plain = false
|
42
|
+
node.quoted = true
|
43
|
+
node.style = Psych::Nodes::Scalar::DOUBLE_QUOTED
|
44
|
+
end
|
45
|
+
|
46
|
+
# Second pass, unquote keys, bools and ints
|
47
|
+
ast.grep(Psych::Nodes::Mapping).each do |node|
|
48
|
+
node.children.each_slice(2) do |k, v|
|
49
|
+
k.plain = true
|
50
|
+
k.quoted = false
|
51
|
+
k.style = Psych::Nodes::Scalar::ANY
|
52
|
+
|
53
|
+
if v.to_ruby.to_s == v.to_ruby.to_s.to_i.to_s
|
54
|
+
v.plain = true
|
55
|
+
v.quoted = false
|
56
|
+
v.style = Psych::Nodes::Scalar::ANY
|
57
|
+
end
|
58
|
+
|
59
|
+
if v.to_ruby.to_s == "true" || v.to_ruby.to_s == "false"
|
60
|
+
v.plain = true
|
61
|
+
v.quoted = false
|
62
|
+
v.style = Psych::Nodes::Scalar::ANY
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
ast.yaml( nil, line_width: -1 )
|
68
|
+
end
|
35
69
|
end
|