sprout 0.7.153-darwin

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.

@@ -0,0 +1,35 @@
1
+
2
+ module Sprout
3
+
4
+ # accepts a destination path and a sprout specification
5
+ # and will download and unpack the platform-specific
6
+ # archives that are identified in the spec
7
+ class Builder # :nodoc:
8
+
9
+ class BuilderError < StandardError #:nodoc:
10
+ end
11
+
12
+ def self.build(file_targets_yaml, destination)
13
+ data = nil
14
+
15
+ File.open(file_targets_yaml, 'r') do |f|
16
+ data = f.read
17
+ end
18
+
19
+ usr = User.new
20
+ platform = usr.platform.to_s
21
+
22
+ targets = YAML.load(data)
23
+ targets.each do |target|
24
+ if(target.platform == 'universal' || target.platform == platform)
25
+ target.install_path = FileUtils.mkdir_p(destination)
26
+ target.resolve
27
+ return target
28
+ end
29
+ end
30
+ raise BuilderError.new("Sprout::Builder.build failed, unsupported platform or unexpected yaml")
31
+ end
32
+
33
+ end
34
+ end
35
+
@@ -0,0 +1,14 @@
1
+ # Shamelessly copied from Ruby On Rails
2
+ # Which happens to share the same MIT license!
3
+
4
+ =begin
5
+ #require "#{RAILS_ROOT}/config/environment"
6
+ require 'rubygems'
7
+ gem 'activesupport', '>= 2.0.2'
8
+ require 'generator'
9
+ #require 'generator/scripts/generate'
10
+ require 'sprout'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ Rails::Generator::Scripts::Generate.new.run(ARGV)
14
+ =end
@@ -0,0 +1,5 @@
1
+
2
+ require 'sprout/tasks/sftp_task'
3
+ require 'sprout/tasks/zip_task'
4
+ require 'sprout/tasks/gem_wrap_task'
5
+ require 'sprout/tasks/library_task'
@@ -0,0 +1,6 @@
1
+ gem 'activesupport', '>= 2.0.2'
2
+ require 'rails_generator'
3
+ require 'sprout/generator/base_mixins'
4
+ require 'sprout/generator/named_base'
5
+
6
+ # This is the entry point for sprout generator features
@@ -0,0 +1,132 @@
1
+
2
+ module Rails # :nodoc:[all]
3
+ module Generator # :nodoc:[all]
4
+
5
+ class Base # :nodoc:[all]
6
+
7
+ def initialize(runtime_args, runtime_options = {})
8
+ @args = runtime_args
9
+ parse!(@args, runtime_options)
10
+
11
+ # Derive source and destination paths.
12
+ @source_root = options[:source] || File.join(spec.path, 'templates')
13
+
14
+ if options[:destination]
15
+ @destination_root = options[:destination]
16
+ # The following two lines were changed:
17
+ #elsif defined? ::RAILS_ROOT
18
+ # @destination_root = ::RAILS_ROOT
19
+ elsif defined? Sprout::Sprout.project_path
20
+ @destination_root = Sprout::Sprout.project_path
21
+ else
22
+ @destination_root = Dir.pwd
23
+ end
24
+
25
+ # Silence the logger if requested.
26
+ logger.quiet = options[:quiet]
27
+
28
+ # Raise usage error if help is requested.
29
+ usage if options[:help]
30
+ end
31
+
32
+ end
33
+
34
+ # GemGeneratorSource hits the mines to quarry for generators. The latest versions
35
+ # of gems named sprout-#{sprout_name}-bundle are selected.
36
+ class GemGeneratorSource < AbstractGemSource # :nodoc:[all]
37
+
38
+ def initialize(name=nil)
39
+ super()
40
+ @sprout_name = name
41
+ end
42
+
43
+ # Yield latest versions of generator gems.
44
+ def each
45
+ Gem::cache.search(/sprout-*#{@sprout_name}-bundle$/).inject({}) { |latest, gem|
46
+ hem = latest[gem.name]
47
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
48
+ latest
49
+ }.values.each { |gem|
50
+ yield Spec.new(gem.name.sub(/sprout-*#{@sprout_name}-bundle$/, ''), gem.full_gem_path, label)
51
+ }
52
+ end
53
+
54
+ def each_sprout
55
+ Gem::cache.search(/^sprout-.*/).inject({}) { |latest, gem|
56
+ hem = latest[gem.name]
57
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
58
+ latest
59
+ }.values.each { |gem|
60
+ yield Spec.new(gem.name, gem.full_gem_path, label)
61
+ }
62
+ end
63
+ end
64
+
65
+ # GemPathSource looks for generators within any RubyGem's
66
+ # /sprout/generators/<generator_name>/<generator_name>_generator.rb file.
67
+ # It will only include generators from sprouts whose name includes
68
+ # #{sprout_name}-bundle
69
+ class GemPathSource < AbstractGemSource # :nodoc:[all]
70
+
71
+ def initialize(name=nil)
72
+ super()
73
+ @sprout_name = name
74
+ end
75
+
76
+ # Yield each generator within rails_generator subdirectories.
77
+ def each
78
+ generator_full_paths.each do |generator|
79
+ yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label)
80
+ end
81
+ end
82
+
83
+ private
84
+ def generator_full_paths
85
+ @generator_full_paths ||=
86
+ Gem::cache.inject({}) do |latest, name_gem|
87
+ name, gem = name_gem
88
+ hem = latest[gem.name]
89
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
90
+ latest
91
+ end.values.inject([]) do |mem, gem|
92
+ Dir[gem.full_gem_path + '/lib/sprout/**/generators/**/*_generator.rb'].each do |generator|
93
+ if(@sprout_name && gem.name.match(/sprout-#{@sprout_name}-bundle/))
94
+ mem << generator
95
+ end
96
+ end
97
+ mem
98
+ end
99
+ end
100
+ end
101
+
102
+ module Lookup # :nodoc:[all]
103
+ module ClassMethods # :nodoc:[all]
104
+
105
+ def use_sprout_sources!(sprout_name, project_path=nil)
106
+ reset_sources
107
+
108
+ # Project-specific generator paths
109
+ if project_path
110
+ sources << PathSource.new(:project, "#{project_path}/generators")
111
+ sources << PathSource.new(:script, "#{project_path}/script/generators")
112
+ sources << PathSource.new(:vendor, "#{project_path}/vendor/generators")
113
+ end
114
+
115
+ # System-wide generator paths
116
+ system_path = "#{Sprout::Sprout.sprout_cache}/generators/#{sprout_name}"
117
+ if(File.exists?(system_path))
118
+ sources << PathSource.new(:system, system_path)
119
+ end
120
+
121
+ # Gem generators will collect all
122
+ # rubygems that end with -bundle or -generators
123
+ if(Object.const_defined?(:Gem))
124
+ sources << GemGeneratorSource.new(sprout_name)
125
+ sources << GemPathSource.new(sprout_name)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ end
132
+ end
@@ -0,0 +1,216 @@
1
+
2
+ module Sprout
3
+ module Generator #:nodoc:
4
+
5
+ class NamedBaseError < StandardError #:nodoc:
6
+ end
7
+
8
+ # The NamedBase is a good default base class for ActionScript class Generators.
9
+ # This class will accept the first command line argument and create
10
+ # many helpful properties for concrete generators to use.
11
+ #
12
+ # Can accept class names in following formats:
13
+ # * src/package/package/ClassName.as
14
+ # * test/package/package/ClassName.as
15
+ # * package/package/ClassName
16
+ # * package.package.ClassName
17
+ #
18
+ # Regardless of which format the name was sent in, the helper
19
+ # methods should provide valid results
20
+ #
21
+ class NamedBase < Rails::Generator::Base
22
+
23
+ # Fully qualified class named including package name like 'flash.display.Sprite'
24
+ attr_reader :full_class_name
25
+ # Path to the class file relative to your src_dir like 'flash/display/Sprite.as'
26
+ attr_reader :class_file
27
+ # The directory that contains the file, relative to your src_dir like 'flash/diplay'
28
+ attr_reader :class_dir
29
+ # The unqualified name of the class like 'Sprite'
30
+ attr_reader :class_name
31
+ # The package name of the class like 'flash.display'
32
+ attr_reader :package_name
33
+
34
+ def initialize(runtime_args, runtime_options = {})
35
+ super
36
+
37
+ rakefile = Sprout.project_rakefile
38
+ if(rakefile && File.exists?(rakefile))
39
+ load rakefile
40
+ end
41
+ @model = ProjectModel.instance
42
+
43
+ # Had to stop throwing on no args because the suite generator does
44
+ # not require the user to send in a class name....
45
+ #usage("Final argument must be a name parameter") if runtime_args.empty?
46
+ @args = runtime_args.dup
47
+ assign_names! @args.shift
48
+ end
49
+
50
+ # Quick access to the source directory identified by your project model
51
+ def src_dir
52
+ return model.src_dir
53
+ end
54
+
55
+ # Quick access to the test directory identified by your project model
56
+ def test_dir
57
+ return model.test_dir
58
+ end
59
+
60
+ # Quick access to the library directory identified by your project model
61
+ def lib_dir
62
+ return model.lib_dir
63
+ end
64
+
65
+ # The path to your project. This will either be the directory from which
66
+ # the sprout gem was executed, or the nearest ancestor directory that
67
+ # contains a properly named rakefile.
68
+ def project_path
69
+ return model.project_path
70
+ end
71
+
72
+ # The project_name that was either sent to the sprout gem or
73
+ # defined in your rakefile project model
74
+ def project_name
75
+ @project_name ||= (Sprout.project_name || model.project_name)
76
+ end
77
+
78
+ # The technology language that is stored in your project model usually (as2 or as3)
79
+ def language
80
+ return model.language
81
+ end
82
+
83
+ # Name of possible test case for this class_name
84
+ def test_case_name
85
+ @test_case_name ||= class_name + 'Test'
86
+ end
87
+
88
+ # Full name of the possible test case for this class_name
89
+ def full_test_case_name
90
+ full_class_name + 'Test'
91
+ end
92
+
93
+ # Full path to the parent directory that contains the class
94
+ # like 'src/flash/display' for flash.display.Sprite class.
95
+ def full_class_dir
96
+ @full_class_dir ||= File.join(src_dir, class_dir)
97
+ # pull trailing slash for classes in the root package
98
+ @full_class_dir.gsub!(/\/$/, '')
99
+ @full_class_dir
100
+ end
101
+
102
+ # Full path to the class file from your project_path like 'src/flash/display/Sprite.as'
103
+ def full_class_path
104
+ @full_class_path ||= File.join(src_dir, class_file)
105
+ end
106
+
107
+ # Filesystem path to the folder that contains the TestCase file
108
+ def full_test_dir
109
+ @full_test_dir ||= full_class_dir.gsub(src_dir, test_dir)
110
+ end
111
+
112
+ # Filesystem path to the TestCase file
113
+ def full_test_case_path
114
+ @full_test_case_path ||= File.join(full_test_dir, test_case_name + '.as')
115
+ end
116
+
117
+ def instance_name
118
+ name = class_name.dup;
119
+ char = name[0, 1]
120
+ name[0, 1] = char.downcase
121
+ if(name.size > 10)
122
+ name = 'instance'
123
+ end
124
+ return name
125
+ end
126
+
127
+ # Will return whether the user originally requested a class name
128
+ # that looks like a test case (e.g., name.match(/Test$/) )
129
+ def user_requested_test
130
+ @user_requested_test ||= false
131
+ end
132
+
133
+ # Glob that is used to search for test cases and build
134
+ # up the test suites
135
+ def test_glob
136
+ return @test_glob ||= '**/**/*Test.as'
137
+ end
138
+
139
+ def test_glob=(glob)
140
+ @test_glob = glob
141
+ end
142
+
143
+ # Collection of all test case files either assigned or found
144
+ # using the test_glob as provided.
145
+ def test_cases
146
+ @test_cases ||= Dir.glob(test_dir + test_glob)
147
+ end
148
+
149
+ def test_cases=(collection)
150
+ @test_cases = collection
151
+ end
152
+
153
+ # Get the list of test_cases (which are files) as a
154
+ # list of fully qualified class names
155
+ def test_case_classes
156
+ @test_case_classes = self.test_cases.dup
157
+ @test_case_classes.collect! do |file|
158
+ actionscript_file_to_class_name(file)
159
+ end
160
+ @test_case_classes
161
+ end
162
+
163
+ # Transform a file name in the source or test path
164
+ # to a fully-qualified class name
165
+ def actionscript_file_to_class_name(file)
166
+ name = file.dup
167
+ name.gsub!(/^#{Dir.pwd}\//, '')
168
+ name.gsub!(/^#{test_dir}\//, '')
169
+ name.gsub!(/^#{src_dir}\//, '')
170
+ name.gsub!(/.as$/, '')
171
+ name.gsub!(/#{File::SEPARATOR}/, '.')
172
+ return name
173
+ end
174
+
175
+ protected
176
+
177
+ def banner
178
+ "Usage: #{$0} [options] packagename.ClassName"
179
+ end
180
+
181
+ def model
182
+ @model ||= ProjectModel.instance
183
+ end
184
+
185
+ def assign_names!(name)
186
+ # trim file name suffix in case it was submitted
187
+ name.gsub!(/\//, '.')
188
+ name.gsub!(/\.as$/, '')
189
+ name.gsub!(/\.mxml$/, '')
190
+ if(model)
191
+ # Pull leading src_dir from class name if submitted
192
+ name.gsub!(/^#{src_dir}\./, '')
193
+ name.gsub!(/^#{test_dir}\./, '')
194
+ end
195
+
196
+ if(name.match(/Test$/))
197
+ @user_requested_test = true
198
+ name = name.gsub(/Test$/, '')
199
+ end
200
+ if(name.match(/^I/) || name.match(/able$/))
201
+ @user_requested_interface = true
202
+ end
203
+
204
+ @full_class_name = name
205
+ parts = name.split('.')
206
+ @class_name = parts.pop
207
+ @package_name = parts.join('.')
208
+ @class_file = @full_class_name.split('.').join(File::SEPARATOR) + '.as'
209
+ @class_dir = File.dirname(@class_file)
210
+ if(@class_dir == '.')
211
+ @class_dir = ''
212
+ end
213
+ end
214
+ end
215
+ end
216
+ end
data/lib/sprout/log.rb ADDED
@@ -0,0 +1,46 @@
1
+
2
+ module Sprout #:nodoc:
3
+
4
+ class Log #:nodoc:
5
+ @@debug = false
6
+ @@output = ''
7
+ @@printout = ''
8
+
9
+ def Log.debug=(debug)
10
+ @@debug = debug
11
+ end
12
+
13
+ def Log.debug
14
+ return @@debug
15
+ end
16
+
17
+ def Log.puts(msg)
18
+ @@output << msg + "\n"
19
+ Log.flush
20
+ end
21
+
22
+ def Log.print(msg)
23
+ @@printout << msg
24
+ Log.flush_print
25
+ end
26
+
27
+ def Log.printf(msg)
28
+ @@printout << msg
29
+ Log.flush_print
30
+ end
31
+
32
+ def Log.flush_print
33
+ if(!Log.debug)
34
+ $stdout.print @@printout
35
+ @@printout = ''
36
+ end
37
+ end
38
+
39
+ def Log.flush
40
+ if(!Log.debug)
41
+ $stdout.puts @@output
42
+ @@output = ''
43
+ end
44
+ end
45
+ end
46
+ end