Class: Sprout::ProjectModel

Inherits:
Hash
  • Object
show all
Defined in:
lib/sprout/project_model.rb

Overview

The ProjectModel gives you a place to describe your project so that you don’t need to repeat yourself throughout a rakefile.

The default set of properties are also used from code generators, library tasks and sometimes tools.

The ProjectModel can be configured as follows:

project_model :model do |p|
  p.name          = 'SomeProject'
  p.source_path   << 'somedir/otherdir'
  p.library_path  << 'somedir'
end

This class should have some reasonable default values, but can be modified from any rakefile. If you don’t find some properties that you’d like on the ProjectModel, you can simply add new properties and use them however you wish.

Arbitrary properties can be added as follows:

m = project_model :model do |p|
  p.unknown_property = 'someValue'
end

puts "Unknown Property: #{m.unknown_property}"

The ProjectModel is typically treated as if it is a Singleton, and many helper tasks will automatically go look for their model at:

Sprout::ProjectModel.instance

Unlike a real Singleton, this static property will actually be populated with the most recently instantiated ProjectModel, and any well-behaved helper task will also allow you to send in a model as a prerequisite.

project_model :model_a
project_model :model_b

desc 'Compile and run a'
debug :debug_a => :model_a

desc 'Compile and run b'
debug :debug_b => :model_b

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProjectModel

Returns a new instance of ProjectModel.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/sprout/project_model.rb', line 156

def initialize
  super
  @project_name   = ''
  @doc_dir        = 'doc'
  @src_dir        = 'src'
  @lib_dir        = 'lib'
  @swc_dir        = 'lib'
  @bin_dir        = 'bin'
  @test_dir       = 'test'
  @asset_dir      = 'assets'
  @skin_dir       = File.join(@asset_dir, 'skins')
  @frame_rate     = 24
  @language       = 'as3'

  @external_css   = []
  @libraries      = []
  @library_path   = []
  @modules        = []
  @source_path    = []

  @model_dir      = nil
  @view_dir       = nil
  @controller_dir = nil
  
  @test_height    = 550
  @test_width     = 900
  @@instance      = self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (protected)



247
248
249
250
251
252
253
254
255
256
# File 'lib/sprout/project_model.rb', line 247

def method_missing(method_name, *args)
  method_name = method_name.to_s
  if method_name =~ /=$/
    super if args.size > 1
    self[method_name[0...-1]] = args[0]
  else
    super unless has_key?(method_name) and args.empty?
    self[method_name]
  end
end

Instance Attribute Details

#asset_dirObject

Relative path to the folder where compile time assets will be stored



47
48
49
# File 'lib/sprout/project_model.rb', line 47

def asset_dir
  @asset_dir
end

#background_colorObject

The Background Color of the SWF file



51
52
53
# File 'lib/sprout/project_model.rb', line 51

def background_color
  @background_color
end

#bin_dirObject

The folder where binary files will be created. Usually this is where any build artifacts like SWF files get placed.



49
50
51
# File 'lib/sprout/project_model.rb', line 49

def bin_dir
  @bin_dir
end

#compiler_gem_nameObject

If you don’t want to use the default compiler for your language set it manually here. Possible values are:

  • sprout-flex2sdk-tool

  • sprout-flex3sdk-tool

  • sprout-flex4sdk-tool (Experimental)

  • sprout-mtasc-tool



61
62
63
# File 'lib/sprout/project_model.rb', line 61

def compiler_gem_name
  @compiler_gem_name
end

#compiler_gem_versionObject

The version number of the compiler gem to use



63
64
65
# File 'lib/sprout/project_model.rb', line 63

def compiler_gem_version
  @compiler_gem_version
end

#contributorsObject

Contributors to the SWF file



53
54
55
# File 'lib/sprout/project_model.rb', line 53

def contributors
  @contributors
end

#creatorObject

The primary creator of the SWF file



65
66
67
# File 'lib/sprout/project_model.rb', line 65

def creator
  @creator
end

#doc_dirObject

Directory where documentation should be placed.



67
68
69
# File 'lib/sprout/project_model.rb', line 67

def doc_dir
  @doc_dir
end

#external_cssObject

CSS documents that should be individually compiled for runtime stylesheet loading.



70
71
72
# File 'lib/sprout/project_model.rb', line 70

def external_css
  @external_css
end

#frame_rateObject

The default frame rate of the SWF file



72
73
74
# File 'lib/sprout/project_model.rb', line 72

def frame_rate
  @frame_rate
end

#heightObject

The default height of the SWF file _(This value is overridden when embedded in an HTML page)_



75
76
77
# File 'lib/sprout/project_model.rb', line 75

def height
  @height
end

#languageObject

The technology language that is being used, right now this value can be ‘as2’, ‘as3’ or ‘mxml’. Code generators take advantage of this setting to determine which templates to use and build tasks use this setting to determin the input file suffix (.as or .mxml).



79
80
81
# File 'lib/sprout/project_model.rb', line 79

def language
  @language
end

#lib_dirObject

The relative path to your library directory. Defaults to ‘lib’

Any remote .SWC and source libraries that are referenced in your rakefile will be installed into this directory. Source libraries will be placed in a folder that matches the library name, while SWCs will be simply placed directly into the lib_dir.



85
86
87
# File 'lib/sprout/project_model.rb', line 85

def lib_dir
  @lib_dir
end

#librariesObject

Array of sprout library symbols



87
88
89
# File 'lib/sprout/project_model.rb', line 87

def libraries
  @libraries
end

#library_pathObject

The Array of SWC paths to add to all compilation tasks



89
90
91
# File 'lib/sprout/project_model.rb', line 89

def library_path
  @library_path
end

#localeObject

The locale for the SWF file



91
92
93
# File 'lib/sprout/project_model.rb', line 91

def locale
  @locale
end

#modulesObject

A collection of Flex Module root source files. If this collection has items added to it, the deploy task will generate a ‘link_report’ from the main application compilation and then consume it as ‘load_externs’ for each module compilation.



96
97
98
# File 'lib/sprout/project_model.rb', line 96

def modules
  @modules
end

#organizationObject

Organization responsible for this SWF file



98
99
100
# File 'lib/sprout/project_model.rb', line 98

def organization
  @organization
end

#outputObject

The production file that this Project will generate



100
101
102
# File 'lib/sprout/project_model.rb', line 100

def output
  @output
end

#preprocessed_pathObject

Folder where preprocessed files will be created. Defaults to ‘.preprocessed’



104
105
106
# File 'lib/sprout/project_model.rb', line 104

def preprocessed_path
  @preprocessed_path
end

#preprocessorObject

Terminal command to preprocessor application that accepts STDIN and returns on STDOUT



102
103
104
# File 'lib/sprout/project_model.rb', line 102

def preprocessor
  @preprocessor
end

#project_nameObject

The real name of the project, usually capitalized like a class name ‘SomeProject’



106
107
108
# File 'lib/sprout/project_model.rb', line 106

def project_name
  @project_name
end

#skin_dirObject

The folder where compile time skins can be loaded from



108
109
110
# File 'lib/sprout/project_model.rb', line 108

def skin_dir
  @skin_dir
end

#skin_outputObject

The skin file that will be generated



110
111
112
# File 'lib/sprout/project_model.rb', line 110

def skin_output
  @skin_output
end

#source_pathObject

The Array of source paths to add to all compilation tasks _Do not add task-specific paths (like lib/asunit) to this value_



113
114
115
# File 'lib/sprout/project_model.rb', line 113

def source_path
  @source_path
end

#src_dirObject

The relative path to your main source directory. Defaults to ‘src’



115
116
117
# File 'lib/sprout/project_model.rb', line 115

def src_dir
  @src_dir
end

#strictObject

Enforce strict type checking



117
118
119
# File 'lib/sprout/project_model.rb', line 117

def strict
  @strict
end

#swc_dirObject

The relative path to the directory where swc files should be kept. This value defaults to lib_dir



120
121
122
# File 'lib/sprout/project_model.rb', line 120

def swc_dir
  @swc_dir
end

#test_dirObject

Relative path to the folder that contains your test cases



122
123
124
# File 'lib/sprout/project_model.rb', line 122

def test_dir
  @test_dir
end

#test_heightObject

The test runner SWF height



126
127
128
# File 'lib/sprout/project_model.rb', line 126

def test_height
  @test_height
end

#test_outputObject

The test executable



124
125
126
# File 'lib/sprout/project_model.rb', line 124

def test_output
  @test_output
end

#test_widthObject

The test runner SWF width



128
129
130
# File 'lib/sprout/project_model.rb', line 128

def test_width
  @test_width
end

#use_fcshObject

Tasks that can, will use the Flex Compiler SHell.



130
131
132
# File 'lib/sprout/project_model.rb', line 130

def use_fcsh
  @use_fcsh
end

#use_fdbObject

Flash Player Tasks will launch using the Flex Debugger.



132
133
134
# File 'lib/sprout/project_model.rb', line 132

def use_fdb
  @use_fdb
end

#widthObject

The default width of the SWF file _(This value is overridden when embedded in an HTML page)_



135
136
137
# File 'lib/sprout/project_model.rb', line 135

def width
  @width
end

Class Method Details

.destroyObject

:nodoc:



152
153
154
# File 'lib/sprout/project_model.rb', line 152

def self.destroy # :nodoc:
  @@instance = nil
end

.instance {|@@instance| ... } ⇒ Object

Static method that returns the most recently instantiated ProjectModel, or instantiates one if none have been created yet.

Yields:



139
140
141
142
143
# File 'lib/sprout/project_model.rb', line 139

def self.instance
  @@instance ||= ProjectModel.new
  yield @@instance if block_given?
  return @@instance
end

.setup {|@@instance| ... } ⇒ Object

Decorates the static instance method.

Yields:



146
147
148
149
150
# File 'lib/sprout/project_model.rb', line 146

def self.setup
  @@instance ||= ProjectModel.new
  yield @@instance if block_given?
  return @@instance
end

Instance Method Details

#controller_dirObject

Simple MVC helper for project-wide views if your project is called ‘SomeProject’ this will default to:

SomeProject/src/someproject/controllers


225
226
227
228
229
230
# File 'lib/sprout/project_model.rb', line 225

def controller_dir
  if(@controller_dir.nil?)
    @controller_dir = File.join(src_dir, project_name.downcase, 'controllers')
  end
  return @controller_dir
end

#controller_dir=(dir) ⇒ Object



218
219
220
# File 'lib/sprout/project_model.rb', line 218

def controller_dir=(dir)
  @controller_dir = dir
end

#model_dirObject

Simple MVC helper for project-wide models if your project is called ‘SomeProject’ this will default to:

SomeProject/src/someproject/models


197
198
199
200
201
202
# File 'lib/sprout/project_model.rb', line 197

def model_dir
  if(@model_dir.nil?)
    @model_dir = File.join(src_dir, project_name.downcase, 'models')
  end
  return @model_dir
end

#model_dir=(dir) ⇒ Object



190
191
192
# File 'lib/sprout/project_model.rb', line 190

def model_dir=(dir)
  @model_dir = dir
end

#nameObject



237
238
239
# File 'lib/sprout/project_model.rb', line 237

def name
  @project_name
end

#name=(name) ⇒ Object

Alias for project_name



233
234
235
# File 'lib/sprout/project_model.rb', line 233

def name=(name)
  @project_name = name
end

#project_pathObject

Path to the project directory from which all other paths are created



186
187
188
# File 'lib/sprout/project_model.rb', line 186

def project_path
  return Sprout.project_path
end

#to_sObject



241
242
243
# File 'lib/sprout/project_model.rb', line 241

def to_s
  return "[Sprout::ProjectModel project_name=#{project_name}]"
end

#view_dirObject

Simple MVC helper for project-wide views if your project is called ‘SomeProject’ this will default to:

SomeProject/src/someproject/views


211
212
213
214
215
216
# File 'lib/sprout/project_model.rb', line 211

def view_dir
  if(@view_dir.nil?)
    @view_dir = File.join(src_dir, project_name.downcase, 'views')
  end
  return @view_dir
end

#view_dir=(dir) ⇒ Object



204
205
206
# File 'lib/sprout/project_model.rb', line 204

def view_dir=(dir)
  @view_dir = dir
end