sprout 1.0.20.pre → 1.0.22.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

@@ -213,6 +213,7 @@ module Sprout
213
213
  def prepare_command
214
214
  @logger ||= $stdout
215
215
  @command = Command.new self
216
+ @command.logger = logger
216
217
  manifest
217
218
  @command
218
219
  end
@@ -230,10 +231,7 @@ module Sprout
230
231
  end
231
232
 
232
233
  def generator name, options={}
233
- instance = Sprout::Generator.create_instance name, options
234
- instance.from_hash to_hash.merge(options)
235
- instance.logger = logger
236
- instance.execute
234
+ @command.generator name, to_hash.merge(options)
237
235
  end
238
236
 
239
237
  private
@@ -4,8 +4,6 @@ module Sprout::Generator
4
4
  attr_accessor :logger
5
5
  attr_accessor :working_dir
6
6
 
7
- attr_reader :generator
8
-
9
7
  def initialize generator
10
8
  @generator = generator
11
9
  @working_dir = DirectoryManifest.new
@@ -16,42 +14,49 @@ module Sprout::Generator
16
14
  def directory path, &block
17
15
  raise Sprout::Errors::GeneratorError.new "Cannot create directory with nil path" if path.nil?
18
16
  manifest = DirectoryManifest.new
19
- manifest.generator = generator
17
+ manifest.generator = @generator
20
18
  manifest.path = File.join(@working_dir.path, path)
21
19
  @working_dir.children << manifest
22
- parent = @working_dir
23
- @working_dir = manifest
20
+ parent = @working_dir
21
+ @working_dir = manifest
24
22
  yield if block_given?
25
- @working_dir = parent
23
+ @working_dir = parent
26
24
  end
27
25
 
28
26
  def template path, template=nil
29
27
  raise Sprout::Errors::GeneratorError.new "Cannot create file with nil path" if path.nil?
30
28
  manifest = TemplateManifest.new
31
- manifest.generator = generator
29
+ manifest.generator = @generator
32
30
  manifest.path = File.join( working_dir.path, path )
33
31
  manifest.template = template
34
- manifest.templates = generator.template_paths
32
+ manifest.templates = @generator.template_paths
35
33
  working_dir.children << manifest
36
34
  end
37
35
 
38
36
  def file path, template=nil
39
- raise Sprout::Errors::GeneratorError.new "Cannot create file with nil path" if path.nil?
37
+ raise sprout::errors::generatorerror.new "Cannot create file with nil path" if path.nil?
40
38
  manifest = FileManifest.new
41
- manifest.generator = generator
39
+ manifest.generator = @generator
42
40
  manifest.path = File.join( working_dir.path, path )
43
41
  manifest.template = template
44
- manifest.templates = generator.template_paths
42
+ manifest.templates = @generator.template_paths
45
43
  working_dir.children << manifest
46
44
  end
47
45
 
46
+ def generator name, options={}
47
+ raise sprout::errors::generatorerror.new "Cannot call another generator with nil name" if name.nil?
48
+ instance = Sprout::Generator.create_instance name, options
49
+ instance.logger = logger
50
+ instance.path = working_dir.path
51
+ instance.from_hash options
52
+ working_dir.generators << instance
53
+ end
54
+
48
55
  def execute
49
56
  begin
50
- working_dir.children.each do |child|
51
- child.create
52
- end
57
+ working_dir.create
53
58
  rescue StandardError => e
54
- generator.say "[#{e.class}] #{e.message}"
59
+ @generator.say "[#{e.class}] #{e.message}"
55
60
  working_dir.children.each do |child|
56
61
  child.destroy
57
62
  end
@@ -1,10 +1,12 @@
1
1
  module Sprout::Generator
2
2
  class DirectoryManifest < Manifest
3
3
  attr_reader :children
4
+ attr_reader :generators
4
5
 
5
6
  def initialize
6
7
  super
7
8
  @children = []
9
+ @generators = []
8
10
  end
9
11
 
10
12
  def create
@@ -12,12 +14,14 @@ module Sprout::Generator
12
14
  FileUtils.mkdir_p path
13
15
  say "Created directory: #{path}"
14
16
  else
15
- say "Skipped existing: #{path}"
17
+ say "Skipped existing: #{path}" unless(path == Dir.pwd)
16
18
  end
17
19
  create_children
20
+ execute_generators
18
21
  end
19
22
 
20
23
  def destroy
24
+ unexecute_generators
21
25
  success = destroy_children
22
26
 
23
27
  if success && can_remove?
@@ -45,5 +49,18 @@ module Sprout::Generator
45
49
  destroyed = children.reverse.select { |child| child.destroy }
46
50
  return (destroyed.size == children.size)
47
51
  end
52
+
53
+ def execute_generators
54
+ generators.each do |generator|
55
+ generator.execute
56
+ end
57
+ end
58
+
59
+ def unexecute_generators
60
+ generators.each do |generator|
61
+ generator.unexecute
62
+ end
63
+ end
64
+
48
65
  end
49
66
  end
@@ -30,7 +30,6 @@ class <%= input.camel_case %>GeneratorTest < Test::Unit::TestCase
30
30
  assert_file input_file do |content|
31
31
  assert_matches /Your content to assert here/, content
32
32
  end
33
-
34
33
  end
35
34
 
36
35
  end
@@ -6,7 +6,7 @@ module Sprout
6
6
  module VERSION #:nodoc:
7
7
  MAJOR = 1
8
8
  MINOR = 0
9
- TINY = 20
9
+ TINY = 22
10
10
  RELEASE = 'pre'
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, RELEASE].join('.')
@@ -103,6 +103,7 @@ class GeneratorTest < Test::Unit::TestCase
103
103
 
104
104
  should "notify user of all files created" do
105
105
  @generator.input = 'some_project'
106
+ @string_io.expects(:puts).with('Skipped existing: .')
106
107
  @string_io.expects(:puts).with('Created directory: ./some_project')
107
108
  @string_io.expects(:puts).with('Created file: ./some_project/SomeFile')
108
109
  @string_io.expects(:puts).with('Created file: ./some_project/SomeOtherFile')
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 20
8
+ - 22
9
9
  - pre
10
- version: 1.0.20.pre
10
+ version: 1.0.22.pre
11
11
  platform: ruby
12
12
  authors:
13
13
  - Luke Bayes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-04 00:00:00 -07:00
18
+ date: 2010-07-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -270,7 +270,6 @@ files:
270
270
  - script/console
271
271
  - script/destroy
272
272
  - script/generate
273
- - sprout-1.0.20.pre.gem
274
273
  - sprout.gemspec
275
274
  - test/fixtures/archive_unpacker/copyable/some_file.exe
276
275
  - test/fixtures/archive_unpacker/copyable/some_file.rb