module Sprout # 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. # # 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! class ProjectModel < Hash # The real name of the project, usually capitalized like a class name 'SomeProject' attr_accessor :project_name # The relative path to your main source directory. Defaults to 'src' attr_accessor :src_dir # 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. attr_accessor :lib_dir # The folder where binary files will be created. Usually this is where any build artifacts like SWF files get placed. attr_accessor :bin_dir # Relative path to the folder that contains your test cases attr_accessor :test_dir # Relative path to the folder where compile time assets will be stored attr_accessor :asset_dir # The folder where compile time skins can be loaded from attr_accessor :skin_dir # The technology language that is being used, right now this is either 'as2' or 'as3'. # Code generators take advantage of this setting to determine which templates to use. attr_accessor :language # The production file that this Project will generate attr_accessor :output # The test executable attr_accessor :test_output # The skin file that will be generated attr_accessor :skin_output # TODO: Add clean hash interface so that users # can simply add to this object's properties like: # model.foo = 'bar' # model.junk = true # and then just as easily reference those vars from # external generators... def self.instance @@instance ||= ProjectModel.new end def self.destroy # :nodoc: @@instance = nil end # Patch submitted by Thomas Winkler def self.setup(&block) yield instance end def initialize super @project_name = '' @src_dir = 'src' @lib_dir = 'lib' @bin_dir = 'bin' @test_dir = 'test' @asset_dir = 'assets' @skin_dir = File.join(@asset_dir, 'skins') @language = 'as3' @model_dir = nil @view_dir = nil @controller_dir = nil end # Path to the project directory from which all other paths are created def project_path return Sprout.project_path end def model_dir=(dir) @model_dir = dir end # Simple MVC helper for project-wide models if your project is called 'SomeProject' # this will default to: # SomeProject/src/someproject/models def model_dir if(@model_dir.nil?) @model_dir = File.join(src_dir, project_name.downcase, 'models') end return @model_dir end def view_dir=(dir) @view_dir = dir end # Simple MVC helper for project-wide views if your project is called 'SomeProject' # this will default to: # SomeProject/src/someproject/views def view_dir if(@view_dir.nil?) @view_dir = File.join(src_dir, project_name.downcase, 'views') end return @view_dir end def controller_dir=(dir) @controller_dir = dir end # Simple MVC helper for project-wide views if your project is called 'SomeProject' # this will default to: # SomeProject/src/someproject/controllers def controller_dir if(@controller_dir.nil?) @controller_dir = File.join(src_dir, project_name.downcase, 'controllers') end return @controller_dir end end end