Class: Bakeware::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/bakeware/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_custom_gemsObject



81
82
83
84
85
86
# File 'lib/bakeware/app_builder.rb', line 81

def add_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

#add_email_validatorObject



200
201
202
# File 'lib/bakeware/app_builder.rb', line 200

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

#add_extra_configObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bakeware/app_builder.rb', line 95

def add_extra_config
  copy_file 'unicorn_config', 'config/unicorn.rb'
  copy_file 'newrelic_config', 'config/newrelic.yml'
  copy_file 's3yml', 'config/s3.yml'
  copy_file 'asset_sync', 'config/initializers/asset_sync.rb'
  copy_file 'timeout', 'config/initializers/timeout.rb'
  copy_file 'Procfile', 'Procfile'
  inject_into_file 'Procfile', "worker: env QUEUE=* bundle exec rake resque:work",
    :after => "\n"
  replace_in_file 'Procfile',
    'web: bundle exec rails server thin -p $PORT','web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb'
end

#add_jquery_uiObject



62
63
64
65
# File 'lib/bakeware/app_builder.rb', line 62

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

#add_meaty_gemsObject



88
89
90
91
92
93
# File 'lib/bakeware/app_builder.rb', line 88

def add_meaty_gems
  meaty_path = find_in_source_paths('Gemfile_extra_meat')
  meaty_gems = File.open(meaty_path).read
  inject_into_file 'Gemfile', "\n#{meaty_gems}",
    :after => /gem 'haml'/
end

#configure_action_mailerObject



120
121
122
123
124
125
# File 'lib/bakeware/app_builder.rb', line 120

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

#configure_time_formatsObject



115
116
117
118
# File 'lib/bakeware/app_builder.rb', line 115

def configure_time_formats
  remove_file 'config/locales/en.yml'
  copy_file 'config_locales_en.yml', 'config/locales/en.yml'
end

#configure_time_zoneObject



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

def configure_time_zone
  time_zone_config = "config.active_record.default_timezone = :utc\n  RUBY\n  inject_into_class \"config/application.rb\", \"Application\", time_zone_config\nend\n"

#copy_librariesObject



171
172
173
# File 'lib/bakeware/app_builder.rb', line 171

def copy_libraries
  copy_file 'override_recipient_smtp.rb', 'lib/override_recipient_smtp.rb'
end

#copy_miscellaneous_filesObject



175
176
177
# File 'lib/bakeware/app_builder.rb', line 175

def copy_miscellaneous_files
  copy_file 'errors.rb', 'config/initializers/errors.rb'
end

#create_application_layoutObject



52
53
54
55
56
# File 'lib/bakeware/app_builder.rb', line 52

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

#create_common_javascriptsObject



58
59
60
# File 'lib/bakeware/app_builder.rb', line 58

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

#create_databaseObject



72
73
74
# File 'lib/bakeware/app_builder.rb', line 72

def create_database
  bundle_command 'exec rake db:create'
end

#create_github_repo(repo_name) ⇒ Object



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

def create_github_repo(repo_name)
  path_addition = override_path_for_tests
  run "#{path_addition} hub create #{repo_name}"
end

#create_heroku_appsObject



160
161
162
163
164
# File 'lib/bakeware/app_builder.rb', line 160

def create_heroku_apps
  path_addition = override_path_for_tests
  run "#{path_addition} heroku create #{app_name} --remote=production"
  run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
end

#create_partials_directoryObject



40
41
42
# File 'lib/bakeware/app_builder.rb', line 40

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



44
45
46
# File 'lib/bakeware/app_builder.rb', line 44

def create_shared_flashes
  copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
end

#create_shared_javascriptsObject



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

def create_shared_javascripts
  copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
end

#customize_error_pagesObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/bakeware/app_builder.rb', line 179

def customize_error_pages
  meta_tags ="  <meta charset='utf-8' />\n  <meta name='ROBOTS' content='NOODP' />\n  EOS\n  style_tags =<<-EOS\n<link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />\n  EOS\n  %w(500 404 422).each do |page|\n    inject_into_file \"public/\#{page}.html\", meta_tags, :after => \"<head>\\n\"\n    replace_in_file \"public/\#{page}.html\", /<style.+>.+<\\/style>/mi, style_tags.strip\n    replace_in_file \"public/\#{page}.html\", /<!--.+-->\\n/, ''\n  end\nend\n"

#gitignore_filesObject



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/bakeware/app_builder.rb', line 143

def gitignore_files
  concat_file 'bakeware_gitignore', '.gitignore'
  [
    'app/models',
    'app/assets/images',
    'app/views/pages',
    'db/migrate',
    'log'
  ].each do |dir|
    empty_directory_with_gitkeep dir
  end
end

#init_gitObject



156
157
158
# File 'lib/bakeware/app_builder.rb', line 156

def init_git
  run 'git init'
end

#initialize_on_precompileObject



34
35
36
37
38
# File 'lib/bakeware/app_builder.rb', line 34

def initialize_on_precompile
  inject_into_file 'config/application.rb',
    "\n    config.assets.initialize_on_precompile = false",
    :after => 'config.assets.enabled = true'
end

#provide_setup_scriptObject



22
23
24
25
# File 'lib/bakeware/app_builder.rb', line 22

def provide_setup_script
  copy_file 'script_setup', 'script/setup'
  run 'chmod a+x script/setup'
end

#raise_delivery_errorsObject



17
18
19
20
# File 'lib/bakeware/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/bakeware/app_builder.rb', line 5

def readme
  template 'README.md.erb', 'README.md'
end

#remove_public_indexObject



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

def remove_public_index
  remove_file 'public/index.html'
end

#remove_rails_logo_imageObject



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

def remove_rails_logo_image
  remove_file 'app/assets/images/rails.png'
end

#remove_routes_comment_linesObject



194
195
196
197
198
# File 'lib/bakeware/app_builder.rb', line 194

def remove_routes_comment_lines
  replace_in_file 'config/routes.rb',
    /Application\.routes\.draw do.*end/m,
    "Application.routes.draw do\nend"
end

#set_ruby_to_version_being_usedObject



76
77
78
79
# File 'lib/bakeware/app_builder.rb', line 76

def set_ruby_to_version_being_used
  inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
    :after => /source 'https:\/\/rubygems.org'/
end

#setup_default_rake_taskObject



204
205
206
207
208
# File 'lib/bakeware/app_builder.rb', line 204

def setup_default_rake_task
  # append_file 'Rakefile' do
  #   "task(:default).clear\n"
  # end
end

#setup_foremanObject



131
132
133
# File 'lib/bakeware/app_builder.rb', line 131

def setup_foreman
  copy_file 'sample.env', 'sample.env'
end

#setup_guard_sporkObject



127
128
129
# File 'lib/bakeware/app_builder.rb', line 127

def setup_guard_spork
  copy_file 'Guardfile', 'Guardfile'
end

#setup_staging_environmentObject



27
28
29
30
31
32
# File 'lib/bakeware/app_builder.rb', line 27

def setup_staging_environment
  run 'cp config/environments/production.rb config/environments/staging.rb'
  inject_into_file 'config/environments/staging.rb',
    "\n  config.action_mailer.delivery_method = :override_recipient_smtp, to: '[email protected]'",
    :after => 'config.action_mailer.raise_delivery_errors = false'
end

#setup_stylesheetsObject



135
136
137
138
139
140
141
# File 'lib/bakeware/app_builder.rb', line 135

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



67
68
69
70
# File 'lib/bakeware/app_builder.rb', line 67

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