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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: accc36f444e49fdce316464ef42d7ab5dbee863c
4
- data.tar.gz: 912a67f6db4edb45f73ef454a35016b4b42d1b9a
3
+ metadata.gz: eaa7072cea6f58fcbe9e341e3cfe3e6569ac7754
4
+ data.tar.gz: 9c35be524118f1a0a53ddf349688fdf6780cdeb7
5
5
  SHA512:
6
- metadata.gz: e888126dcbbeb1b3045b38fe46a21ff9df09e4b3a1d65d59c93ed6f901f95359ca7102cbfabd73222c96ee38868e5034543199749107996b95ff7063b971af90
7
- data.tar.gz: cc3ec0b4b6519080bec3742e47bde94d9d32f1c7cf01e1d3183491a533f6f21d1d67f49b3b31a28e2d318dc8796e4e934c5e5519266747f53c78b894dda076db
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
+ ```
@@ -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
- value_buf.puts(indent + "end\n" + indent + curr_key + ' do |*|')
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(' [')
@@ -1,3 +1,3 @@
1
1
  class Dslh
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dslh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara