<commit_before>module Ti
  module Generate
    class Project
      class << self
        attr_accessor :project_name, :device_platform, :app_id
        include ::Ti::Utils

        # Ti::Generate::Project.create('demo', 'org.codewranglers.demo', 'ipad')
        def create(name, id, platform='iphone')
          @project_name    = name
          @device_platform = platform
          @app_id          = id
          if system(generate_titanium_project)
            create_directories('tmp')
            copy_defaults
            remove_old_files
            generate_files
            log "Your Titanium project is ready for you to get rockin!"
          else
            error "There was an error generating your Titanium project."
          end
        end


        def copy_defaults
          FileUtils.cp(location.join("Resources/KS_nav_ui.png"),    "/tmp/")
          FileUtils.cp(location.join("Resources/KS_nav_views.png"), "/tmp/")
        end
        

        def create_config_from_templates(project_name)
          eruby = Erubis::Eruby.new( File.read(templates("defaults/config.erb")) )
          File.open(location.join("config/config.rb"), 'w') do |f| 
            f.write(eruby.result(:project_name => project_name)) 
          end
        end
        
        def create_defaults_with_template(name, contents={})
          template = templates("defaults/#{name}.erb")
          eruby = Erubis::Eruby.new(File.read(template))

          File.open(location.join(name), 'w') do |f| 
            f.write(eruby.result(contents))
          end

        end

        def create_rakefile_from_template(project_name)
          eruby = Erubis::Eruby.new( File.read(templates("defaults/Rakefile.erb")) )
          File.open(location.join("Rakefile"), 'w') do |f| 
            f.write( eruby.result({
                :app_name             => project_name, 
                :app_name_underscore  => underscore(project_name)
            })) 
          end
        end

        def generate_files
          create_project_directory
          touch('Readme.mkd')
          # touch('specs/spec_helper.coffee') # TODO: Necessary? If so, what is in it?

          create_new_file("app/app.coffee",         templates('app/app.coffee'))
          create_new_file(".gitignore",             templates('gitignore'))
          create_new_file("specs/app_spec.coffee",  templates('specs/app_spec.coffee'))
          
          
          
          create_config_from_templates(@project_name)
          create_defaults_with_template("Rakefile", {:app_name => @project_name, :app_name_underscore => underscore(@project_name)})
          create_defaults_with_template("Readme.mkd", {:app_name => @project_name})
          create_defaults_with_template("Guardfile", {:app_name => underscore(@project_name)})
          
          
          
          
          # load default images
          FileUtils.cp("/tmp/KS_nav_ui.png",    location.join("Resources/images/"))
          FileUtils.cp("/tmp/KS_nav_views.png", location.join("Resources/images/"))
        end
        
        
        def create_project_directory<commit_msg>Adding a comment to the project.rb<commit_after>module Ti
  module Generate
    class Project
      class << self
        attr_accessor :project_name, :device_platform, :app_id
        include ::Ti::Utils

        # Ti::Generate::Project.create('demo', 'org.codewranglers.demo', 'ipad')
        def create(name, id, platform='iphone')
          @project_name    = name
          @device_platform = platform
          @app_id          = id
          if system(generate_titanium_project)
            create_directories('tmp')
            copy_defaults
            remove_old_files
            generate_files
            log "Your Titanium project is ready for you to get rockin!"
          else
            error "There was an error generating your Titanium project."
          end
        end


        def copy_defaults
          FileUtils.cp(location.join("Resources/KS_nav_ui.png"),    "/tmp/")
          FileUtils.cp(location.join("Resources/KS_nav_views.png"), "/tmp/")
        end
        

        def create_config_from_templates(project_name)
          eruby = Erubis::Eruby.new( File.read(templates("defaults/config.erb")) )
          File.open(location.join("config/config.rb"), 'w') do |f| 
            f.write(eruby.result(:project_name => project_name)) 
          end
        end
        
        def create_defaults_with_template(name, contents={})
          template = templates("defaults/#{name}.erb")
          eruby = Erubis::Eruby.new(File.read(template))

          File.open(location.join(name), 'w') do |f| 
            f.write(eruby.result(contents))
          end

        end

        def create_rakefile_from_template(project_name)
          eruby = Erubis::Eruby.new( File.read(templates("defaults/Rakefile.erb")) )
          File.open(location.join("Rakefile"), 'w') do |f| 
            f.write( eruby.result({
                :app_name             => project_name, 
                :app_name_underscore  => underscore(project_name)
            })) 
          end
        end

        def generate_files
          create_project_directory
          touch('Readme.mkd')
          # touch('specs/spec_helper.coffee') # TODO: Necessary? If so, what is in it?

          create_new_file("app/app.coffee",         templates('app/app.coffee'))
          create_new_file(".gitignore",             templates('gitignore'))
          create_new_file("specs/app_spec.coffee",  templates('specs/app_spec.coffee'))
          
          
          # TODO: these can be refactored
          create_config_from_templates(@project_name)
          create_defaults_with_template("Rakefile", {:app_name => @project_name, :app_name_underscore => underscore(@project_name)})
          create_defaults_with_template("Readme.mkd", {:app_name => @project_name})
          create_defaults_with_template("Guardfile", {:app_name => underscore(@project_name)})
          
          
          
          
          # load default images
          FileUtils.cp("/tmp/KS_nav_ui.png",    location.join("Resources/images/"))
          FileUtils.cp("/tmp/KS_nav_views.png", location.join("Resources/images/"))
        end
        
        
        def create_project_directory
{'fraction_non_alphanumeric': 0.11144674085850556, 'fraction_numerical': 0.0, 'mean_word_length': 2.0657894736842106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7558202', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1776, 'n_words': 305}