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



126
127
128
129
130
131
132
133
134
# File 'lib/topkit/app_builder.rb', line 126

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

#add_relative_url_rootObject



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

def add_relative_url_root
  relative_root = "  #Deploy staging to subdirectory\n  config.action_controller.relative_url_root = '/\#{options[:client]}/\#{options[:project]}'\n  eos\n  inject_into_file \"config/environments/staging.rb\", \"\\n\#{relative_root}\", after: \"config.serve_static_assets = true\\n\"\n\n  replace_in_file \"config.ru\",\n    \"run \#{app_const}\",\n    %(map ActionController::Base.config.relative_url_root || \"/\" do\\n  run \#{app_const}\\nend)\nend\n"

#add_to_git_ignoreObject



153
154
155
# File 'lib/topkit/app_builder.rb', line 153

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 = "config.generators do |g|\n  g.fixture true\n  g.fixture_replacement \"factory_girl\"\n  g.assets false\n  g.test_framework :rspec\n  g.view_specs false\n  g.controller_specs false\n  g.helper_specs false\n  g.routing_specs false\n  g.request_specs false\n  g.stylesheets false\nend\n\n  RUBY\n\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#create_application_layoutObject



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

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



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

def create_database
  bundle_command "exec rake db:create"
end

#create_partials_directoryObject



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

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_status_partialsObject



71
72
73
74
75
# File 'lib/topkit/app_builder.rb', line 71

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



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

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



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

def generate_admin
  generate "rails_admin:install"
end

#generate_backboneObject



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

def generate_backbone
  generate "backbone:install"
end

#generate_backtraceObject



90
91
92
# File 'lib/topkit/app_builder.rb', line 90

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

#generate_cucumberObject



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

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

#generate_deviseObject



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

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

#generate_rich_editorObject



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

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

#generate_rspecObject



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

def generate_rspec
  generate 'rspec:install'
end

#init_gitObject



149
150
151
# File 'lib/topkit/app_builder.rb', line 149

def init_git
  run 'git init'
end

#remove_public_indexObject



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

def remove_public_index
  remove_file 'public/index.html'
end

#remove_rails_logo_imageObject



50
51
52
# File 'lib/topkit/app_builder.rb', line 50

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

#remove_routes_comment_linesObject



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

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

#set_puma_as_default_serverObject



30
31
32
33
34
35
36
# File 'lib/topkit/app_builder.rb', line 30

def set_puma_as_default_server
  config = "require 'rack/handler'\nRack::Handler::WEBrick = Rack::Handler.get(:puma)\n  RUBY\n  inject_into_file \"script/rails\", config, before: \"require 'rails/commands'\"\nend\n"

#setup_staging_environmentObject



60
61
62
63
64
65
# File 'lib/topkit/app_builder.rb', line 60

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



114
115
116
117
# File 'lib/topkit/app_builder.rb', line 114

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

#template_database_fileObject



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

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