Class: Derail::Generators::AppGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/generators/derail/app/app_generator.rb

Instance Method Summary collapse

Instance Method Details

#configure_action_mailerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/derail/app/app_generator.rb', line 33

def configure_action_mailer
  inject_into_file "config/environments/development.rb", <<-RUBY.redent(2), :after => /config.action_mailer.*?\n/

    # Development URL
    config.action_mailer.default_url_options = { :host => '#{app_slug}.dev' }

    # Send mail via MailCatcher
    config.action_mailer.smtp_settings = { :address => 'localhost', :port => 1025 }
  RUBY

  inject_into_file "config/environments/test.rb", <<-RUBY.redent(2), :after => /config.action_mailer.*?\n/

    # Testing URL
    config.action_mailer.default_url_options = { :host => '#{app_slug}.test' }
  RUBY
end

#configure_coffeeObject



61
62
63
64
# File 'lib/generators/derail/app/app_generator.rb', line 61

def configure_coffee
  system "mv", "app/assets/javascripts/application.js", "app/assets/javascripts/application.js.coffee"
  gsub_file "app/assets/javascripts/application.js.coffee", %r{^//}, "#"
end

#configure_databaseObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/derail/app/app_generator.rb', line 3

def configure_database
  # The original is full of noise, ick.
  remove_file "config/database.yml", :verbose => false
  create_file "config/database.yml", <<-RUBY.dedent
    development:
      adapter: postgresql
      encoding: unicode
      pool: 5
      database: #{app_slug}_development
      username: development
      password: development

    test:
      adapter: postgresql
      encoding: unicode
      pool: 5
      database: #{app_slug}_test
      username: test
      password: test

    production:
      adapter: postgresql
      encoding: unicode
      pool: 5
      database: <%= ENV["DATABASE"] %>
      username: <%= ENV["DATABASE_USERNAME"] %>
      password: <%= ENV["DATABASE_PASSWORD"] %>
  RUBY
end

#configure_sassObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/generators/derail/app/app_generator.rb', line 50

def configure_sass
  inject_into_file "config/application.rb", <<-RUBY.redent(4), :after => /config\.assets[^\n]*\n/

    # Use SASS by default
    config.generators.stylesheet_engine = :sass
  RUBY

  bundle_run "sass-convert", "app/assets/stylesheets/application.css", "app/assets/stylesheets/application.css.sass"
  remove_file "app/assets/stylesheets/application.css"
end

#generate_adminObject



121
122
123
124
125
# File 'lib/generators/derail/app/app_generator.rb', line 121

def generate_admin
  # TODO: Admin
  # TODO: Make optional
  #generate "derail:admin"
end

#generate_dashboardObject



115
116
117
118
119
# File 'lib/generators/derail/app/app_generator.rb', line 115

def generate_dashboard
  # TODO: Dashboard
  # TODO: Make optional
  #generate "derail:dashboard"
end

#generate_deviseObject



110
111
112
113
# File 'lib/generators/derail/app/app_generator.rb', line 110

def generate_devise
  # TODO: Make optional
  generate "derail:devise"
end

#generate_errorsObject



133
134
135
136
137
# File 'lib/generators/derail/app/app_generator.rb', line 133

def generate_errors
  # TODO: Error handling
  # TODO: Make optional
  #generate "derail:errors"
end

#generate_formtasticObject



93
94
95
96
# File 'lib/generators/derail/app/app_generator.rb', line 93

def generate_formtastic
  # TODO: Make optional
  generate "formtastic:install"
end

#generate_homeObject



104
105
106
107
108
# File 'lib/generators/derail/app/app_generator.rb', line 104

def generate_home
  # TODO: Home
  # TODO: Make optional
  #generate "derail:home"
end

#generate_layoutsObject



98
99
100
101
102
# File 'lib/generators/derail/app/app_generator.rb', line 98

def generate_layouts
  # TODO: Layouts
  # TODO: Make optional
  #generate "derail:layout"
end

#generate_pagesObject



127
128
129
130
131
# File 'lib/generators/derail/app/app_generator.rb', line 127

def generate_pages
  # TODO: Pages
  # TODO: Make optional
  #generate "derail:pages"
end

#install_cucumberObject



71
72
73
74
# File 'lib/generators/derail/app/app_generator.rb', line 71

def install_cucumber
  # TODO: Make optional
  generate "cucumber:install"
end

#install_guardObject



85
86
87
88
89
90
91
# File 'lib/generators/derail/app/app_generator.rb', line 85

def install_guard
  # TODO: Make optional
  say_status :create, "Guardfile"
  ["ego", "bundler", "rspec", "cucumber"].each do |guard|
    bundle_run "guard", "init", guard
  end
end

#install_rrObject



76
77
78
79
80
81
82
83
# File 'lib/generators/derail/app/app_generator.rb', line 76

def install_rr
  gsub_file "spec/spec_helper.rb", /[ \t]*# == Mock Framework\n(.*)\n[ \t]*config\.mock_with[ \t]*\S+\n/m, <<-RUBY.redent(2)
    # == Mock Framework
    config.mock_with :rr
  RUBY

  # TODO: Insert RR cucumber support
end

#install_rspecObject



66
67
68
69
# File 'lib/generators/derail/app/app_generator.rb', line 66

def install_rspec
  # TODO: Make optional
  generate "rspec:install"
end

#remove_indexObject



139
140
141
# File 'lib/generators/derail/app/app_generator.rb', line 139

def remove_index
  remove_file "public/index.html"
end

#remove_rails_logoObject



143
144
145
# File 'lib/generators/derail/app/app_generator.rb', line 143

def 
  remove_file "app/assets/images/rails.png"
end