Class: Suspenders::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/suspenders/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #download_file, #replace_in_file

Instance Method Details

#add_clearance_gemObject



191
192
193
# File 'lib/suspenders/app_builder.rb', line 191

def add_clearance_gem
  inject_into_file("Gemfile", "\ngem 'clearance'", :after => /gem 'jquery-rails'/)
end

#add_email_validatorObject



177
178
179
# File 'lib/suspenders/app_builder.rb', line 177

def add_email_validator
  copy_file "email_validator.rb", "app/validators/email_validator.rb"
end

#add_jquery_uiObject



52
53
54
# File 'lib/suspenders/app_builder.rb', line 52

def add_jquery_ui
  inject_into_file "app/assets/javascripts/application.js", "//= require jquery-ui\n", :before => "//= require_tree ."
end

#configure_action_mailerObject



79
80
81
82
83
84
# File 'lib/suspenders/app_builder.rb', line 79

def configure_action_mailer
  action_mailer_host "development", "#{app_name}.local"
  action_mailer_host "test",        "example.com"
  action_mailer_host "staging",     "staging.#{app_name}.com"
  action_mailer_host "production",  "#{app_name}.com"
end

#configure_rspecObject



70
71
72
73
74
75
76
77
# File 'lib/suspenders/app_builder.rb', line 70

def configure_rspec
  generators_config = <<-RUBY
      config.generators do |generate|
        generate.test_framework :rspec
      end
  RUBY
  inject_into_class "config/application.rb", "Application", generators_config
end

#copy_miscellaneous_filesObject



157
158
159
160
161
# File 'lib/suspenders/app_builder.rb', line 157

def copy_miscellaneous_files
  copy_file "errors.rb", "config/initializers/errors.rb"
  copy_file "time_formats.rb", "config/initializers/time_formats.rb"
  copy_file "Procfile"
end

#create_application_layoutObject



42
43
44
45
46
# File 'lib/suspenders/app_builder.rb', line 42

def create_application_layout
  template "suspenders_layout.html.erb.erb",
           "app/views/layouts/application.html.erb",
           :force => true
end

#create_common_javascriptsObject



48
49
50
# File 'lib/suspenders/app_builder.rb', line 48

def create_common_javascripts
  directory "javascripts", "app/assets/javascripts"
end

#create_databaseObject



60
61
62
# File 'lib/suspenders/app_builder.rb', line 60

def create_database
  bundle_command('exec rake db:create')
end

#create_heroku_appsObject



141
142
143
144
145
146
147
148
149
# File 'lib/suspenders/app_builder.rb', line 141

def create_heroku_apps
  path_additions = ''
  if ENV['TESTING']
    support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
    path_addition = "PATH=#{support_bin}:$PATH"
  end
  run "#{path_addition} heroku create #{app_name}-production --remote=production --stack=cedar"
  run "#{path_addition} heroku create #{app_name}-staging    --remote=staging    --stack=cedar"
end

#create_shared_flashesObject



34
35
36
# File 'lib/suspenders/app_builder.rb', line 34

def create_shared_flashes
  copy_file "_flashes.html.erb", "app/views/shared/_flashes.html.erb"
end

#create_shared_javascriptsObject



38
39
40
# File 'lib/suspenders/app_builder.rb', line 38

def create_shared_javascripts
  copy_file "_javascript.html.erb", "app/views/shared/_javascript.html.erb"
end

#create_views_sharedObject



30
31
32
# File 'lib/suspenders/app_builder.rb', line 30

def create_views_shared
  empty_directory "app/views/shared"
end

#document_herokuObject



151
152
153
154
155
# File 'lib/suspenders/app_builder.rb', line 151

def document_heroku
  heroku_readme_path = find_in_source_paths 'HEROKU_README.md'
  documentation = File.open(heroku_readme_path).read
  inject_into_file("README.md", "#{documentation}\n", :before => "Most importantly")
end

#enable_factory_girl_syntaxObject



21
22
23
24
# File 'lib/suspenders/app_builder.rb', line 21

def enable_factory_girl_syntax
  copy_file "factory_girl_syntax_rspec.rb", "spec/support/factory_girl.rb"
  copy_file "factory_girl_syntax_cucumber.rb", "features/support/factory_girl.rb"
end

#generate_clearanceObject



99
100
101
102
# File 'lib/suspenders/app_builder.rb', line 99

def generate_clearance
  generate "clearance:install"
  generate "clearance:features"
end

#generate_cucumberObject



91
92
93
94
95
96
97
# File 'lib/suspenders/app_builder.rb', line 91

def generate_cucumber
  generate "cucumber:install", "--rspec", "--capybara"
  inject_into_file "features/support/env.rb",
                   %{Capybara.save_and_open_page_path = 'tmp'\n} +
                   %{Capybara.javascript_driver = :webkit\n},
                   :before => %{Capybara.default_selector = :css}
end

#generate_rspecObject



86
87
88
89
# File 'lib/suspenders/app_builder.rb', line 86

def generate_rspec
  generate "rspec:install"
  replace_in_file "spec/spec_helper.rb", "# config.mock_with :mocha", "config.mock_with :mocha"
end

#gitignore_filesObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/suspenders/app_builder.rb', line 115

def gitignore_files
  concat_file "suspenders_gitignore", ".gitignore"
  ["app/models",
    "app/views/pages",
    "db/migrate",
    "log",
    "public/images",
    "spec/support",
    "spec/lib",
    "spec/models",
    "spec/views",
    "spec/controllers",
    "spec/helpers",
    "spec/support/matchers",
    "spec/support/mixins",
    "spec/support/shared_examples"].each do |dir|
    empty_directory_with_gitkeep dir
  end
end

#include_clearance_matchersObject



181
182
183
# File 'lib/suspenders/app_builder.rb', line 181

def include_clearance_matchers
  create_file "spec/support/clearance.rb", "require 'clearance/testing'"
end

#include_custom_gemsObject



64
65
66
67
68
# File 'lib/suspenders/app_builder.rb', line 64

def include_custom_gems
  additions_path = find_in_source_paths 'Gemfile_additions'
  new_gems = File.open(additions_path).read
  inject_into_file("Gemfile", "\n#{new_gems}", :after => /gem 'jquery-rails'/)
end

#init_gitObject



135
136
137
138
139
# File 'lib/suspenders/app_builder.rb', line 135

def init_git
  run "git init"
  run "git add -A ."
  run "git commit -m 'Initial commit - suspended project'"
end

#install_factory_girl_stepsObject



104
105
106
# File 'lib/suspenders/app_builder.rb', line 104

def install_factory_girl_steps
  copy_file "factory_girl_steps.rb", "features/step_definitions/factory_girl_steps.rb"
end

#raise_delivery_errorsObject



17
18
19
# File 'lib/suspenders/app_builder.rb', line 17

def raise_delivery_errors
  replace_in_file "config/environments/development.rb", "raise_delivery_errors = false", "raise_delivery_errors = true"
end

#readmeObject



5
6
7
# File 'lib/suspenders/app_builder.rb', line 5

def readme
  copy_file "README.md"
end

#remove_public_images_railsObject



13
14
15
# File 'lib/suspenders/app_builder.rb', line 13

def remove_public_images_rails
  remove_file 'public/images/rails.png'
end

#remove_public_indexObject



9
10
11
# File 'lib/suspenders/app_builder.rb', line 9

def remove_public_index
  remove_file 'public/index.html'
end

#set_active_record_whitelist_attributesObject



167
168
169
# File 'lib/suspenders/app_builder.rb', line 167

def set_active_record_whitelist_attributes
  inject_into_class "config/application.rb", "Application", "    config.active_record.whitelist_attributes = true\n"
end

#set_attr_accessibles_on_userObject



171
172
173
174
175
# File 'lib/suspenders/app_builder.rb', line 171

def set_attr_accessibles_on_user
  inject_into_file "app/models/user.rb",
    "  attr_accessible :email, :password\n",
    :after => /include Clearance::User\n/
end

#setup_default_rake_taskObject



185
186
187
188
189
# File 'lib/suspenders/app_builder.rb', line 185

def setup_default_rake_task
  append_file "Rakefile" do
    "task(:default).clear\ntask :default => [:spec, :cucumber]"
  end
end

#setup_root_routeObject



163
164
165
# File 'lib/suspenders/app_builder.rb', line 163

def setup_root_route
  route "root :to => 'Clearance::Sessions#new'"
end

#setup_staging_environmentObject



26
27
28
# File 'lib/suspenders/app_builder.rb', line 26

def setup_staging_environment
  run "cp config/environments/production.rb config/environments/staging.rb"
end

#setup_stylesheetsObject



108
109
110
111
112
113
# File 'lib/suspenders/app_builder.rb', line 108

def setup_stylesheets
  copy_file "app/assets/stylesheets/application.css", "app/assets/stylesheets/application.css.scss"
  remove_file "app/assets/stylesheets/application.css"
  concat_file "import_scss_styles", "app/assets/stylesheets/application.css.scss"
  create_file "app/assets/stylesheets/_screen.scss"
end

#use_postgres_config_templateObject



56
57
58
# File 'lib/suspenders/app_builder.rb', line 56

def use_postgres_config_template
  template "postgresql_database.yml.erb", "config/database.yml", :force => true
end