sprout-as2-bundle 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/README +47 -0
- data/lib/sprout/as2/version.rb +12 -0
- data/lib/sprout/as2.rb +5 -0
- data/lib/sprout/as2_tasks.rb +5 -0
- data/lib/sprout/generators/class/USAGE +42 -0
- data/lib/sprout/generators/class/class_generator.rb +35 -0
- data/lib/sprout/generators/class/templates/Class.as +10 -0
- data/lib/sprout/generators/class/templates/Component.mxml +8 -0
- data/lib/sprout/generators/class/templates/TestCase.as +30 -0
- data/lib/sprout/generators/class/templates/TestSuite.as +15 -0
- data/lib/sprout/generators/project/project_generator.rb +30 -0
- data/lib/sprout/generators/project/templates/DefaultSkin.as +7 -0
- data/lib/sprout/generators/project/templates/MainClass.as +20 -0
- data/lib/sprout/generators/project/templates/ProjectSprouts.jpg +0 -0
- data/lib/sprout/generators/project/templates/README.txt +56 -0
- data/lib/sprout/generators/project/templates/SWFMillTemplate.erb +13 -0
- data/lib/sprout/generators/project/templates/TestRunner.as +17 -0
- data/lib/sprout/generators/project/templates/generate +21 -0
- data/lib/sprout/generators/project/templates/rakefile.rb +88 -0
- data/lib/sprout/generators/suite/USAGE +0 -0
- data/lib/sprout/generators/suite/suite_generator.rb +17 -0
- data/lib/sprout/generators/suite/templates/TestSuite.as +18 -0
- data/lib/sprout/generators/test/USAGE +37 -0
- data/lib/sprout/generators/test/templates/TestCase.as +30 -0
- data/lib/sprout/generators/test/templates/TestSuite.as +18 -0
- data/lib/sprout/generators/test/test_generator.rb +20 -0
- data/lib/sprout/tasks/mtasc_doc.rb +112 -0
- data/lib/sprout/tasks/mtasc_task.rb +262 -0
- data/lib/sprout/tasks/swfmill_doc.rb +31 -0
- data/lib/sprout/tasks/swfmill_input_task.rb +135 -0
- data/lib/sprout/tasks/swfmill_task.rb +100 -0
- data/rakefile.rb +66 -0
- metadata +126 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
module Sprout
|
2
|
+
class MTASCTask
|
3
|
+
# Add a directory path to the class path. This is the list of directories that MTASC will use to look for .as files. You can add as many class_path values as you like. This parameter is an Array, so be sure to append rather than overwrite.
|
4
|
+
#
|
5
|
+
# Even though the official MTASC compiler accepts the +cp+ paramter, we have aliased it as +class_path+, you can use either name in your scripts.
|
6
|
+
#
|
7
|
+
# mtasc 'bin/SomeProject.swf' do |t|
|
8
|
+
# t.class_path << 'lib/somelib'
|
9
|
+
# t.class_path << 'lib/otherlib'
|
10
|
+
# # The following is not correct:
|
11
|
+
# # t.class_path = 'lib/somelib'
|
12
|
+
# end
|
13
|
+
def cp=(paths)
|
14
|
+
@cp = paths
|
15
|
+
end
|
16
|
+
|
17
|
+
# Exclude code generation of classes listed in specified file (format is one full class path per line).
|
18
|
+
def exclude=(file)
|
19
|
+
@exclude = file
|
20
|
+
end
|
21
|
+
|
22
|
+
# Export AS2 classes into target frame of swf.
|
23
|
+
def frame=(number)
|
24
|
+
@frame = number
|
25
|
+
end
|
26
|
+
|
27
|
+
# Merge classes into one single clip (this will reduce SWF size but might cause some problems if you're using -keep or -mx).
|
28
|
+
def group=(boolean)
|
29
|
+
@group = boolean
|
30
|
+
end
|
31
|
+
|
32
|
+
# width:height:fps:bgcolor: Create a new swf containing only compiled code and using provided header informations. bgcolor is optional and should be 6 digits hexadecimal value.
|
33
|
+
def header=(string)
|
34
|
+
@header = string
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add type inference for initialized local variables.
|
38
|
+
def infer=(boolean)
|
39
|
+
@infer = boolean
|
40
|
+
end
|
41
|
+
|
42
|
+
# Keep AS2 classes compiled by MCC into the SWF (this could cause some classes to be present two times if also compiled with MTASC).
|
43
|
+
def keep=(boolean)
|
44
|
+
@keep = boolean
|
45
|
+
end
|
46
|
+
|
47
|
+
# Will automaticaly call static function main once all classes are registered.
|
48
|
+
def main=(boolean)
|
49
|
+
@main = boolean
|
50
|
+
end
|
51
|
+
|
52
|
+
# Use Microsoft Visual Studio errors style formating instead of Java style (for file names and line numbers).
|
53
|
+
def msvc=(boolean)
|
54
|
+
@msvc = boolean
|
55
|
+
end
|
56
|
+
|
57
|
+
# Use precompiled MX classes (see section on V2 components below).
|
58
|
+
def mx=(boolean)
|
59
|
+
@mx = boolean
|
60
|
+
end
|
61
|
+
|
62
|
+
# The SWF file that should be generated, use only in addition to the -swf parameter if you want to generate a separate SWF from the one being loaded
|
63
|
+
def out=(file)
|
64
|
+
@out = file
|
65
|
+
end
|
66
|
+
|
67
|
+
# Compile all the files contained in specified package - not recursively (eg to compile files in c:lashdemypp do mtasc -cp c:lashde -pack my/app).
|
68
|
+
def pack=(paths)
|
69
|
+
@pack = paths
|
70
|
+
end
|
71
|
+
|
72
|
+
# Use strict compilation mode which require that all variables are explicitely typed.
|
73
|
+
def strict=(boolean)
|
74
|
+
@strict = boolean
|
75
|
+
end
|
76
|
+
|
77
|
+
# Specify the swf that should be generated, OR the input SWF which contains assets.
|
78
|
+
#
|
79
|
+
# If this parameter is not set, the MTASCTask will do the following:
|
80
|
+
# * Iterate over it's prerequisites and set the -swf parameter to the output of the first SWFMillTask found
|
81
|
+
# * If no SWFMillTask instances are in this task prerequisites and the -swf parameter has not been set, it will be set to the same as the -out parameter
|
82
|
+
def swf=(file)
|
83
|
+
@swf = file
|
84
|
+
end
|
85
|
+
|
86
|
+
# Specify a custom trace function. (see Trace Facilities), or no disable all the traces.
|
87
|
+
def trace=(string)
|
88
|
+
@trace = string
|
89
|
+
end
|
90
|
+
|
91
|
+
# Specify SWF version : 6 to generate Player 6r89 compatible SWF or 8 to access Flash8 features.
|
92
|
+
def version=(number)
|
93
|
+
@version = number
|
94
|
+
end
|
95
|
+
|
96
|
+
# Activate verbose mode, printing some additional information about compiling process. This parameter has been aliased as +verbose+
|
97
|
+
def v=(boolean)
|
98
|
+
@v = boolean
|
99
|
+
end
|
100
|
+
|
101
|
+
# Adds warnings for import statements that are not used in the file.
|
102
|
+
def wimp=(boolean)
|
103
|
+
@wimp = boolean
|
104
|
+
end
|
105
|
+
|
106
|
+
# Main source file to send compiler
|
107
|
+
def input=(file)
|
108
|
+
@input = file
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,262 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2007 Pattern Park
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Sprout # :nodoc:
|
25
|
+
class MTASCError < StandardError #:nodoc:
|
26
|
+
end
|
27
|
+
|
28
|
+
# Compile sources using the Motion Twin ActionScript Compiler (MTASC[http://www.mtasc.org]).
|
29
|
+
#
|
30
|
+
# Like standard Rake file tasks, the name given to the MTASCTask instance should be the
|
31
|
+
# file that the task is epected to create. This value can be overridden in the configuration
|
32
|
+
# block by using the -output parameter.
|
33
|
+
#
|
34
|
+
# mtasc 'bin/SomeProject.swf' do |t|
|
35
|
+
# t.main = true
|
36
|
+
# t.header = '800:600:24'
|
37
|
+
# t.input = 'src/SomeProject.as'
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# The above MTASCTask can be aliased for easier typing on the command line as follows:
|
41
|
+
#
|
42
|
+
# desc "Compile SomeProject.swf"
|
43
|
+
# task :compile => 'bin/SomeProject.swf'
|
44
|
+
#
|
45
|
+
# If the MTASCTask has a SWFMillTask as a prerequisite, it will automatically set that task output
|
46
|
+
# as the value of the -swf paramter. Additionally, when MTASC pulls in an existing SWF file
|
47
|
+
# you no longer need to define the -header parameter as it will use the dimensions and frame rate
|
48
|
+
# found in the loaded SWF file. If the -header parameter is set, it will override
|
49
|
+
# whatever settings are in the loaded SWF. Following is a short example:
|
50
|
+
#
|
51
|
+
# swfmill 'bin/SomeProjectSkin.swf' do |t|
|
52
|
+
# t.input = 'assets/skin'
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# mtasc 'bin/SomeProject.swf' => 'bin/SomeProjectSkin.swf' do |t|
|
56
|
+
# t.main = true
|
57
|
+
# t.input = 'src/SomeProject.as'
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# Any LibraryTask instances that are added as prerequisites to the MTASCTask will be automatically
|
61
|
+
# added to the class_path in the order they are declared as prerequisites.
|
62
|
+
#
|
63
|
+
# The following example will add the imaginary libraries :somelib, :otherlib and :yourlib to the class_path in that order.
|
64
|
+
#
|
65
|
+
# library :yourlib
|
66
|
+
# library :otherlib
|
67
|
+
# library :somelib
|
68
|
+
#
|
69
|
+
# mtasc 'bin/SomeProjectRunner.swf' => [:somelib, :otherlib, :yourlib] do |t|
|
70
|
+
# t.main = true
|
71
|
+
# t.header = '800:600:24'
|
72
|
+
# t.input = 'src/SomeProjectRunner.as'
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# <em>At this time, MTASC does not support libraries that are packaged as SWC files. We are considering
|
76
|
+
# adding support for SWC files in the near future, if you're interested in contributing to this
|
77
|
+
# feature, please let us know.</em>
|
78
|
+
#
|
79
|
+
class MTASCTask < ToolTask
|
80
|
+
|
81
|
+
# Automatically include the installation MTASC 'std' library to the class_path.
|
82
|
+
attr_accessor :include_std
|
83
|
+
|
84
|
+
def initialize_task # :nodoc:
|
85
|
+
@include_std = false
|
86
|
+
@default_gem_name = 'sprout-mtasc-tool'
|
87
|
+
|
88
|
+
add_param(:cp, :paths) do |p|
|
89
|
+
p.delimiter = ' '
|
90
|
+
p.description =<<EOF
|
91
|
+
Add a directory path to the class path. This is the list of directories that MTASC will use to look for .as files. You can add as many class_path values as you like. This parameter is an Array, so be sure to append rather than overwrite.
|
92
|
+
|
93
|
+
Even though the official MTASC compiler accepts the +cp+ paramter, we have aliased it as +class_path+, you can use either name in your scripts.
|
94
|
+
|
95
|
+
mtasc 'bin/SomeProject.swf' do |t|
|
96
|
+
t.class_path << 'lib/somelib'
|
97
|
+
t.class_path << 'lib/otherlib'
|
98
|
+
# The following is not correct:
|
99
|
+
# t.class_path = 'lib/somelib'
|
100
|
+
end
|
101
|
+
|
102
|
+
EOF
|
103
|
+
end
|
104
|
+
|
105
|
+
add_param_alias(:class_path, :cp)
|
106
|
+
|
107
|
+
add_param(:exclude, :file) do |p|
|
108
|
+
p.delimiter = ' '
|
109
|
+
p.description = "Exclude code generation of classes listed in specified file (format is one full class path per line)."
|
110
|
+
end
|
111
|
+
|
112
|
+
add_param(:frame, :number) do |p|
|
113
|
+
p.delimiter = ' '
|
114
|
+
p.description = "Export AS2 classes into target frame of swf."
|
115
|
+
end
|
116
|
+
|
117
|
+
add_param(:group, :boolean) do |p|
|
118
|
+
p.hidden_value = true
|
119
|
+
p.description = "Merge classes into one single clip (this will reduce SWF size but might cause some problems if you're using -keep or -mx)."
|
120
|
+
end
|
121
|
+
|
122
|
+
add_param(:header, :string) do |p|
|
123
|
+
p.delimiter = ' '
|
124
|
+
p.description = "width:height:fps:bgcolor: Create a new swf containing only compiled code and using provided header informations. bgcolor is optional and should be 6 digits hexadecimal value."
|
125
|
+
end
|
126
|
+
|
127
|
+
add_param(:infer, :boolean) do |p|
|
128
|
+
p.hidden_value = true
|
129
|
+
p.description = "Add type inference for initialized local variables."
|
130
|
+
end
|
131
|
+
|
132
|
+
add_param(:keep, :boolean) do |p|
|
133
|
+
p.hidden_value = true
|
134
|
+
p.description = "Keep AS2 classes compiled by MCC into the SWF (this could cause some classes to be present two times if also compiled with MTASC)."
|
135
|
+
end
|
136
|
+
|
137
|
+
add_param(:main, :boolean) do |p|
|
138
|
+
p.hidden_value = true
|
139
|
+
p.description = "Will automaticaly call static function main once all classes are registered."
|
140
|
+
end
|
141
|
+
|
142
|
+
add_param(:msvc, :boolean) do |p|
|
143
|
+
p.hidden_value = true
|
144
|
+
p.description = "Use Microsoft Visual Studio errors style formating instead of Java style (for file names and line numbers)."
|
145
|
+
end
|
146
|
+
|
147
|
+
add_param(:mx, :boolean) do |p|
|
148
|
+
p.hidden_value = true
|
149
|
+
p.description = "Use precompiled MX classes (see section on V2 components below)."
|
150
|
+
end
|
151
|
+
|
152
|
+
add_param(:out, :file) do |p|
|
153
|
+
p.delimiter = ' '
|
154
|
+
p.description = "The SWF file that should be generated, use only in addition to the -swf parameter if you want to generate a separate SWF from the one being loaded"
|
155
|
+
end
|
156
|
+
|
157
|
+
add_param(:pack, :paths) do |p|
|
158
|
+
p.description = "Compile all the files contained in specified package - not recursively (eg to compile files in c:\flash\code\my\app do mtasc -cp c:\flash\code -pack my/app)."
|
159
|
+
end
|
160
|
+
|
161
|
+
add_param(:strict, :boolean) do |p|
|
162
|
+
p.hidden_value = true
|
163
|
+
p.description = "Use strict compilation mode which require that all variables are explicitely typed."
|
164
|
+
end
|
165
|
+
|
166
|
+
add_param(:swf, :file) do |p|
|
167
|
+
p.delimiter = ' '
|
168
|
+
p.required = true
|
169
|
+
p.description =<<EOF
|
170
|
+
Specify the swf that should be generated, OR the input SWF which contains assets.
|
171
|
+
|
172
|
+
If this parameter is not set, the MTASCTask will do the following:
|
173
|
+
* Iterate over it's prerequisites and set the -swf parameter to the output of the first SWFMillTask found
|
174
|
+
* If no SWFMillTask instances are in this task prerequisites and the -swf parameter has not been set, it will be set to the same as the -out parameter
|
175
|
+
EOF
|
176
|
+
end
|
177
|
+
|
178
|
+
add_param(:trace, :string) do |p|
|
179
|
+
p.delimiter = ' '
|
180
|
+
p.description = "Specify a custom trace function. (see Trace Facilities), or no disable all the traces."
|
181
|
+
end
|
182
|
+
|
183
|
+
add_param(:version, :number) do |p|
|
184
|
+
p.delimiter = ' '
|
185
|
+
p.description = "Specify SWF version : 6 to generate Player 6r89 compatible SWF or 8 to access Flash8 features."
|
186
|
+
end
|
187
|
+
|
188
|
+
add_param(:v, :boolean) do |p|
|
189
|
+
p.hidden_value = true
|
190
|
+
p.description = "Activate verbose mode, printing some additional information about compiling process. This parameter has been aliased as +verbose+"
|
191
|
+
end
|
192
|
+
|
193
|
+
add_param_alias(:verbose, :v)
|
194
|
+
|
195
|
+
add_param(:wimp, :boolean) do |p|
|
196
|
+
p.hidden_value = true
|
197
|
+
p.description = "Adds warnings for import statements that are not used in the file."
|
198
|
+
end
|
199
|
+
|
200
|
+
# This must be the last item in this list
|
201
|
+
add_param(:input, :file) do |p|
|
202
|
+
p.hidden_name = true
|
203
|
+
p.required = true
|
204
|
+
p.description = "Main source file to send compiler"
|
205
|
+
end
|
206
|
+
|
207
|
+
self.out = name.to_s.dup
|
208
|
+
end
|
209
|
+
|
210
|
+
def define # :nodoc:
|
211
|
+
super
|
212
|
+
resolve_skin
|
213
|
+
self.swf = out unless swf
|
214
|
+
CLEAN.add(out)
|
215
|
+
|
216
|
+
# If we're on Linux, we need to manually reference
|
217
|
+
# the standard library.
|
218
|
+
# For more Info: http://code.google.com/p/projectsprouts/issues/detail?id=88
|
219
|
+
@include_std = true if RUBY_PLATFORM =~ /linux/i
|
220
|
+
|
221
|
+
if(@include_std)
|
222
|
+
# Don't inject magic/fragile version numbers or platforms here
|
223
|
+
files = Dir.glob(Sprout.sprout_cache + '/sprout-mtasc-tool-.*/archive/std/')
|
224
|
+
files.each do |file|
|
225
|
+
class_path << file
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
protected
|
231
|
+
|
232
|
+
# Iterate over prerequisites until you find the first SWFMillTask
|
233
|
+
# instance, and set self.swf = instance.output so that the skin
|
234
|
+
# gets compiled in.
|
235
|
+
def resolve_skin
|
236
|
+
prerequisites.each do |prereq|
|
237
|
+
instance = Rake::application[prereq]
|
238
|
+
if(instance.is_a?(SWFMillTask))
|
239
|
+
self.swf = instance.output
|
240
|
+
break
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# Handle prerequisite libraries by adding them to the source path
|
246
|
+
def resolve_library(library_task)
|
247
|
+
#TODO: Add support for libraries that don't get
|
248
|
+
# copied into the project
|
249
|
+
path = library_task.project_path
|
250
|
+
if(path.match(/.swc$/))
|
251
|
+
raise MTASCError.new("MTASC doesn't support SWC libraries, but this should be relatively easy to implement. Please let us know if you're interested in this feature!")
|
252
|
+
else
|
253
|
+
class_path << library_task.project_path
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def mtasc(args, &block)
|
261
|
+
Sprout::MTASCTask.define_task(args, &block)
|
262
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Sprout
|
2
|
+
class SWFMillTask
|
3
|
+
# Set the SWFMill simple flag. This setting will determine what kind of xml document the compiler expects. Unless you really know what you're doing with SWFMill, this setting will usually be left alone.
|
4
|
+
def simple=(boolean)
|
5
|
+
@simple = boolean
|
6
|
+
end
|
7
|
+
|
8
|
+
# The input can be one of the following
|
9
|
+
# * SWFMill XML document: Create and manually manage an input file as described at http://www.swfmill.org
|
10
|
+
# * Directory: if you point at a directory, this task will automatically include all files found forward of that directory. As it descends into child directories, the items found will be exposed in the library using period delimiters as follows:
|
11
|
+
#
|
12
|
+
# The file:
|
13
|
+
# yourcompany/yourproject/SomeFile.png
|
14
|
+
# Will be available in the compiled swf with a linkage identifier of:
|
15
|
+
# yourcompany.yourproject.SomeFile
|
16
|
+
def input=(string)
|
17
|
+
@input = string
|
18
|
+
end
|
19
|
+
|
20
|
+
# The output parameter should not be set from outside of this task, the output file should be the task name
|
21
|
+
def output=(file)
|
22
|
+
@output = file
|
23
|
+
end
|
24
|
+
|
25
|
+
# An ERB template to send to the generated SWFMillInputTask. This template can be used to generate an XML input document based on the contents of a directory. If no template is provided, one will be created for you after the first run, and once created, you can configure it however you wish.
|
26
|
+
def template=(file)
|
27
|
+
@template = file
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
|
2
|
+
module Sprout
|
3
|
+
|
4
|
+
class SWFMillInputError < StandardError #:nodoc:
|
5
|
+
end
|
6
|
+
|
7
|
+
# The SWFMillInputTask will generate an XML document by combining an ERB
|
8
|
+
# template with a selected directory. The resulting XML document should
|
9
|
+
# be appropriate as input for the SWFMill tool.
|
10
|
+
#
|
11
|
+
# The good news is that you should probably never need to see this task
|
12
|
+
# since the SWFMillTask will automatically create it when that task is
|
13
|
+
# given a directory as input.
|
14
|
+
class SWFMillInputTask < Rake::FileTask
|
15
|
+
DEFAULT_TEMPLATE = 'Template.erb'
|
16
|
+
DEFAULT_INPUT_EXPR = '/**/*'
|
17
|
+
|
18
|
+
# Directory to scan for files that get added to the template
|
19
|
+
attr_accessor :input
|
20
|
+
# ERB template that will be used to generate the output xml
|
21
|
+
attr_writer :template
|
22
|
+
# Blob or expression that will be used to find files to include
|
23
|
+
attr_writer :input_expr
|
24
|
+
|
25
|
+
def self.define_task(args, &block) # :nodoc:
|
26
|
+
t = super
|
27
|
+
yield t if block_given?
|
28
|
+
t.define(args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def define(args, &block) # :nodoc:
|
32
|
+
@input_files = FileList[input + input_expr]
|
33
|
+
file template
|
34
|
+
|
35
|
+
file @input_files
|
36
|
+
prerequisites << @input_files
|
37
|
+
prerequisites << template
|
38
|
+
|
39
|
+
CLEAN.add output
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(*args) # :nodoc:
|
43
|
+
ensure_template
|
44
|
+
resolve_template(template, output, @input_files, input)
|
45
|
+
end
|
46
|
+
|
47
|
+
# The output XML document to generate. This should be appropriate
|
48
|
+
# input for the SWFMillTask.
|
49
|
+
def output=(output)
|
50
|
+
@output = output
|
51
|
+
end
|
52
|
+
|
53
|
+
def output # :nodoc:
|
54
|
+
@output ||= name.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def input_expr # :nodoc:
|
58
|
+
@input_expr ||= DEFAULT_INPUT_EXPR
|
59
|
+
end
|
60
|
+
|
61
|
+
def template # :nodoc:
|
62
|
+
@template ||= default_template
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def default_template
|
68
|
+
return File.join(File.dirname(input), DEFAULT_TEMPLATE)
|
69
|
+
end
|
70
|
+
|
71
|
+
def ensure_template
|
72
|
+
return if(template && File.exists?(template))
|
73
|
+
File.open(template, 'wb') do |f|
|
74
|
+
f.write(template_content)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# def create_output
|
79
|
+
# File.join(File.dirname(input), File.basename(input).capitalize + ".xml")
|
80
|
+
# end
|
81
|
+
|
82
|
+
def resolve_template(template, output, files, base_dir)
|
83
|
+
SWFMillInputResolver.new(template, output, files, base_dir)
|
84
|
+
Log.puts ">> Created file at: #{output}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def template_content
|
88
|
+
return <<EOF
|
89
|
+
<?xml version="1.0" encoding="iso-8859-1" ?>
|
90
|
+
<%= xml_edit_warning %>
|
91
|
+
<movie width="600" height="450" framerate="24" version="8">
|
92
|
+
<background color="#ffffff"/>
|
93
|
+
<frame>
|
94
|
+
<library>
|
95
|
+
<% files.each do |file| if(!ignore_file?(file) && !File.directory?(file)) %>
|
96
|
+
<clip id="<%=get_symbol_id(file)%>" import="<%=file%>" />
|
97
|
+
<% end end %>
|
98
|
+
|
99
|
+
</library>
|
100
|
+
</frame>
|
101
|
+
<frame>
|
102
|
+
<stop />
|
103
|
+
</frame>
|
104
|
+
</movie>
|
105
|
+
EOF
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class SWFMillInputResolver < SimpleResolver #:nodoc:
|
110
|
+
|
111
|
+
def ignore_file?(file)
|
112
|
+
base = File.basename(file)
|
113
|
+
if(base == '.DS_Store' || base == 'Thumbs.db' || base.match(/^\d/) || base == '.svn')
|
114
|
+
@ignored_files << file
|
115
|
+
return true
|
116
|
+
end
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_symbol_id(file)
|
121
|
+
trimmed = file.gsub(@base_dir, '')
|
122
|
+
parts = trimmed.split('.')
|
123
|
+
parts.pop
|
124
|
+
trimmed = parts.join('.')
|
125
|
+
|
126
|
+
result = trimmed.split(File::SEPARATOR).join('.')
|
127
|
+
result = result.gsub(/^./, '')
|
128
|
+
return result
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def swfmill_input(args, &block)
|
134
|
+
Sprout::SWFMillInputTask.define_task(args, &block)
|
135
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'sprout/tasks/swfmill_input_task'
|
2
|
+
|
3
|
+
module Sprout
|
4
|
+
|
5
|
+
class SWFMillError < StandardError #:nodoc:
|
6
|
+
end
|
7
|
+
|
8
|
+
# Compile a set of assets (pngs, gifs, jpegs, mp3s, fonts, etc)
|
9
|
+
# into a library swf using SWFMill[http://www.swfmill.org].
|
10
|
+
#
|
11
|
+
# The resulting SWF file can be a Flash Player 6, 7 or 8 file format
|
12
|
+
# and is appropriately used as asset input for MTASC or MXMLC compilation.
|
13
|
+
#
|
14
|
+
# This task simplifies SWFMill usage so that you can essentially
|
15
|
+
# point it at a directory of images, set the task as a prerequisite
|
16
|
+
# for an MTASCTask or an MXMLCTask, and have them self-configure
|
17
|
+
# to include the output.
|
18
|
+
#
|
19
|
+
# A simple example is as follows:
|
20
|
+
#
|
21
|
+
# swfmill 'assets/skins/SomeProjectSkin.swf' do |t|
|
22
|
+
# t.input = 'assets/skins/SomeProjectSkin'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
class SWFMillTask < ToolTask
|
26
|
+
|
27
|
+
def initialize_task
|
28
|
+
@default_gem_name = 'sprout-swfmill-tool'
|
29
|
+
|
30
|
+
add_param(:simple, :boolean) do |p|
|
31
|
+
p.value = true
|
32
|
+
p.hidden_value = true
|
33
|
+
p.prefix = ''
|
34
|
+
p.description = "Set the SWFMill simple flag. This setting will determine what kind of xml document the compiler expects. Unless you really know what you're doing with SWFMill, this setting will usually be left alone."
|
35
|
+
end
|
36
|
+
|
37
|
+
add_param(:input, :string) do |p|
|
38
|
+
p.hidden_name = true
|
39
|
+
p.description =<<EOF
|
40
|
+
The input can be one of the following
|
41
|
+
* SWFMill XML document: Create and manually manage an input file as described at http://www.swfmill.org
|
42
|
+
* Directory: if you point at a directory, this task will automatically include all files found forward of that directory. As it descends into child directories, the items found will be exposed in the library using period delimiters as follows:
|
43
|
+
|
44
|
+
The file:
|
45
|
+
yourcompany/yourproject/SomeFile.png
|
46
|
+
Will be available in the compiled swf with a linkage identifier of:
|
47
|
+
yourcompany.yourproject.SomeFile
|
48
|
+
EOF
|
49
|
+
end
|
50
|
+
|
51
|
+
add_param(:output, :file) do |p|
|
52
|
+
p.hidden_name = true
|
53
|
+
p.description = "The output parameter should not be set from outside of this task, the output file should be the task name"
|
54
|
+
end
|
55
|
+
|
56
|
+
add_param(:template, :file) do |p|
|
57
|
+
p.description = "An ERB template to send to the generated SWFMillInputTask. This template can be used to generate an XML input document based on the contents of a directory. If no template is provided, one will be created for you after the first run, and once created, you can configure it however you wish."
|
58
|
+
end
|
59
|
+
|
60
|
+
self.output = name.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
def define # :nodoc:
|
64
|
+
raise SWFMillError.new("The SWFMillTask should be given a SWF file as a task name instead of '#{name}'") unless output.match(/\.swf$/)
|
65
|
+
|
66
|
+
CLEAN.add(output)
|
67
|
+
|
68
|
+
# Respond to input parameter configuration
|
69
|
+
if(File.directory?(input))
|
70
|
+
swfmill_input input_task_name do |t|
|
71
|
+
t.input = input
|
72
|
+
self.input = t.output # not a typo!
|
73
|
+
end
|
74
|
+
prerequisites << input_task_name
|
75
|
+
simple = true
|
76
|
+
end
|
77
|
+
|
78
|
+
if(input.match(/.xml$/))
|
79
|
+
@simple = true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def input_task_name
|
86
|
+
@input_task_name ||= create_input_task_name
|
87
|
+
end
|
88
|
+
|
89
|
+
def create_input_task_name
|
90
|
+
input_task_name = name.to_s.dup
|
91
|
+
input_task_name.gsub!(/.swf$/, 'Input.xml')
|
92
|
+
return input_task_name
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def swfmill(args, &block)
|
99
|
+
Sprout::SWFMillTask.define_task(args, &block)
|
100
|
+
end
|