reality-generators 1.12.0 → 1.13.0

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: 6449615da8a7084e231edf77e9846601f1b8ac55
4
- data.tar.gz: e15cf1793acaf16344595204197d8d34e1e6882d
3
+ metadata.gz: 1297d38734cc883a6243e3f0fbc025b7453c0959
4
+ data.tar.gz: 2ff0c67fff65ebd6d6ea53d389ba6d9b1e23880c
5
5
  SHA512:
6
- metadata.gz: 2a2641ffdf3ffffef5120a76debe8a462a98c5d79b3a271f48f56ca32c43a2406db01aaa3e738fe468d34668669494a9b07eac3450635b79e1085dd05e809a8c
7
- data.tar.gz: 589ed998dfde9b98773a7ffb1d69ab212812af37db233975de9f3b0cecc4a115f5aed751a78250d5e70feaca5866808d5197a7dea35f3849147f4584346f31b1
6
+ metadata.gz: 451e2d53fd2c63d856a423ac98e7414aecbbcb6e86994cb9c3eecc737c53b3f69e3fc565faf344c29f626bdcf2b53812e0750f781d4183079396ab639e145d92
7
+ data.tar.gz: 6187a5a3cfb1516be9011185984661dff6dbe87718ef3014bd578401392cb5946f49b5a4e9de7d64af88e397003b212cc4fe640a73330241de6bfd8b475c1e12
@@ -148,5 +148,47 @@ module Reality #nodoc
148
148
  Generators.error('render_to_string not implemented')
149
149
  end
150
150
  end
151
+
152
+ # Base class for templates that generate a single directory
153
+ class SingleDirectoryOutputTemplate < Reality::Generators::Template
154
+ attr_reader :output_directory_pattern
155
+
156
+ def initialize(template_set, facets, target, template_key, output_directory_pattern, helpers = [], options = {})
157
+ super(template_set, facets, target, template_key, helpers, options)
158
+ @output_directory_pattern = output_directory_pattern
159
+ end
160
+
161
+ def output_path
162
+ output_directory_pattern
163
+ end
164
+
165
+ protected
166
+
167
+ def generate!(target_basedir, element, unprocessed_files)
168
+ object_name = name_for_element(element)
169
+ render_context = create_context(element)
170
+ context_binding = render_context.context_binding
171
+ begin
172
+ output_directory = eval("\"#{self.output_directory_pattern}\"", context_binding, "#{self.template_key}#Filename")
173
+ output_directory = File.join(target_basedir, output_directory)
174
+ unprocessed_files.delete_if { |f| f =~ /^#{output_directory}\/.*/ }
175
+
176
+ FileUtils.mkdir_p File.dirname(output_directory) unless File.directory?(File.dirname(output_directory))
177
+ generated = generate_to_directory!(output_directory, element)
178
+
179
+ if generated
180
+ Generators.debug "Generated #{self.name} for #{self.target} #{object_name} to #{output_directory}"
181
+ else
182
+ Generators.debug "Skipped generation of #{self.name} for #{self.target} #{object_name} to #{output_filename} due to no changes"
183
+ end
184
+ rescue => e
185
+ raise Generators::GeneratorError.new("Error generating #{self.name} for #{self.target} #{object_name} due to '#{e}'", e)
186
+ end
187
+ end
188
+
189
+ def generate_to_directory!(output_directory, element)
190
+ Generators.error('generate_to_directory! not implemented')
191
+ end
192
+ end
151
193
  end
152
194
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.12.0'
5
+ s.version = '1.13.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -156,4 +156,44 @@ class Reality::Generators::TestTemplate < Reality::TestCase
156
156
 
157
157
  assert_equal 'X', IO.read(target_filename)
158
158
  end
159
+
160
+ class DirTemplate < Reality::Generators::SingleDirectoryOutputTemplate
161
+ def generate_to_directory!(output_directory, element)
162
+ FileUtils.rm_rf output_directory
163
+ FileUtils.mkdir_p output_directory
164
+ File.write("#{output_directory}/foo.txt",'X')
165
+ end
166
+ end
167
+
168
+ def test_single_directory_template
169
+ template_set = Reality::Generators::TemplateSet.new(TestTemplateSetContainer, 'foo')
170
+
171
+ output_directory_pattern = 'assets/#{component.name}'
172
+ template_key = 'MyFiles/templates/noft'
173
+ TestTemplateSetContainer.target_manager.target(:component)
174
+
175
+ template1 = DirTemplate.new(template_set, [], :component, template_key, output_directory_pattern, [], {})
176
+
177
+ assert_equal output_directory_pattern, template1.output_directory_pattern
178
+ assert_equal output_directory_pattern, template1.output_path
179
+ assert_equal template_set, template1.template_set
180
+ assert_equal [], template1.facets
181
+ assert_equal :component, template1.target
182
+ assert_equal [], template1.helpers
183
+ assert_equal template_key, template1.template_key
184
+ assert_equal nil, template1.guard
185
+ assert_equal({}, template1.extra_data)
186
+ assert_equal 'foo:MyFiles/templates/noft', template1.name
187
+
188
+ target_basedir = "#{temp_dir}/generated/single_dir_template"
189
+ target_filename = "#{target_basedir}/assets/SimpleModel/foo.txt"
190
+ other_filename = "#{target_basedir}/main/java/Other.java"
191
+ unprocessed_files = %W(#{target_filename} #{other_filename})
192
+ assert_equal false, File.exist?(target_filename)
193
+ template1.generate(target_basedir, SimpleModel.new, unprocessed_files)
194
+ assert_equal true, File.exist?(target_filename)
195
+ assert_equal 1, unprocessed_files.size
196
+
197
+ assert_equal 'X', IO.read(target_filename)
198
+ end
159
199
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reality-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-21 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core