dslh 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -0
- data/lib/dslh.rb +12 -7
- data/lib/dslh/version.rb +1 -1
- data/spec/dslh_spec.rb +51 -0
- 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: eaa7072cea6f58fcbe9e341e3cfe3e6569ac7754
|
4
|
+
data.tar.gz: 9c35be524118f1a0a53ddf349688fdf6780cdeb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32898eaf5f6a60ce2eaa6c5e2e87a07e80ac389c6a62b163cd947fc3be03fc8797195c4770c5f93479d909020dbe6db635f10b715cfe725a92405a924fca5e5a
|
7
|
+
data.tar.gz: 86d4481731ac1549e55bd1d803dffe825258c7dcb590ffcc844f98aa38f27ad8111d4fadd558a2eafd80af0a480e3fdc0af4505123545eeaa8f278434c020de6
|
data/README.md
CHANGED
@@ -153,3 +153,47 @@ pp h
|
|
153
153
|
# {"title"=>"example glossary",
|
154
154
|
# "date"=>'2016-05-21 00:00:00 UTC'}]}
|
155
155
|
```
|
156
|
+
|
157
|
+
### Use braces
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
h = {"glossary"=>
|
161
|
+
{"title"=>"example glossary",
|
162
|
+
"GlossDiv"=>
|
163
|
+
{"title"=>"S",
|
164
|
+
"GlossList"=>
|
165
|
+
{"GlossEntry"=>
|
166
|
+
{"ID"=>"SGML",
|
167
|
+
"SortAs"=>"SGML",
|
168
|
+
"GlossTerm"=>"Standard Generalized Markup Language",
|
169
|
+
"Acronym"=>"SGML",
|
170
|
+
"Abbrev"=>"ISO 8879:1986",
|
171
|
+
"GlossDef"=>
|
172
|
+
{"para"=>
|
173
|
+
"A meta-markup language, used to create markup languages such as DocBook.",
|
174
|
+
"GlossSeeAlso"=>["GML", "XML"]},
|
175
|
+
"GlossSee"=>"markup"}}}}}
|
176
|
+
|
177
|
+
dsl = Dslh.deval(h, :use_braces_instead_of_do_end => true)
|
178
|
+
puts dsl
|
179
|
+
#=> glossary {
|
180
|
+
# title "example glossary"
|
181
|
+
# GlossDiv {
|
182
|
+
# title "S"
|
183
|
+
# GlossList {
|
184
|
+
# GlossEntry {
|
185
|
+
# ID "SGML"
|
186
|
+
# SortAs "SGML"
|
187
|
+
# GlossTerm "Standard Generalized Markup Language"
|
188
|
+
# Acronym "SGML"
|
189
|
+
# Abbrev "ISO 8879:1986"
|
190
|
+
# GlossDef {
|
191
|
+
# para "A meta-markup language, used to create markup languages such as DocBook."
|
192
|
+
# GlossSeeAlso "GML", "XML"
|
193
|
+
# }
|
194
|
+
# GlossSee "markup"
|
195
|
+
# }
|
196
|
+
# }
|
197
|
+
# }
|
198
|
+
# }
|
199
|
+
```
|
data/lib/dslh.rb
CHANGED
@@ -41,7 +41,8 @@ class Dslh
|
|
41
41
|
@options = {
|
42
42
|
:time_inspecter => method(:inspect_time),
|
43
43
|
:dump_old_hash_array_format => false,
|
44
|
-
:force_dump_braces => false
|
44
|
+
:force_dump_braces => false,
|
45
|
+
:use_braces_instead_of_do_end => false,
|
45
46
|
}.merge(options)
|
46
47
|
|
47
48
|
@options[:key_conv] ||= (@options[:conv] || proc {|i| i.to_s })
|
@@ -137,29 +138,33 @@ class Dslh
|
|
137
138
|
value_buf.puts('(' + ("\n" + value.pretty_inspect.strip).gsub("\n", "\n" + next_indent) + ')')
|
138
139
|
else
|
139
140
|
nested = true
|
140
|
-
value_buf.puts(' do')
|
141
|
+
value_buf.puts(@options[:use_braces_instead_of_do_end] ? ' {' : ' do')
|
141
142
|
deval0(value, depth + 1, value_buf)
|
142
|
-
value_buf.puts(indent + 'end')
|
143
|
+
value_buf.puts(indent + (@options[:use_braces_instead_of_do_end] ? '}' : 'end'))
|
143
144
|
end
|
144
145
|
when Array
|
145
146
|
if value.any? {|v| [Array, Hash].any? {|c| v.kind_of?(c) }}
|
146
147
|
nested = true
|
147
148
|
|
148
149
|
if not @options[:dump_old_hash_array_format] and value.all? {|i| i.kind_of?(Hash) }
|
149
|
-
value_buf.puts(' do |*|')
|
150
|
+
value_buf.puts(@options[:use_braces_instead_of_do_end] ? ' {|*|' : ' do |*|')
|
150
151
|
|
151
152
|
value.each_with_index do |v, i|
|
152
153
|
deval0(v, depth + 1, value_buf)
|
153
154
|
|
154
155
|
if i < (value.length - 1)
|
155
|
-
|
156
|
+
if @options[:use_braces_instead_of_do_end]
|
157
|
+
value_buf.puts(indent + "}\n" + indent + curr_key + ' {|*|')
|
158
|
+
else
|
159
|
+
value_buf.puts(indent + "end\n" + indent + curr_key + ' do |*|')
|
160
|
+
end
|
156
161
|
end
|
157
162
|
end
|
158
163
|
|
159
164
|
if newline
|
160
|
-
value_buf.puts(indent + 'end')
|
165
|
+
value_buf.puts(indent + (@options[:use_braces_instead_of_do_end] ? '}' : 'end'))
|
161
166
|
else
|
162
|
-
value_buf.print(indent + 'end')
|
167
|
+
value_buf.print(indent + (@options[:use_braces_instead_of_do_end] ? '}' : 'end'))
|
163
168
|
end
|
164
169
|
else
|
165
170
|
value_buf.puts(' [')
|
data/lib/dslh/version.rb
CHANGED
data/spec/dslh_spec.rb
CHANGED
@@ -775,6 +775,14 @@ end
|
|
775
775
|
expect(evaluated).to eq(template)
|
776
776
|
end
|
777
777
|
|
778
|
+
it 'should convert json to dsl (use braces)' do
|
779
|
+
template = JSON.parse(drupal_multi_az_template)
|
780
|
+
|
781
|
+
dsl = Dslh.deval(template)
|
782
|
+
evaluated = Dslh.eval(dsl, :key_conv => proc {|i| i.to_s }, :use_braces_instead_of_do_end => true)
|
783
|
+
expect(evaluated).to eq(template)
|
784
|
+
end
|
785
|
+
|
778
786
|
it 'should convert json to dsl with key_conf' do
|
779
787
|
template = JSON.parse(drupal_multi_az_template)
|
780
788
|
|
@@ -2751,4 +2759,47 @@ glossary do
|
|
2751
2759
|
end
|
2752
2760
|
EOS
|
2753
2761
|
end
|
2762
|
+
|
2763
|
+
it 'should convert hash to dsl (use braces)' do
|
2764
|
+
h = {"glossary"=>
|
2765
|
+
{"title"=>"example glossary",
|
2766
|
+
"GlossDiv"=>
|
2767
|
+
{"title"=>"S",
|
2768
|
+
"GlossList"=>
|
2769
|
+
{"GlossEntry"=>
|
2770
|
+
{"ID"=>"SGML",
|
2771
|
+
"SortAs"=>"SGML",
|
2772
|
+
"GlossTerm"=>"Standard Generalized Markup Language",
|
2773
|
+
"Acronym"=>"SGML",
|
2774
|
+
"Abbrev"=>"ISO 8879:1986",
|
2775
|
+
"GlossDef"=>
|
2776
|
+
{"para"=>
|
2777
|
+
"A meta-markup language, used to create markup languages such as DocBook.",
|
2778
|
+
"GlossSeeAlso"=>["GML", "XML"]},
|
2779
|
+
"GlossSee"=>"markup"}}}}}
|
2780
|
+
|
2781
|
+
dsl = Dslh.deval(h, :use_braces_instead_of_do_end => true)
|
2782
|
+
expect(dsl).to eq(<<-EOS)
|
2783
|
+
glossary {
|
2784
|
+
title "example glossary"
|
2785
|
+
GlossDiv {
|
2786
|
+
title "S"
|
2787
|
+
GlossList {
|
2788
|
+
GlossEntry {
|
2789
|
+
ID "SGML"
|
2790
|
+
SortAs "SGML"
|
2791
|
+
GlossTerm "Standard Generalized Markup Language"
|
2792
|
+
Acronym "SGML"
|
2793
|
+
Abbrev "ISO 8879:1986"
|
2794
|
+
GlossDef {
|
2795
|
+
para "A meta-markup language, used to create markup languages such as DocBook."
|
2796
|
+
GlossSeeAlso "GML", "XML"
|
2797
|
+
}
|
2798
|
+
GlossSee "markup"
|
2799
|
+
}
|
2800
|
+
}
|
2801
|
+
}
|
2802
|
+
}
|
2803
|
+
EOS
|
2804
|
+
end
|
2754
2805
|
end
|