reality-generators 1.3.0 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9ad0b0940ce5ac12939a1a706dc9ad33bcc11dc
4
- data.tar.gz: eb2a63bbafeb93019936dbe82e04be952267484d
3
+ metadata.gz: fd884c4080b180702c66c240bc3782989c7e0533
4
+ data.tar.gz: 80120fc316eb2ab3136c5be04e4f7f359afac81d
5
5
  SHA512:
6
- metadata.gz: 6bec7f97ecedf32f57af104a8b759b8236c7aaeb7dd56062854632462792918752040c0c218c80fba42f0eabaf35a7c64db7b9eee048a56d79f7d302afcfb385
7
- data.tar.gz: 6a8d123251caaccd2f19e200ef26772402a3bed3d95f8ff9d234b0997003311238cead078c4edd6eff99912bbf0d3d63c09b757a131c86ec480fe44f39ef92a2
6
+ metadata.gz: 749439d7af5d2316f8b22960c893a5b277ca074031e8c915e4dbfe7f5d18c2d99600dcaeee9344d5a5ba2a2d7d3c7d9d6c70b6ace3c59d0aefbc1765befded8c
7
+ data.tar.gz: 675da30cf2daa432a2e66cde10fb35a407ee7753eb9e2e0f92a32c96c7b863723ad312257df618cc6567c020829b35d7a1e49e45c00b985223efd6e4a46f0fd5
@@ -27,5 +27,7 @@ require 'reality/generators/erb_template'
27
27
  require 'reality/generators/template_set'
28
28
  require 'reality/generators/template_set_container'
29
29
  require 'reality/generators/generator'
30
+ require 'reality/generators/standard_template_set'
31
+ require 'reality/generators/standard_artifact_dsl'
30
32
 
31
33
  require 'reality/generators/buildr_integration'
@@ -14,87 +14,89 @@
14
14
 
15
15
  module Reality #nodoc
16
16
  module Generators #nodoc
17
- module Generator
18
- # This method is called from a Rake or Buildr task to configure the Buildr
19
- # project so that it knows the location of all the generated artifacts and
20
- # adds them to the appropriate compile paths etc.
21
- def configure_buildr_project(buildr_project, generator_task, templates, target_dir)
22
- if buildr_project.nil?
23
- task('clean') do
24
- rm_rf target_dir
25
- end
26
- else
27
- buildr_project.clean { rm_rf target_dir }
28
- file(File.expand_path(target_dir) => [generator_task])
29
-
30
- # Is there java source generated in project?
31
- if templates.any? { |template| template.output_path =~ /^main\/java\/.*/ }
32
- main_java_dir = "#{target_dir}/main/java"
33
- file(main_java_dir => [generator_task]) do
34
- mkdir_p main_java_dir
17
+ module Buildr
18
+ class << self
19
+ # This method is called from a Rake or Buildr task to configure the Buildr
20
+ # project so that it knows the location of all the generated artifacts and
21
+ # adds them to the appropriate compile paths etc.
22
+ def configure_buildr_project(buildr_project, generator_task, templates, target_dir)
23
+ if buildr_project.nil?
24
+ task('clean') do
25
+ rm_rf target_dir
35
26
  end
36
- buildr_project.compile.using :javac
37
- buildr_project.compile.from main_java_dir
38
- # Need to force this as it may have already been cached and thus will not recalculate
39
- buildr_project.iml.main_generated_source_directories << main_java_dir if buildr_project.iml?
40
- end
27
+ else
28
+ buildr_project.clean { rm_rf target_dir }
29
+ file(File.expand_path(target_dir) => [generator_task])
41
30
 
42
- # Is there resources generated in project?
43
- if templates.any? { |template| template.output_path =~ /^main\/resources\/.*/ }
44
- main_resources_dir = "#{target_dir}/main/resources"
45
- file(main_resources_dir => [generator_task]) do
46
- mkdir_p main_resources_dir
31
+ # Is there java source generated in project?
32
+ if templates.any? { |template| template.output_path =~ /^main\/java\/.*/ }
33
+ main_java_dir = "#{target_dir}/main/java"
34
+ file(main_java_dir => [generator_task]) do
35
+ mkdir_p main_java_dir
36
+ end
37
+ buildr_project.compile.using :javac
38
+ buildr_project.compile.from main_java_dir
39
+ # Need to force this as it may have already been cached and thus will not recalculate
40
+ buildr_project.iml.main_generated_source_directories << main_java_dir if buildr_project.iml?
47
41
  end
48
- buildr_project.resources.enhance([generator_task])
49
- buildr_project.resources.filter.into buildr_project.path_to(:target, :main, :resources) unless buildr_project.resources.target
50
- buildr_project.resources do |t|
51
- t.enhance do
52
- if File.exist?(main_resources_dir)
53
- FileUtils.mkdir_p buildr_project.resources.target.to_s
54
- FileUtils.cp_r "#{main_resources_dir}/.", buildr_project.resources.target.to_s
42
+
43
+ # Is there resources generated in project?
44
+ if templates.any? { |template| template.output_path =~ /^main\/resources\/.*/ }
45
+ main_resources_dir = "#{target_dir}/main/resources"
46
+ file(main_resources_dir => [generator_task]) do
47
+ mkdir_p main_resources_dir
48
+ end
49
+ buildr_project.resources.enhance([generator_task])
50
+ buildr_project.resources.filter.into buildr_project.path_to(:target, :main, :resources) unless buildr_project.resources.target
51
+ buildr_project.resources do |t|
52
+ t.enhance do
53
+ if File.exist?(main_resources_dir)
54
+ FileUtils.mkdir_p buildr_project.resources.target.to_s
55
+ FileUtils.cp_r "#{main_resources_dir}/.", buildr_project.resources.target.to_s
56
+ end
55
57
  end
56
58
  end
59
+ buildr_project.iml.main_generated_resource_directories << main_resources_dir if buildr_project.iml?
57
60
  end
58
- buildr_project.iml.main_generated_resource_directories << main_resources_dir if buildr_project.iml?
59
- end
60
61
 
61
- # Is there assets generated in project?
62
- if templates.any? { |template| template.output_path =~ /^main\/webapp\/.*/ }
63
- webapp_dir = File.expand_path("#{target_dir}/main/webapp")
64
- buildr_project.assets.enhance([generator_task])
65
- buildr_project.assets.paths << file(webapp_dir => [generator_task]) do
66
- mkdir_p webapp_dir
62
+ # Is there assets generated in project?
63
+ if templates.any? { |template| template.output_path =~ /^main\/webapp\/.*/ }
64
+ webapp_dir = File.expand_path("#{target_dir}/main/webapp")
65
+ buildr_project.assets.enhance([generator_task])
66
+ buildr_project.assets.paths << file(webapp_dir => [generator_task]) do
67
+ mkdir_p webapp_dir
68
+ end
67
69
  end
68
- end
69
70
 
70
- # Is there test java source generated in project?
71
- if templates.any? { |template| template.output_path =~ /^test\/java\/.*/ }
72
- test_java_dir = "#{target_dir}/test/java"
73
- file(test_java_dir => [generator_task]) do
74
- mkdir_p test_java_dir
71
+ # Is there test java source generated in project?
72
+ if templates.any? { |template| template.output_path =~ /^test\/java\/.*/ }
73
+ test_java_dir = "#{target_dir}/test/java"
74
+ file(test_java_dir => [generator_task]) do
75
+ mkdir_p test_java_dir
76
+ end
77
+ buildr_project.test.compile.from test_java_dir
78
+ # Need to force this as it may have already been cached and thus will not recalculate
79
+ buildr_project.iml.test_generated_source_directories << test_java_dir if buildr_project.iml?
75
80
  end
76
- buildr_project.test.compile.from test_java_dir
77
- # Need to force this as it may have already been cached and thus will not recalculate
78
- buildr_project.iml.test_generated_source_directories << test_java_dir if buildr_project.iml?
79
- end
80
81
 
81
- # Is there resources generated in project?
82
- if templates.any? { |template| template.output_path =~ /^test\/resources\/.*/ }
83
- test_resources_dir = "#{target_dir}/test/resources"
84
- file(test_resources_dir => [generator_task]) do
85
- mkdir_p test_resources_dir
86
- end
87
- buildr_project.test.resources.enhance([generator_task])
88
- buildr_project.test.resources.filter.into buildr_project.path_to(:target, :test, :resources) unless buildr_project.test.resources.target
89
- buildr_project.test.resources do |t|
90
- t.enhance do
91
- if File.exist?(test_resources_dir)
92
- FileUtils.mkdir_p buildr_project.test.resources.target.to_s
93
- FileUtils.cp_r "#{test_resources_dir}/.", buildr_project.test.resources.target.to_s
82
+ # Is there resources generated in project?
83
+ if templates.any? { |template| template.output_path =~ /^test\/resources\/.*/ }
84
+ test_resources_dir = "#{target_dir}/test/resources"
85
+ file(test_resources_dir => [generator_task]) do
86
+ mkdir_p test_resources_dir
87
+ end
88
+ buildr_project.test.resources.enhance([generator_task])
89
+ buildr_project.test.resources.filter.into buildr_project.path_to(:target, :test, :resources) unless buildr_project.test.resources.target
90
+ buildr_project.test.resources do |t|
91
+ t.enhance do
92
+ if File.exist?(test_resources_dir)
93
+ FileUtils.mkdir_p buildr_project.test.resources.target.to_s
94
+ FileUtils.cp_r "#{test_resources_dir}/.", buildr_project.test.resources.target.to_s
95
+ end
94
96
  end
95
97
  end
98
+ buildr_project.iml.test_generated_resource_directories << test_resources_dir if buildr_project.iml?
96
99
  end
97
- buildr_project.iml.test_generated_resource_directories << test_resources_dir if buildr_project.iml?
98
100
  end
99
101
  end
100
102
  end
@@ -14,11 +14,18 @@
14
14
 
15
15
  module Reality #nodoc
16
16
  module Generators #nodoc
17
- module Generator
17
+ class Generator
18
+
19
+ def initialize(template_set_container)
20
+ @template_set_container = template_set_container
21
+ end
22
+
23
+ attr_reader :template_set_container
24
+
18
25
  # Return a list of templates loaded from specified template_set_keys
19
- def load_templates_from_template_sets(template_set_container, template_set_keys)
26
+ def load_templates_from_template_sets(template_set_keys)
20
27
  template_map = {}
21
- load_templates(template_set_container, template_map, template_set_keys, [])
28
+ load_templates(template_map, template_set_keys, [])
22
29
  template_map.values
23
30
  end
24
31
 
@@ -29,13 +36,13 @@ module Reality #nodoc
29
36
  # The traversal starts from a root element of specified element_type and
30
37
  # traverses all elements that are contained transitively by the root element.
31
38
  # The templates then generate files from traversed elements.
32
- def generate(template_set_container, element_type, element, directory, templates, filter)
39
+ def generate(element_type, element, directory, templates, filter)
33
40
  unprocessed_files = (Dir["#{directory}/**/*.*"] + Dir["#{directory}/**/*"]).uniq
34
41
 
35
42
  Generators.debug "Templates to process: #{templates.collect { |t| t.name }.inspect}"
36
43
 
37
44
  targets = {}
38
- collect_generation_targets(template_set_container, element_type, element, element, targets)
45
+ collect_generation_targets(element_type, element, element, targets)
39
46
 
40
47
  templates.each do |template|
41
48
  Generators.debug "Evaluating template: #{template.name}"
@@ -66,12 +73,12 @@ module Reality #nodoc
66
73
 
67
74
  private
68
75
 
69
- def load_templates(template_set_container, template_map, template_set_keys, processed_template_sets)
76
+ def load_templates(template_map, template_set_keys, processed_template_sets)
70
77
  template_set_keys.each do |template_set_key|
71
78
  next if processed_template_sets.include?(template_set_key)
72
- template_set = template_set_container.template_set_by_name(template_set_key)
79
+ template_set = self.template_set_container.template_set_by_name(template_set_key)
73
80
  processed_template_sets << template_set_key
74
- load_templates(template_set_container, template_map, template_set.required_template_sets, processed_template_sets)
81
+ load_templates(template_map, template_set.required_template_sets, processed_template_sets)
75
82
  template_set.templates.each do |template|
76
83
  template_map[template.name] = template
77
84
  end
@@ -92,11 +99,11 @@ module Reality #nodoc
92
99
  # ...
93
100
  # }
94
101
  #
95
- def collect_generation_targets(template_set_container, element_type, scope_element, element, targets)
102
+ def collect_generation_targets(element_type, scope_element, element, targets)
96
103
  (targets[element_type] ||= []) << [scope_element, element]
97
104
 
98
- template_set_container.target_manager.targets_by_container(element_type).each do |target|
99
- next unless handle_subelement?(element, target.key)
105
+ self.template_set_container.target_manager.targets_by_container(element_type).each do |target|
106
+ next unless self.template_set_container.handle_subelement?(element, target.key)
100
107
  subelements = nil
101
108
  subscope = nil
102
109
  if target.standard?
@@ -110,16 +117,10 @@ module Reality #nodoc
110
117
  subelements = [subelements] unless subelements.is_a?(Array)
111
118
 
112
119
  subelements.each do |subelement|
113
- collect_generation_targets(template_set_container, target.qualified_key, subscope || subelement, subelement, targets)
120
+ collect_generation_targets(target.qualified_key, subscope || subelement, subelement, targets)
114
121
  end
115
122
  end
116
123
  end
117
-
118
- # A hook to control whether certain paths in model should
119
- # be follow when collecting generation targets
120
- def handle_subelement?(object, sub_feature_key)
121
- true
122
- end
123
124
  end
124
125
  end
125
126
  end
@@ -0,0 +1,121 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ module Reality #nodoc
16
+ module Generators #nodoc
17
+
18
+ # This module is typically included into the facet extension objects. It
19
+ # simplifies the definition of templates from the facet extension objects.
20
+ #
21
+ # Note: The framework needs to supply a method template_set_container
22
+ #
23
+ # The module assumes that facets are defined using a specific convention.
24
+ # Namely that by convention facets are defined in a file named `.../<myfacet>/model.rb`
25
+ # and templates are defined in a file named `.../<myfacet>/templates/<templatekey>.<output_extension>.<template_extension>`
26
+ # When attempting to derive default values for configuration it will be derived using these conventions.
27
+ #
28
+ module ArtifactDSL
29
+
30
+ #
31
+ # Define a java artifact. This is a wrapper around the artifact() method
32
+ # that makes additional assumptions for java based artifacts. This method
33
+ # assumes a maven-style file system layout (i.e. java is stored in main/java or test/java).
34
+ # It also assumes that the facet has the fully qualified name of the artifact in a method
35
+ # named with the convention "qualified_<artifact_key>_name"
36
+ #
37
+ # The options supported include those supplied to the artifact method plus:
38
+ # * :artifact_category - The option must be one of :main or :test and determines which source hierarchy the code is added to.
39
+ #
40
+ def java_artifact(template_set_suffix, artifact_key, options = {})
41
+ options = options.dup
42
+ artifact_category = options.delete(:artifact_category) || :main
43
+ Reality::Generators.error("artifact_category '#{artifact_category}' is not a known type") unless [:main, :test].include?(artifact_category)
44
+ filename_pattern = "#{artifact_category}/java/\#{#{self.target_key}.#{self.facet_key}.qualified_#{artifact_key}_name.gsub(\".\",\"/\")}.java"
45
+ artifact(template_set_suffix, artifact_key, filename_pattern, options)
46
+ end
47
+
48
+ #
49
+ # Define an artifact and attach it to template_set.
50
+ # This assumes that the the template is named with the convention "<facet_templates_directory>/<artifact_key>.<file_extension>"
51
+ # with the file extension derived from the supplied filename pattern.
52
+ #
53
+ # The template set is prefixed with the name of the facet from which this is extended.
54
+ #
55
+ # The options supported include:
56
+ # * :facets - additional facets that must be enabled for the facet to be generated.
57
+ # * :helpers - additional helpers that are added to the default helpers.
58
+ # * :guard - The :guard option passed to the template.
59
+ #
60
+ def artifact(template_set_suffix, artifact_key, filename_pattern, options = {})
61
+ Reality::Options.check(options, [:facets, :guard, :helpers], Reality::Generators, 'define artifact')
62
+
63
+ facets = [self.facet_key] + (options[:facets].nil? ? [] : options[:facets])
64
+
65
+ guard = options[:guard]
66
+
67
+ artifact_type = self.target_key
68
+
69
+ template_set_key = :"#{self.facet_key}_#{template_set_suffix}"
70
+
71
+ file_extension = File.extname(filename_pattern)[1...9999]
72
+
73
+ template_set = template_set_container.template_set_by_name?(template_set_key) ?
74
+ template_set_container.template_set_by_name(template_set_key) :
75
+ template_set_container.template_set(template_set_key)
76
+
77
+ base_template_filename = "#{facet_templates_directory}/#{artifact_key}.#{file_extension}"
78
+ template_extension = File.exist?("#{base_template_filename}.erb") ? 'erb' : 'rb'
79
+ template_filename = "#{base_template_filename}.#{template_extension}"
80
+
81
+
82
+ helpers = template_set_container.derive_default_helpers(options.merge(:file_type => file_extension, :artifact_type => artifact_type, :facet_key => self.facet_key)) +
83
+ (options[:helpers].nil? ? [] : options[:helpers])
84
+
85
+ if 'erb' == template_extension
86
+ template_set.erb_template(facets,
87
+ artifact_type,
88
+ template_filename,
89
+ filename_pattern,
90
+ helpers,
91
+ :guard => guard)
92
+ else
93
+ template_set.ruby_template(facets,
94
+ artifact_type,
95
+ template_filename,
96
+ filename_pattern,
97
+ helpers,
98
+ :guard => guard)
99
+ end
100
+ end
101
+
102
+ def facet_templates_directory
103
+ @facet_templates_directory ||= "#{facet_directory}/templates"
104
+ end
105
+
106
+ def facet_directory
107
+ @facet_directory ||= nil
108
+ if @facet_directory.nil?
109
+ caller_locations.each do |location|
110
+ if location.absolute_path =~ /.*\/#{self.facet_key}\/model\.rb$/
111
+ @facet_directory = File.dirname(location.absolute_path)
112
+ break
113
+ end
114
+ end
115
+ Reality::Generators.error("Unable to locate facet_directory for facet #{self.facet_key}. Caller trace: #{caller_locations.collect{|c|c.absolute_path}.inspect}") if @facet_directory.nil?
116
+ end
117
+ @facet_directory
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ module Reality #nodoc
16
+ module Generators #nodoc
17
+
18
+ # A standard template set that simple methods for creating templates using included template types
19
+ class StandardTemplateSet < TemplateSet
20
+ def erb_template(facets, target, template_filename, output_filename_pattern, helpers = [], options = {})
21
+ Reality::Generators::ErbTemplate.new(self, facets, target.to_sym, template_filename, output_filename_pattern, helpers, options)
22
+ end
23
+
24
+ def ruby_template(facets, target, template_filename, output_filename_pattern, helpers = [], options = {})
25
+ Reality::Generators::RubyTemplate.new(self, facets, target.to_sym, template_filename, output_filename_pattern, helpers, options)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -26,7 +26,7 @@ module Reality #nodoc
26
26
  @container_key = container_key.nil? ? nil : container_key.to_sym
27
27
 
28
28
  if @container_key && !target_manager.target_by_key?(@container_key)
29
- raise "Target '#{key}' defines container as '#{@container_key}' but no such target exists."
29
+ Reality::Generators.error("Target '#{key}' defines container as '#{@container_key}' but no such target exists.")
30
30
  end
31
31
 
32
32
  @target_manager.send(:register_target, self)
@@ -69,7 +69,7 @@ module Reality #nodoc
69
69
 
70
70
  def target_by_key(key)
71
71
  target = target_map[key.to_sym]
72
- raise "Can not find target with key '#{key}'" unless target
72
+ Reality::Generators.error("Can not find target with key '#{key}'") unless target
73
73
  target
74
74
  end
75
75
 
@@ -88,7 +88,7 @@ module Reality #nodoc
88
88
  private
89
89
 
90
90
  def register_target(target)
91
- raise "Attempting to redefine target #{target.qualified_key}" if target_map[target.qualified_key]
91
+ Reality::Generators.error("Attempting to redefine target #{target.qualified_key}") if target_map[target.qualified_key]
92
92
  target_map[target.qualified_key] = target
93
93
  end
94
94
 
@@ -71,7 +71,7 @@ module Reality #nodoc
71
71
  end
72
72
 
73
73
  def name
74
- @name ||= "#{self.template_set.name}:#{self.template_key.gsub(/.*\/templates\/(.*)\.#{template_extension}$/, '\1')}"
74
+ @name ||= "#{self.template_set.name}:#{self.template_key.gsub(/^(.*\/)?templates\/(.*)\.#{template_extension}$/, '\2')}"
75
75
  end
76
76
 
77
77
  protected
@@ -29,7 +29,7 @@ module Reality #nodoc
29
29
  super(options, &block)
30
30
  self.required_template_sets.each do |template_set_name|
31
31
  unless container.template_set_by_name?(template_set_name)
32
- raise "TemplateSet '#{self.name}' defined requirement on template set '#{template_set_name}' that does not exist."
32
+ Reality::Generators.error("TemplateSet '#{self.name}' defined requirement on template set '#{template_set_name}' that does not exist.")
33
33
  end
34
34
  end
35
35
  container.send(:register_template_set, self)
@@ -45,18 +45,31 @@ module Reality #nodoc
45
45
  end
46
46
 
47
47
  def generator
48
- @generator ||= new_generator
48
+ @generator ||= Reality::Generators::Generator.new(self)
49
+ end
50
+
51
+ # A hook to control whether certain paths in model should
52
+ # be follow when collecting generation targets
53
+ def handle_subelement?(object, sub_feature_key)
54
+ true
55
+ end
56
+
57
+ # Hook for deriving the default set of helpers when defining
58
+ # templates using the artifact DSL. Typically this is overridden
59
+ # in framework specific template set containers
60
+ def derive_default_helpers(options)
61
+ []
49
62
  end
50
63
 
51
64
  protected
52
65
 
53
66
  def register_template_set(template_set)
54
- raise "Attempting to redefine template_set #{template_set.name}" if template_set_map[template_set.name.to_s]
67
+ Reality::Generators.error("Attempting to redefine template_set #{template_set.name}") if template_set_map[template_set.name.to_s]
55
68
  template_set_map[template_set.name.to_s] = template_set
56
69
  end
57
70
 
58
71
  def new_template_set(name, options, &block)
59
- Generators.error('new_template_set not implemented')
72
+ Reality::Generators::StandardTemplateSet.new(self, name.to_s, options, &block)
60
73
  end
61
74
 
62
75
  def new_generator
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-generators}
5
- s.version = '1.3.0'
5
+ s.version = '1.5.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.has_rdoc = false
22
22
  s.rdoc_options = %w(--line-numbers --inline-source --title reality-generators)
23
23
 
24
- s.add_dependency 'reality-core', '>= 1.4.0'
25
- s.add_dependency 'reality-naming', '>= 1.4.0'
24
+ s.add_dependency 'reality-core', '>= 1.7.0'
25
+ s.add_dependency 'reality-naming', '>= 1.6.0'
26
26
  s.add_dependency 'reality-orderedhash', '>= 1.0.0'
27
27
 
28
28
  s.add_development_dependency(%q<minitest>, ['= 5.9.1'])
@@ -0,0 +1,63 @@
1
+ class TestFacetExtension
2
+ module MyHelperModule
3
+ end
4
+
5
+ class << self
6
+ include Reality::Generators::ArtifactDSL
7
+
8
+ def template_set_container
9
+ Reality::TestCase::TestTemplateSetContainer
10
+ end
11
+
12
+ def target_key
13
+ :entity
14
+ end
15
+
16
+ def facet_key
17
+ :jpa
18
+ end
19
+
20
+ def define_artifacts1
21
+ artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
22
+ end
23
+
24
+ def define_artifacts2
25
+ artifact(:models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
26
+ end
27
+
28
+ def define_artifacts3
29
+ artifact(:models,
30
+ :mytemplate,
31
+ 'main/java/#{entity.qualified_name}.java',
32
+ :facets => [:ee],
33
+ :helpers => [MyHelperModule],
34
+ :guard => 'entity.jpa.good?')
35
+ end
36
+
37
+ def define_artifacts4
38
+ artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
39
+ end
40
+
41
+ def define_artifacts5
42
+ artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java')
43
+ artifact(:qa_models, :mytemplate, 'test/java/#{entity.qualified_name}.java')
44
+ artifact(:qa_models, :rubytemplate, 'main/java/#{entity.qualified_name}.java')
45
+ end
46
+
47
+ def define_artifacts6
48
+ artifact(:models, :mytemplate, 'main/java/#{entity.qualified_name}.java', :bad_option => true)
49
+ end
50
+
51
+ def define_artifacts7
52
+ java_artifact(:models, :mytemplate)
53
+ end
54
+
55
+ def define_artifacts8
56
+ java_artifact(:models, :mytemplate, :artifact_category => :test)
57
+ end
58
+
59
+ def define_artifacts9
60
+ java_artifact(:models, :mytemplate, :artifact_category => :main)
61
+ end
62
+ end
63
+ end
@@ -16,7 +16,7 @@ class Reality::Generators::TestErbTemplate < Reality::TestCase
16
16
  template_set = Reality::Generators::TemplateSet.new(TestTemplateSetContainer, 'foo')
17
17
 
18
18
  output_filename_pattern = 'main/java/#{component.name}.java'
19
- template_filename = File.expand_path(File.dirname(__FILE__) + '/templates/mytemplate.java.erb')
19
+ template_filename = File.expand_path(File.dirname(__FILE__) + '/jpa/templates/mytemplate.java.erb')
20
20
  TestTemplateSetContainer.target_manager.target(:component)
21
21
 
22
22
  template1 = Reality::Generators::ErbTemplate.new(template_set, [], :component, template_filename, output_filename_pattern, [], {})
@@ -59,11 +59,11 @@ class Reality::Generators::TestGenerator < Reality::TestCase
59
59
  end
60
60
 
61
61
  def facet_enabled?(facet)
62
- facet == :jpa ? !!@jpa : false
62
+ facet == :jpa ? !!self.jpa : false
63
63
  end
64
64
 
65
65
  def jpa
66
- @jpa
66
+ @jpa ||= nil
67
67
  end
68
68
 
69
69
  def enable_jpa!
@@ -90,7 +90,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
90
90
  TestTemplateSetContainer.target_manager.target(:unit, :repository, :facet_key => :jpa)
91
91
 
92
92
  targets = {}
93
- TestTemplateSetContainer.generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
93
+ TestTemplateSetContainer.generator.send(:collect_generation_targets, :repository, repository, repository, targets)
94
94
 
95
95
  assert_equal true, targets.include?(:repository)
96
96
  assert_equal true, targets.include?(:entity)
@@ -119,7 +119,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
119
119
  repository.enable_jpa!
120
120
 
121
121
  targets = {}
122
- TestTemplateSetContainer.generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
122
+ TestTemplateSetContainer.generator.send(:collect_generation_targets, :repository, repository, repository, targets)
123
123
 
124
124
  # No units have been defined so no extra targets
125
125
  assert_equal 3, targets.size
@@ -128,7 +128,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
128
128
  repository.jpa.unit(:MyUnit2)
129
129
 
130
130
  targets = {}
131
- TestTemplateSetContainer.generator.send(:collect_generation_targets, TestTemplateSetContainer, :repository, repository, repository, targets)
131
+ TestTemplateSetContainer.generator.send(:collect_generation_targets, :repository, repository, repository, targets)
132
132
 
133
133
  assert_equal true, targets.include?(:repository)
134
134
  assert_equal true, targets.include?(:entity)
@@ -189,12 +189,12 @@ class Reality::Generators::TestGenerator < Reality::TestCase
189
189
  TestTemplateSetContainer.target_manager.target(:attribute, :entity)
190
190
  TestTemplateSetContainer.target_manager.target(:unit, :repository, :facet_key => :jpa)
191
191
 
192
- template_set = TestTemplateSetContainer.template_set(:test) do |template_set|
193
- RepositoryTemplate.new(template_set, [], :repository, 'repository.java', 'main/java/#{repository.name}.java')
192
+ template_set = TestTemplateSetContainer.template_set(:test) do |t|
193
+ RepositoryTemplate.new(t, [], :repository, 'repository.java', 'main/java/#{repository.name}.java')
194
194
 
195
- EntityTemplate.new(template_set, [], :entity, 'entity.java', 'main/java/#{entity.qualified_name.gsub(".","/")}.java', [], :guard => 'entity.qualified_name == "MyRepo.MyEntityB"')
196
- AttributeTemplate.new(template_set, [], :attribute, 'attribute.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}.java')
197
- UnitTemplate.new(template_set, [], :'jpa.unit', 'unit.java', 'main/java/units/#{unit.name.gsub(".","/")}.java', [], {})
195
+ EntityTemplate.new(t, [], :entity, 'entity.java', 'main/java/#{entity.qualified_name.gsub(".","/")}.java', [], :guard => 'entity.qualified_name == "MyRepo.MyEntityB"')
196
+ AttributeTemplate.new(t, [], :attribute, 'attribute.java', 'main/java/#{attribute.qualified_name.gsub(".","/")}.java')
197
+ UnitTemplate.new(t, [], :'jpa.unit', 'unit.java', 'main/java/units/#{unit.name.gsub(".","/")}.java', [], {})
198
198
  end
199
199
 
200
200
  target_directory = "#{temp_dir}/generated/erb_template"
@@ -211,7 +211,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
211
211
 
212
212
  filter = Proc.new { |artifact_type, artifact| artifact_type != :attribute || %w(MyAttr1 MyAttr2).include?(artifact.name.to_s) }
213
213
  TestTemplateSetContainer.generator.
214
- generate(TestTemplateSetContainer, :repository, repository, target_directory, template_set.templates, filter)
214
+ generate(:repository, repository, target_directory, template_set.templates, filter)
215
215
 
216
216
  assert_equal false, File.directory?("#{target_directory}/some")
217
217
  assert_equal false, File.exist?("#{target_directory}/main/java/Touched.java")
@@ -269,8 +269,7 @@ class Reality::Generators::TestGenerator < Reality::TestCase
269
269
  end
270
270
 
271
271
  template_set_keys = [:template_set_1, :template_set_4]
272
- templates = TestTemplateSetContainer.generator.
273
- load_templates_from_template_sets(TestTemplateSetContainer, template_set_keys)
272
+ templates = TestTemplateSetContainer.generator.load_templates_from_template_sets(template_set_keys)
274
273
 
275
274
  assert_equal 6, templates.size
276
275
  assert_equal %w(template_set_1:attribute.java template_set_1:entity.java template_set_1:repository1.java template_set_1:unit.java template_set_4:attribute4.java template_set_4:repository4.java),
@@ -16,7 +16,7 @@ class Reality::Generators::TestRubyTemplate < Reality::TestCase
16
16
  template_set = Reality::Generators::TemplateSet.new(TestTemplateSetContainer, 'foo')
17
17
 
18
18
  output_filename_pattern = 'main/java/#{component.name}.java'
19
- template_filename = File.expand_path(File.dirname(__FILE__) + '/templates/rubytemplate.rb')
19
+ template_filename = File.expand_path(File.dirname(__FILE__) + '/jpa/templates/rubytemplate.java.rb')
20
20
  TestTemplateSetContainer.target_manager.target(:component)
21
21
 
22
22
  template1 = Reality::Generators::RubyTemplate.new(template_set, [], :component, template_filename, output_filename_pattern, [], {})
@@ -30,7 +30,7 @@ class Reality::Generators::TestRubyTemplate < Reality::TestCase
30
30
  assert_equal template_filename, template1.template_key
31
31
  assert_equal nil, template1.guard
32
32
  assert_equal({}, template1.extra_data)
33
- assert_equal 'foo:rubytemplate', template1.name
33
+ assert_equal 'foo:rubytemplate.java', template1.name
34
34
 
35
35
  target_basedir = "#{temp_dir}/generated/ruby_template"
36
36
  target_filename = "#{target_basedir}/main/java/SimpleModel.java"
@@ -0,0 +1,216 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+ require File.expand_path('../jpa/model', __FILE__)
3
+
4
+ class Reality::Generators::TestStandardArtifactDSL < Reality::TestCase
5
+ def test_artifact_with_erb_template
6
+ TestTemplateSetContainer.target_manager.target(:entity)
7
+
8
+ TestFacetExtension.define_artifacts1
9
+
10
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
11
+
12
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
13
+
14
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
15
+
16
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
17
+
18
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
19
+
20
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
21
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.qualified_name}.java'
22
+ assert_equal template_set, mytemplate.template_set
23
+ assert_equal [:jpa], mytemplate.facets
24
+ assert_equal :entity, mytemplate.target
25
+ assert_equal [], mytemplate.helpers
26
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
27
+ assert_equal nil, mytemplate.guard
28
+ assert_equal({}, mytemplate.extra_data)
29
+ end
30
+
31
+ def test_artifact_with_ruby_template
32
+ TestTemplateSetContainer.target_manager.target(:entity)
33
+
34
+ TestFacetExtension.define_artifacts2
35
+
36
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
37
+
38
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
39
+
40
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
41
+
42
+ assert_equal true, template_set.template_by_name?('jpa_models:rubytemplate.java')
43
+
44
+ mytemplate = template_set.template_by_name('jpa_models:rubytemplate.java')
45
+
46
+ assert_equal mytemplate.name, 'jpa_models:rubytemplate.java'
47
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.qualified_name}.java'
48
+ assert_equal template_set, mytemplate.template_set
49
+ assert_equal [:jpa], mytemplate.facets
50
+ assert_equal :entity, mytemplate.target
51
+ assert_equal [], mytemplate.helpers
52
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/rubytemplate.java.rb"), mytemplate.template_key
53
+ assert_equal nil, mytemplate.guard
54
+ assert_equal({}, mytemplate.extra_data)
55
+ end
56
+
57
+ def test_artifact_with_options
58
+ TestTemplateSetContainer.target_manager.target(:entity)
59
+
60
+ TestFacetExtension.define_artifacts3
61
+
62
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
63
+
64
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
65
+
66
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
67
+
68
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
69
+
70
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
71
+
72
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
73
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.qualified_name}.java'
74
+ assert_equal template_set, mytemplate.template_set
75
+ assert_equal [:jpa, :ee], mytemplate.facets
76
+ assert_equal :entity, mytemplate.target
77
+ assert_equal [TestFacetExtension::MyHelperModule], mytemplate.helpers
78
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
79
+ assert_equal 'entity.jpa.good?', mytemplate.guard
80
+ assert_equal({}, mytemplate.extra_data)
81
+ end
82
+
83
+ def test_artifact_with_default_helpers
84
+ TestTemplateSetContainer.target_manager.target(:entity)
85
+
86
+ TestTemplateSetContainer.helpers = [TestFacetExtension::MyHelperModule]
87
+
88
+ TestFacetExtension.define_artifacts4
89
+
90
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
91
+
92
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
93
+
94
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
95
+
96
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
97
+
98
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
99
+
100
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
101
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.qualified_name}.java'
102
+ assert_equal template_set, mytemplate.template_set
103
+ assert_equal [:jpa], mytemplate.facets
104
+ assert_equal :entity, mytemplate.target
105
+ assert_equal [TestFacetExtension::MyHelperModule], mytemplate.helpers
106
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
107
+ assert_equal nil, mytemplate.guard
108
+ assert_equal({}, mytemplate.extra_data)
109
+ end
110
+
111
+ def test_multiple_artifact_definitions
112
+ TestTemplateSetContainer.target_manager.target(:entity)
113
+
114
+ TestFacetExtension.define_artifacts5
115
+
116
+ assert_equal TestTemplateSetContainer.template_sets.size, 2
117
+
118
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
119
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_qa_models), true
120
+
121
+ template_set1 = TestTemplateSetContainer.template_set_by_name(:jpa_models)
122
+ assert_equal 1, template_set1.templates.size
123
+ assert_equal true, template_set1.template_by_name?('jpa_models:mytemplate.java')
124
+
125
+ template_set2 = TestTemplateSetContainer.template_set_by_name(:jpa_qa_models)
126
+ assert_equal 2, template_set2.templates.size
127
+ assert_equal true, template_set2.template_by_name?('jpa_qa_models:mytemplate.java')
128
+ assert_equal true, template_set2.template_by_name?('jpa_qa_models:rubytemplate.java')
129
+ end
130
+
131
+ def test_artifact_bad_option
132
+ TestTemplateSetContainer.target_manager.target(:entity)
133
+
134
+ assert_generator_error("Unknown option ':bad_option' passed to define artifact") do
135
+ TestFacetExtension.define_artifacts6
136
+ end
137
+ end
138
+
139
+ def test_java_artifact
140
+ TestTemplateSetContainer.target_manager.target(:entity)
141
+
142
+ TestFacetExtension.define_artifacts7
143
+
144
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
145
+
146
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
147
+
148
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
149
+
150
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
151
+
152
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
153
+
154
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
155
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.jpa.qualified_mytemplate_name.gsub(".","/")}.java'
156
+ assert_equal template_set, mytemplate.template_set
157
+ assert_equal [:jpa], mytemplate.facets
158
+ assert_equal :entity, mytemplate.target
159
+ assert_equal [], mytemplate.helpers
160
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
161
+ assert_equal nil, mytemplate.guard
162
+ assert_equal({}, mytemplate.extra_data)
163
+ end
164
+
165
+ def test_test_java_artifact
166
+ TestTemplateSetContainer.target_manager.target(:entity)
167
+
168
+ TestFacetExtension.define_artifacts8
169
+
170
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
171
+
172
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
173
+
174
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
175
+
176
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
177
+
178
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
179
+
180
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
181
+ assert_equal mytemplate.output_filename_pattern, 'test/java/#{entity.jpa.qualified_mytemplate_name.gsub(".","/")}.java'
182
+ assert_equal template_set, mytemplate.template_set
183
+ assert_equal [:jpa], mytemplate.facets
184
+ assert_equal :entity, mytemplate.target
185
+ assert_equal [], mytemplate.helpers
186
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
187
+ assert_equal nil, mytemplate.guard
188
+ assert_equal({}, mytemplate.extra_data)
189
+ end
190
+
191
+ def test_main_java_artifact
192
+ TestTemplateSetContainer.target_manager.target(:entity)
193
+
194
+ TestFacetExtension.define_artifacts9
195
+
196
+ assert_equal TestTemplateSetContainer.template_sets.size, 1
197
+
198
+ assert_equal TestTemplateSetContainer.template_set_by_name?(:jpa_models), true
199
+
200
+ template_set = TestTemplateSetContainer.template_set_by_name(:jpa_models)
201
+
202
+ assert_equal true, template_set.template_by_name?('jpa_models:mytemplate.java')
203
+
204
+ mytemplate = template_set.template_by_name('jpa_models:mytemplate.java')
205
+
206
+ assert_equal mytemplate.name, 'jpa_models:mytemplate.java'
207
+ assert_equal mytemplate.output_filename_pattern, 'main/java/#{entity.jpa.qualified_mytemplate_name.gsub(".","/")}.java'
208
+ assert_equal template_set, mytemplate.template_set
209
+ assert_equal [:jpa], mytemplate.facets
210
+ assert_equal :entity, mytemplate.target
211
+ assert_equal [], mytemplate.helpers
212
+ assert_equal File.expand_path("#{File.dirname(__FILE__)}/jpa/templates/mytemplate.java.erb"), mytemplate.template_key
213
+ assert_equal nil, mytemplate.guard
214
+ assert_equal({}, mytemplate.extra_data)
215
+ end
216
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../../helper', __FILE__)
2
+
3
+ class Reality::Generators::TestStandardTemplateSet < Reality::TestCase
4
+ def test_template_set
5
+ TestTemplateSetContainer.target_manager.target(:component)
6
+
7
+ template_set =
8
+ Reality::Generators::StandardTemplateSet.new(TestTemplateSetContainer,
9
+ :iris_entity,
10
+ :description => 'Templates that generate iris entities') do |t|
11
+
12
+ t.erb_template([], :component, 'jpa/templates/mytemplate.java.erb', 'src/main/#{component.name}')
13
+ t.ruby_template([], :component, 'jpa/templates/rubytemplate.java.rb', 'src/main/#{component.name}2')
14
+ end
15
+
16
+
17
+ assert_equal :iris_entity, template_set.name
18
+ assert_equal [], template_set.required_template_sets
19
+ assert_equal 2, template_set.templates.size
20
+ assert_equal 'Templates that generate iris entities', template_set.description
21
+ assert_equal true, template_set.template_by_name?('iris_entity:rubytemplate.java')
22
+ assert_equal true, template_set.template_by_name?('iris_entity:mytemplate.java')
23
+ end
24
+ end
@@ -49,9 +49,9 @@ class Reality::Generators::TestTargetManager < Reality::TestCase
49
49
  assert_equal nil, target1.facet_key
50
50
  assert_equal true, target1.standard?
51
51
 
52
- assert_raise_message('Attempting to redefine target project') { Reality::Generators::Target.new(target_manager, :project, nil, {}) }
52
+ assert_generator_error('Attempting to redefine target project') { Reality::Generators::Target.new(target_manager, :project, nil, {}) }
53
53
 
54
- assert_raise_message("Target 'foo' defines container as 'bar' but no such target exists.") { Reality::Generators::Target.new(target_manager, :foo, :bar, {}) }
54
+ assert_generator_error("Target 'foo' defines container as 'bar' but no such target exists.") { Reality::Generators::Target.new(target_manager, :foo, :bar, {}) }
55
55
  end
56
56
 
57
57
  def test_target_manager_basic_operation
@@ -84,6 +84,6 @@ class Reality::Generators::TestTargetManager < Reality::TestCase
84
84
  assert_equal 1, target_manager.targets_by_container(:project).size
85
85
  assert_equal :component, target_manager.targets_by_container(:project)[0].key
86
86
 
87
- assert_raise_message("Can not find target with key 'foo'") { target_manager.target_by_key(:foo) }
87
+ assert_generator_error("Can not find target with key 'foo'") { target_manager.target_by_key(:foo) }
88
88
  end
89
89
  end
@@ -64,12 +64,12 @@ class Reality::Generators::TestTemplate < Reality::TestCase
64
64
  name = 'Foo'
65
65
  options = {:guard => guard, :name => name, :extra_data => extra_data}
66
66
 
67
- assert_raise_message('Unexpected facets: "X"') {
67
+ assert_generator_error('Unexpected facets: "X"') do
68
68
  Reality::Generators::Template.new(template_set, 'X', target, template_key, helpers, options)
69
- }
70
- assert_raise_message("Unknown target 'component' for template 'someMagicKey'. Valid targets include: ") {
69
+ end
70
+ assert_generator_error("Unknown target 'component' for template 'someMagicKey'. Valid targets include: ") do
71
71
  Reality::Generators::Template.new(template_set, facets, target, template_key, helpers, options)
72
- }
72
+ end
73
73
 
74
74
  TestTemplateSetContainer.target_manager.target(target)
75
75
 
@@ -85,7 +85,7 @@ class Reality::Generators::TestTemplate < Reality::TestCase
85
85
  assert_equal name, template1.name
86
86
  assert_equal name, template1.to_s
87
87
 
88
- assert_raise_message('output_path unimplemented') { template1.output_path }
88
+ assert_generator_error('output_path unimplemented') { template1.output_path }
89
89
 
90
90
  render_context = template1.send(:create_context, 'SomeValue')
91
91
 
@@ -116,6 +116,10 @@ class Reality::Generators::TestTemplate < Reality::TestCase
116
116
  end
117
117
 
118
118
  class StringTemplate < Reality::Generators::SingleFileOutputTemplate
119
+ def template_extension
120
+ 'erb'
121
+ end
122
+
119
123
  def render_to_string(context_binding)
120
124
  'X'
121
125
  end
@@ -125,7 +129,7 @@ class Reality::Generators::TestTemplate < Reality::TestCase
125
129
  template_set = Reality::Generators::TemplateSet.new(TestTemplateSetContainer, 'foo')
126
130
 
127
131
  output_filename_pattern = 'main/java/#{component.name}.java'
128
- template_key = 'MyFiles/templates/foo.erb.java'
132
+ template_key = 'MyFiles/templates/foo.java.erb'
129
133
  TestTemplateSetContainer.target_manager.target(:component)
130
134
 
131
135
  template1 = StringTemplate.new(template_set, [], :component, template_key, output_filename_pattern, [], {})
@@ -139,7 +143,7 @@ class Reality::Generators::TestTemplate < Reality::TestCase
139
143
  assert_equal template_key, template1.template_key
140
144
  assert_equal nil, template1.guard
141
145
  assert_equal({}, template1.extra_data)
142
- assert_equal 'foo:MyFiles/templates/foo.erb.java', template1.name
146
+ assert_equal 'foo:foo.java', template1.name
143
147
 
144
148
  target_basedir = "#{temp_dir}/generated/single_file_template"
145
149
  target_filename = "#{target_basedir}/main/java/SimpleModel.java"
@@ -4,11 +4,11 @@ class Reality::Generators::TestTemplateSet < Reality::TestCase
4
4
  def test_template_set
5
5
  TestTemplateSetContainer.target_manager.target(:component)
6
6
 
7
- assert_raise_message("TemplateSet 'iris_entity' defined requirement on template set 'iris_shared' that does not exist.") {
7
+ assert_generator_error("TemplateSet 'iris_entity' defined requirement on template set 'iris_shared' that does not exist.") do
8
8
  Reality::Generators::TemplateSet.new(TestTemplateSetContainer,
9
9
  :iris_entity,
10
10
  :required_template_sets => [:iris_shared])
11
- }
11
+ end
12
12
 
13
13
  template_set1 = Reality::Generators::TemplateSet.new(TestTemplateSetContainer, :iris_shared)
14
14
 
@@ -31,7 +31,7 @@ class Reality::Generators::TestTemplateSet < Reality::TestCase
31
31
  template = Reality::Generators::ErbTemplate.new(template_set2,
32
32
  [],
33
33
  :component,
34
- 'templates/mytemplate.java.erb',
34
+ 'jpa/templates/mytemplate.java.erb',
35
35
  'src/main/#{component.name}',
36
36
  [],
37
37
  {})
@@ -39,15 +39,14 @@ class Reality::Generators::TestTemplateSet < Reality::TestCase
39
39
  assert_equal true, template_set2.template_by_name?(template.name)
40
40
  assert_equal template, template_set2.template_by_name(template.name)
41
41
 
42
- assert_raise_message('Template already exists with specified name iris_entity:templates/mytemplate.java.erb') {
42
+ assert_generator_error('Template already exists with specified name iris_entity:mytemplate.java') do
43
43
  Reality::Generators::ErbTemplate.new(template_set2,
44
44
  [],
45
45
  :component,
46
- 'templates/mytemplate.java.erb',
46
+ 'jpa/templates/mytemplate.java.erb',
47
47
  'src/main/#{component.name}',
48
48
  [],
49
49
  {})
50
- }
51
-
50
+ end
52
51
  end
53
52
  end
@@ -4,13 +4,13 @@ class Reality::Generators::TestTemplateSetContainer < Reality::TestCase
4
4
  def test_template_set_container
5
5
  assert_equal 0, TestTemplateSetContainer.template_sets.size
6
6
  assert_equal false, TestTemplateSetContainer.template_set_by_name?(:foo)
7
- assert_raise_message('Unable to locate template_set foo') { TestTemplateSetContainer.template_set_by_name(:foo) }
7
+ assert_generator_error('Unable to locate template_set foo') { TestTemplateSetContainer.template_set_by_name(:foo) }
8
8
 
9
- assert_raise_message("TemplateSet 'iris_entity' defined requirement on template set 'iris_shared' that does not exist.") {
9
+ assert_generator_error("TemplateSet 'iris_entity' defined requirement on template set 'iris_shared' that does not exist.") do
10
10
  Reality::Generators::TemplateSet.new(TestTemplateSetContainer,
11
11
  :iris_entity,
12
12
  :required_template_sets => [:iris_shared])
13
- }
13
+ end
14
14
 
15
15
  template_set1 = TestTemplateSetContainer.template_set(:foo)
16
16
 
data/test/helper.rb CHANGED
@@ -6,26 +6,24 @@ require 'reality/generators'
6
6
 
7
7
  class Reality::TestCase < Minitest::Test
8
8
  include Test::Unit::Assertions
9
-
10
- module TestGenerator
11
- class << self
12
- include Reality::Generators::Generator
13
- end
14
- end
9
+ include Reality::Logging::Assertions
15
10
 
16
11
  module TestTemplateSetContainer
17
12
  class << self
18
13
  include Reality::Generators::TemplateSetContainer
19
14
 
20
- def new_template_set(name, options, &block)
21
- Reality::Generators::TemplateSet.new(self, name, options, &block)
15
+ def derive_default_helpers(options)
16
+ helpers
22
17
  end
23
18
 
24
- def new_generator
25
- TestGenerator
19
+ attr_writer :helpers
20
+
21
+ def helpers
22
+ @helpers ||= []
26
23
  end
27
24
 
28
25
  def reset
26
+ helpers.clear
29
27
  template_set_map.clear
30
28
  target_manager.reset_targets
31
29
  end
@@ -52,4 +50,10 @@ class Reality::TestCase < Minitest::Test
52
50
  end
53
51
  @temp_dir
54
52
  end
53
+
54
+ def assert_generator_error(expected_message, &block)
55
+ assert_logging_error(Reality::Generators, expected_message) do
56
+ yield block
57
+ end
58
+ end
55
59
  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.3.0
4
+ version: 1.5.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: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reality-core
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.0
19
+ version: 1.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.0
26
+ version: 1.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: reality-naming
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: 1.6.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: 1.6.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: reality-orderedhash
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -102,17 +102,22 @@ files:
102
102
  - lib/reality/generators/generator.rb
103
103
  - lib/reality/generators/render_context.rb
104
104
  - lib/reality/generators/ruby_template.rb
105
+ - lib/reality/generators/standard_artifact_dsl.rb
106
+ - lib/reality/generators/standard_template_set.rb
105
107
  - lib/reality/generators/target_manager.rb
106
108
  - lib/reality/generators/template.rb
107
109
  - lib/reality/generators/template_set.rb
108
110
  - lib/reality/generators/template_set_container.rb
109
111
  - reality-generators.gemspec
110
- - test/generators/templates/mytemplate.java.erb
111
- - test/generators/templates/rubytemplate.rb
112
+ - test/generators/jpa/model.rb
113
+ - test/generators/jpa/templates/mytemplate.java.erb
114
+ - test/generators/jpa/templates/rubytemplate.java.rb
112
115
  - test/generators/test_erb_template.rb
113
116
  - test/generators/test_generator.rb
114
117
  - test/generators/test_render_context.rb
115
118
  - test/generators/test_ruby_template.rb
119
+ - test/generators/test_standard_artifact_dsl.rb
120
+ - test/generators/test_standard_template_set.rb
116
121
  - test/generators/test_target_manager.rb
117
122
  - test/generators/test_template.rb
118
123
  - test/generators/test_template_set.rb