ad_hoc_template 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module AdHocTemplate
2
- VERSION = "0.4.0"
4
+ VERSION = '0.4.1'
3
5
  end
@@ -0,0 +1,14 @@
1
+ Title: Famous authors of French literature
2
+
3
+ Name: Albert Camus
4
+ Birthplace: Algeria
5
+ Works:
6
+ * L'E'tranger
7
+ * La Peste
8
+
9
+ Name: Marcel Ayme'
10
+ Birthplace: France
11
+ Works:
12
+ * Le Passe-muraille
13
+ * Les Contes du chat perche'
14
+
@@ -586,6 +586,37 @@ TSV
586
586
  end
587
587
  end
588
588
 
589
+ describe '--init-local-settings' do
590
+ before do
591
+ @config_manager = AdHocTemplate::ConfigManager
592
+ @settings_dir = File.expand_path(@config_manager::LOCAL_SETTINGS_DIR)
593
+ @setting_file_name = @config_manager::SETTINGS_FILE_NAME
594
+ @tag_def_file_name = @config_manager::TAG_DEF_FILE_NAME
595
+ @settings_path = File.expand_path(File.join(@settings_dir, @setting_file_name))
596
+ @settings_file = StringIO.new('', "w")
597
+ @tag_def_path = File.expand_path(File.join(@settings_dir, @tag_def_file_name))
598
+ @tag_def_file = StringIO.new('', "w")
599
+ end
600
+
601
+ it 'output a message indicating the directory created using this option' do
602
+ allow(File).to receive(:exist?).with(@settings_dir).and_return(true)
603
+ allow(FileUtils).to receive(:mkdir).and_return(false)
604
+ allow(File).to receive(:exist?).with(@settings_path).and_return(true)
605
+ allow(@config_manager).to receive(:open).with(@settings_path, 'wb').and_yield(@settings_file)
606
+ allow(File).to receive(:exist?).with(@tag_def_path).and_return(true)
607
+ allow(@config_manager).to receive(:open).with(@tag_def_path, 'wb').and_yield(@tag_def_file)
608
+
609
+ allow(STDOUT).to receive(:puts).with("Please edit configuration files created in #{@settings_dir}")
610
+
611
+ set_argv('--init-local-settings')
612
+ command_line_interface = AdHocTemplate::CommandLineInterface.new
613
+ command_line_interface.parse_command_line_options
614
+
615
+ expect(@settings_file.string).to be_empty
616
+ expect(@tag_def_file.string).to be_empty
617
+ end
618
+ end
619
+
589
620
  describe '--recipe-template' do
590
621
  it 'reads template files and geperates a blank recipe' do
591
622
  expected_result = <<RECIPE
@@ -114,9 +114,9 @@ YAML
114
114
  allow(File).to receive(:exist?).with(@settings_dir).and_return(false)
115
115
  allow(FileUtils).to receive(:mkdir).and_return(true)
116
116
  allow(File).to receive(:exist?).with(@settings_path).and_return(false)
117
- allow(@config_manager).to receive(:open).with(@settings_path, 'w').and_yield(@settings_file)
117
+ allow(File).to receive(:open).with(@settings_path, 'wb').and_yield(@settings_file)
118
118
  allow(File).to receive(:exist?).with(@tag_def_path).and_return(false)
119
- allow(@config_manager).to receive(:open).with(@tag_def_path, 'w').and_yield(@tag_def_file)
119
+ allow(File).to receive(:open).with(@tag_def_path, 'wb').and_yield(@tag_def_file)
120
120
 
121
121
  @config_manager.init_local_settings
122
122
 
@@ -128,9 +128,9 @@ YAML
128
128
  allow(File).to receive(:exist?).with(@settings_dir).and_return(true)
129
129
  allow(FileUtils).to receive(:mkdir).and_return(false)
130
130
  allow(File).to receive(:exist?).with(@settings_path).and_return(true)
131
- allow(@config_manager).to receive(:open).with(@settings_path, 'w').and_yield(@settings_file)
131
+ allow(File).to receive(:open).with(@settings_path, 'wb').and_yield(@settings_file)
132
132
  allow(File).to receive(:exist?).with(@tag_def_path).and_return(true)
133
- allow(@config_manager).to receive(:open).with(@tag_def_path, 'w').and_yield(@tag_def_file)
133
+ allow(File).to receive(:open).with(@tag_def_path, 'wb').and_yield(@tag_def_file)
134
134
 
135
135
  @config_manager.init_local_settings
136
136
 
@@ -296,7 +296,7 @@ RECIPE
296
296
 
297
297
  template_names = %w(template1.html template2.html)
298
298
  template_names.each do |template_name|
299
- allow(AdHocTemplate::EntryFormatGenerator).to receive(:open).with(File.expand_path(template_name)).and_yield(StringIO.new(@template))
299
+ allow(File).to receive(:open).with(File.expand_path(template_name), 'rb:BOM|UTF-8').and_yield(StringIO.new(@template))
300
300
  end
301
301
 
302
302
  result = AdHocTemplate::EntryFormatGenerator.extract_recipes_from_template_files(template_names)
@@ -432,7 +432,7 @@ CONFIG
432
432
  defined_tag_type = AdHocTemplate::Parser::TagType[:xml_like3]
433
433
  expect(defined_tag_type.head_of[iteration_tag_node]).to eq('<repeat>')
434
434
  expect(defined_tag_type.tail_of[iteration_tag_node]).to eq('</repeat>')
435
- expect(defined_tag_type.remove_iteration_indent).to eq(true)
435
+ expect(defined_tag_type.strip_iteration_indent).to eq(true)
436
436
  end
437
437
 
438
438
  it "raises an error if a given definition does not contain sufficient information" do
@@ -491,6 +491,20 @@ TEMPLATE
491
491
  end
492
492
  end
493
493
 
494
+ describe '#contains_any_fallback_tag?' do
495
+ it 'returns true if a FallbackNode is contained' do
496
+ source = 'main start <%# <%* content in fallback_tag <%= tag node in fallback tag %> fallback end *%> optional content with <%#iterations: in iteration tag <%= item %> #%> iteration part end #%> main end'
497
+ tree = AdHocTemplate::Parser.parse(source)
498
+ expect(tree[1].contains_any_fallback_tag?).to be_truthy
499
+ end
500
+
501
+ it 'returns false if no FallbackNode is contained' do
502
+ source = 'main start <%# <% content in non-fallback_tag <%= tag node in non-fallback tag %> fallback end %> optional content with <%#iterations: in iteration tag <%= item %> #%> iteration part end #%> main end'
503
+ tree = AdHocTemplate::Parser.parse(source)
504
+ expect(tree[1].contains_any_fallback_tag?).to be_falsy
505
+ end
506
+ end
507
+
494
508
  describe "#inner_iteration_tag_labels" do
495
509
  it "returns labels of inner iteration tags" do
496
510
  template =<<TEMPLATE
@@ -117,7 +117,7 @@ EXPECTED_RESULT
117
117
  data_file_path = File.expand_path(block['data'])
118
118
  csv_data = StringIO.new(@csv_data)
119
119
  open_mode = ['rb', block['data_encoding']].join(':')
120
- allow(reader).to receive(:open).with(data_file_path, open_mode).and_yield(csv_data)
120
+ allow(File).to receive(:open).with(data_file_path, open_mode).and_yield(csv_data)
121
121
  block_data = reader.prepare_block_data(block)
122
122
  expect(block_data).to eq(expected_result)
123
123
  end
@@ -158,7 +158,7 @@ RECIPE
158
158
  data_file_path = File.expand_path(block['data'])
159
159
  csv_data = StringIO.new(@csv_data)
160
160
  open_mode = ['rb', block['data_encoding']].join(':')
161
- allow(reader).to receive(:open).with(data_file_path, open_mode).and_yield(csv_data)
161
+ allow(File).to receive(:open).with(data_file_path, open_mode).and_yield(csv_data)
162
162
  block_data = reader.prepare_block_data(block)
163
163
  expect(block_data).to eq(expected_result)
164
164
  end
@@ -176,12 +176,12 @@ RECIPE
176
176
 
177
177
  reader = AdHocTemplate::RecipeManager.new(@recipe)
178
178
  recipe = reader.recipe
179
- allow(reader).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
179
+ allow(File).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
180
180
  recipe['blocks'].each do |block|
181
181
  data_file_path = File.expand_path(block['data'])
182
182
  csv_data = StringIO.new(@csv_data)
183
183
  open_mode = ['rb', block['data_encoding']].join(':')
184
- allow(reader).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
184
+ allow(File).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
185
185
  end
186
186
  main_block = reader.load_records
187
187
  expect(main_block).to eq(expected_result)
@@ -212,7 +212,7 @@ MAIN_DATA
212
212
 
213
213
  reader = AdHocTemplate::RecipeManager.new(recipe_source)
214
214
  recipe = reader.recipe
215
- allow(reader).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(main_data))
215
+ allow(File).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(main_data))
216
216
 
217
217
  main_block = reader.load_records
218
218
  expect(main_block).to eq(expected_result)
@@ -251,7 +251,7 @@ RECIPE
251
251
 
252
252
  reader = AdHocTemplate::RecipeManager.new(recipe_source)
253
253
  recipe = reader.recipe
254
- allow(reader).to receive(:open).with(File.expand_path(recipe['blocks'][1]['data']), 'rb:iso-8859-1').and_yield(StringIO.new(@csv_data))
254
+ allow(File).to receive(:open).with(File.expand_path(recipe['blocks'][1]['data']), 'rb:iso-8859-1').and_yield(StringIO.new(@csv_data))
255
255
  main_block = reader.load_records
256
256
 
257
257
  expect(main_block).to eq(expected_result)
@@ -286,7 +286,7 @@ RECIPE
286
286
 
287
287
  reader = AdHocTemplate::RecipeManager.new(recipe_source)
288
288
  recipe = reader.recipe
289
- allow(reader).to receive(:open).with(File.expand_path(recipe['blocks'][0]['data']), 'rb:iso-8859-1').and_yield(StringIO.new(@csv_data))
289
+ allow(File).to receive(:open).with(File.expand_path(recipe['blocks'][0]['data']), 'rb:iso-8859-1').and_yield(StringIO.new(@csv_data))
290
290
  main_block = reader.load_records
291
291
 
292
292
  expect(main_block).to eq(expected_result)
@@ -295,12 +295,12 @@ RECIPE
295
295
  it "the result of #load_records can be used as input of DataLoader.parse" do
296
296
  reader = AdHocTemplate::RecipeManager.new(@recipe)
297
297
  recipe = reader.recipe
298
- allow(reader).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
298
+ allow(File).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
299
299
  recipe['blocks'].each do |block|
300
300
  data_file_path = File.expand_path(block['data'])
301
301
  csv_data = StringIO.new(@csv_data)
302
302
  open_mode = ['rb', block['data_encoding']].join(':')
303
- allow(reader).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
303
+ allow(File).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
304
304
  end
305
305
 
306
306
  main_block = reader.load_records
@@ -313,7 +313,7 @@ RECIPE
313
313
  reader = AdHocTemplate::RecipeManager.new(@recipe)
314
314
  template_path = File.expand_path(reader.recipe['template'])
315
315
  open_mode = 'rb:BOM|UTF-8'
316
- expect_any_instance_of(AdHocTemplate::RecipeManager).to receive(:open).with(template_path, open_mode).and_yield(StringIO.new(@template))
316
+ allow(File).to receive(:open).with(template_path, open_mode).and_yield(StringIO.new(@template))
317
317
 
318
318
  reader.parse_template
319
319
 
@@ -324,20 +324,20 @@ RECIPE
324
324
  reader = AdHocTemplate::RecipeManager.new(@recipe)
325
325
  recipe = reader.recipe
326
326
 
327
- allow_any_instance_of(AdHocTemplate::RecipeManager).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
327
+ allow(File).to receive(:open).with(File.expand_path(recipe['data']), 'rb:BOM|UTF-8').and_yield(StringIO.new(@main_data))
328
328
  recipe['blocks'].each do |block|
329
329
  data_file_path = File.expand_path(block['data'])
330
330
  csv_data = StringIO.new(@csv_data)
331
331
  open_mode = block['data_encoding'] ? ['rb', block['data_encoding']].join(':') : 'rb:BOM|UTF-8'
332
- expect_any_instance_of(AdHocTemplate::RecipeManager).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
332
+ expect(File).to receive(:open).with(data_file_path, open_mode).and_yield(StringIO.new(@csv_data))
333
333
  end
334
334
 
335
335
  template_path = File.expand_path(reader.recipe['template'])
336
336
  open_mode = 'rb:BOM|UTF-8'
337
337
  output_file_path = File.expand_path(reader.recipe['output_file'])
338
338
  output_file = StringIO.new(@template)
339
- expect_any_instance_of(AdHocTemplate::RecipeManager).to receive(:open).with(template_path, open_mode).and_yield(StringIO.new(@template))
340
- expect_any_instance_of(AdHocTemplate::RecipeManager).to receive(:open).with(output_file_path, 'wb:UTF-8').and_yield(output_file)
339
+ allow(File).to receive(:open).with(template_path, open_mode).and_yield(StringIO.new(@template))
340
+ allow(File).to receive(:open).with(output_file_path, 'wb:UTF-8').and_yield(output_file)
341
341
 
342
342
  reader.update_output_file
343
343
  expect(output_file.string).to eq(@expected_result)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ad_hoc_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-05 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pseudohikiparser
@@ -44,42 +44,56 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '1.16'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '1.16'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.1'
61
+ version: '12.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.1'
68
+ version: '12.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.2'
75
+ version: '3.7'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.2'
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.55'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.55'
83
97
  description: AdHocTemplate is a template processor with simple but sufficient rules
84
98
  for some ad hoc tasks.
85
99
  email:
@@ -91,6 +105,7 @@ extra_rdoc_files: []
91
105
  files:
92
106
  - ".gitignore"
93
107
  - ".rspec"
108
+ - ".rubocop.yml"
94
109
  - ".travis.yml"
95
110
  - Gemfile
96
111
  - LICENSE.txt
@@ -107,8 +122,10 @@ files:
107
122
  - lib/ad_hoc_template/pseudohiki_formatter.rb
108
123
  - lib/ad_hoc_template/recipe_manager.rb
109
124
  - lib/ad_hoc_template/record_reader.rb
125
+ - lib/ad_hoc_template/shim.rb
110
126
  - lib/ad_hoc_template/utils.rb
111
127
  - lib/ad_hoc_template/version.rb
128
+ - output.html
112
129
  - samples/en/inner_iteration/data.aht
113
130
  - samples/en/inner_iteration/data.csv
114
131
  - samples/en/inner_iteration/data.yaml
@@ -166,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
183
  version: '0'
167
184
  requirements: []
168
185
  rubyforge_project:
169
- rubygems_version: 2.2.0
186
+ rubygems_version: 2.4.5.3
170
187
  signing_key:
171
188
  specification_version: 4
172
189
  summary: A tiny template processor