Class: Topkit::AppBuilder

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

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #configure_environment, #download_file, #replace_in_file

Instance Method Details

#add_admin_to_gemfileObject



118
119
120
121
122
123
124
125
126
# File 'lib/topkit/app_builder.rb', line 118

def add_admin_to_gemfile
  admin_gems = <<-eos
  gem 'devise'
  gem 'rails_admin'
  gem 'rich'
  eos
  inject_into_file 'Gemfile', "\n#{new_gems}", after: /gem 'kaminari'/
  bundle_command "install"
end

#add_relative_url_rootObject



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/topkit/app_builder.rb', line 86

def add_relative_url_root
  relative_root = <<-eos
  #Deploy staging to subdirectory
  config.action_controller.relative_url_root = '/#{options[:client]}/#{options[:project]}'
  eos
  inject_into_file "config/environments/staging.rb", "\n#{relative_root}", after: "config.serve_static_assets = true\n"

  replace_in_file "config.ru",
    "run #{app_const}",
    %(map ActionController::Base.config.relative_url_root || "/" do\n  run #{app_const}\nend)
end

#add_to_git_ignoreObject



145
146
147
# File 'lib/topkit/app_builder.rb', line 145

def add_to_git_ignore
  concat_file 'topkit_gitignore', '.gitignore'
end

#configure_rspec_generatorsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/topkit/app_builder.rb', line 5

def configure_rspec_generators
  config = <<-RUBY
config.generators do |g|
  g.fixture true
  g.fixture_replacement "factory_girl"
  g.assets false
  g.test_framework :rspec
  g.view_specs false
  g.controller_specs false
  g.helper_specs false
  g.routing_specs false
  g.request_specs false
  g.stylesheets false
end

  RUBY

  inject_into_class 'config/application.rb', 'Application', config
end

#create_application_layoutObject



69
70
71
72
# File 'lib/topkit/app_builder.rb', line 69

def create_application_layout
  remove_file "app/views/layouts/application.html.erb"
  copy_file "application_layout.html.erb", "app/views/layouts/application.html.erb", force: true
end

#create_databaseObject



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

def create_database
  bundle_command "exec rake db:create"
end

#create_partials_directoryObject



59
60
61
# File 'lib/topkit/app_builder.rb', line 59

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_status_partialsObject



63
64
65
66
67
# File 'lib/topkit/app_builder.rb', line 63

def create_status_partials
  copy_file '_status.html.erb', 'app/views/application/_status.html.erb'
  copy_file '_header.html.erb', 'app/views/application/_header.html.erb'
  copy_file '_footer.html.erb', 'app/views/application/_footer.html.erb'
end

#enable_database_cleanerObject



98
99
100
101
102
103
104
# File 'lib/topkit/app_builder.rb', line 98

def enable_database_cleaner
  replace_in_file 'spec/spec_helper.rb',
    'config.use_transactional_fixtures = true',
    'config.use_transactional_fixtures = false'

  copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end

#generate_adminObject



128
129
130
# File 'lib/topkit/app_builder.rb', line 128

def generate_admin
  generate "rails_admin:install"
end

#generate_backboneObject



78
79
80
# File 'lib/topkit/app_builder.rb', line 78

def generate_backbone
  generate "backbone:install"
end

#generate_backtraceObject



82
83
84
# File 'lib/topkit/app_builder.rb', line 82

def generate_backtrace
  download_file "https://gist.github.com/apcomplete/4113645/download", "vendor/assets/javascripts/backtrace.js"
end

#generate_cucumberObject



137
138
139
# File 'lib/topkit/app_builder.rb', line 137

def generate_cucumber
  generate 'cucumber:install', '--rspec', '--capybara'
end

#generate_deviseObject



111
112
113
114
115
116
# File 'lib/topkit/app_builder.rb', line 111

def generate_devise
  generate "devise:install"
  generate "devise User"
  bundle_command "exec rake db:migrate"
  generate "devise:views"
end

#generate_rich_editorObject



132
133
134
135
# File 'lib/topkit/app_builder.rb', line 132

def generate_rich_editor
  generate "rich:install"
  bundle_command "exec rake db:migrate"
end

#generate_rspecObject



74
75
76
# File 'lib/topkit/app_builder.rb', line 74

def generate_rspec
  generate 'rspec:install'
end

#init_gitObject



141
142
143
# File 'lib/topkit/app_builder.rb', line 141

def init_git
  run 'git init'
end

#remove_public_indexObject



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

def remove_public_index
  remove_file 'public/index.html'
end

#remove_rails_logo_imageObject



42
43
44
# File 'lib/topkit/app_builder.rb', line 42

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

#remove_routes_comment_linesObject



46
47
48
49
50
# File 'lib/topkit/app_builder.rb', line 46

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

#replace_gemfileObject



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

def replace_gemfile
  remove_file 'Gemfile'
  copy_file 'Gemfile_clean', 'Gemfile'
end

#setup_staging_environmentObject



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

def setup_staging_environment
  run "cp config/environments/production.rb config/environments/staging.rb"
  replace_in_file "config/environments/staging.rb", "config.serve_static_assets = false", "config.serve_static_assets = true"
  replace_in_file "config/environments/staging.rb", "config.assets.compile = false", "config.assets.compile = true"
  replace_in_file "config/environments/staging.rb", "# config.log_level = :debug", "config.log_level = :debug"
end

#setup_stylesheetsObject



106
107
108
109
# File 'lib/topkit/app_builder.rb', line 106

def setup_stylesheets
  remove_file 'app/assets/stylesheets/application.css'
  create_file 'app/assets/stylesheets/application.css.scss'
end

#template_database_fileObject



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

def template_database_file
  template 'database.mysql.yml.erb', 'config/database.yml', force: true
end