da-suspenders 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.gitignore +5 -4
  2. data/CHANGELOG.md +39 -30
  3. data/LICENSE +21 -21
  4. data/README.md +64 -66
  5. data/Rakefile +41 -40
  6. data/bin/da-suspenders +1 -1
  7. data/da-suspenders.gemspec +26 -26
  8. data/features/running_cucumber.feature +17 -17
  9. data/features/step_definitions/shell.rb +30 -30
  10. data/features/support/env.rb +0 -1
  11. data/lib/create.rb +57 -55
  12. data/lib/da-suspenders/version.rb +2 -2
  13. data/lib/errors.rb +12 -12
  14. data/template/da-suspenders.rb +159 -172
  15. data/template/files/factory_girl_steps.rb +1 -1
  16. data/template/files/mysql_database.yml.erb +39 -39
  17. data/template/trout/Gemfile +66 -43
  18. data/template/trout/app/assets/javascripts/application.js.coffee +10 -0
  19. data/template/trout/app/assets/stylesheets/application.css.scss +16 -0
  20. data/template/trout/app/assets/stylesheets/ie6.css.scss +4 -0
  21. data/template/trout/app/assets/stylesheets/ie7.css.scss +4 -0
  22. data/template/trout/app/helpers/body_class_helper.rb +6 -6
  23. data/template/trout/app/views/layouts/application.html.erb +16 -15
  24. data/template/trout/app/views/shared/_flashes.html.erb +5 -5
  25. data/template/trout/config/initializers/errors.rb +26 -26
  26. data/template/trout/config/initializers/will_paginate.rb +3 -3
  27. data/template/trout/config/locales/de.yml +54 -11
  28. data/template/trout/features/step_definitions/js_steps.rb +3 -3
  29. data/template/trout/vendor/assets/javascripts/jquery-ui-1.8.16.js +791 -0
  30. data/template/trout/vendor/{sprockets/modernizr/src → assets/javascripts}/modernizr.js +29 -29
  31. metadata +12 -14
  32. data/template/trout/app/javascripts/application.js +0 -10
  33. data/template/trout/app/stylesheets/application.scss +0 -14
  34. data/template/trout/app/stylesheets/ie.scss +0 -2
  35. data/template/trout/lib/templates/erb/scaffold/_form.html.erb +0 -13
  36. data/template/trout/vendor/sprockets/jquery-ujs/src/rails.js +0 -169
@@ -1 +0,0 @@
1
- require 'spec/expectations'
data/lib/create.rb CHANGED
@@ -1,55 +1,57 @@
1
- # Methods needed to create a project.
2
-
3
- require 'rubygems'
4
- require File.expand_path(File.dirname(__FILE__) + "/errors")
5
-
6
- module DaSuspenders
7
- class Create
8
- attr_accessor :project_path
9
-
10
- def self.run!(project_path)
11
- creator = self.new(project_path)
12
- creator.create_project!
13
- end
14
-
15
- def initialize(project_path)
16
- self.project_path = project_path
17
- validate_project_path
18
- validate_project_name
19
- end
20
-
21
- def create_project!
22
- exec(<<-COMMAND)
23
- rails new #{project_path} \
24
- --template="#{template}" \
25
- --database=mysql \
26
- --skip-test-unit \
27
- --skip-prototype
28
- COMMAND
29
- end
30
-
31
- private
32
-
33
- def validate_project_name
34
- project_name = File.basename(project_path)
35
- unless project_name =~ /^[a-z0-9_]+$/
36
- raise InvalidInput.new("Project name must only contain [a-z0-9_]")
37
- end
38
- end
39
-
40
- def validate_project_path
41
- base_directory = Dir.pwd
42
- full_path = File.join(base_directory, project_path)
43
-
44
- # This is for the common case for the user's convenience; the race
45
- # condition can still occur.
46
- if File.exists?(full_path)
47
- raise InvalidInput.new("Project directory (#{project_path}) already exists")
48
- end
49
- end
50
-
51
- def template
52
- File.expand_path(File.dirname(__FILE__) + "/../template/da-suspenders.rb")
53
- end
54
- end
55
- end
1
+ # Methods needed to create a project.
2
+
3
+ require 'rubygems'
4
+ require File.expand_path(File.dirname(__FILE__) + "/errors")
5
+
6
+ module DaSuspenders
7
+ class Create
8
+ attr_accessor :project_path, :repo
9
+
10
+ def self.run!(project_path, repo)
11
+ creator = self.new(project_path, repo)
12
+ creator.create_project!
13
+ end
14
+
15
+ def initialize(project_path, repo)
16
+ self.project_path = project_path
17
+ self.repo = repo
18
+ validate_project_path
19
+ validate_project_name
20
+ end
21
+
22
+ def create_project!
23
+ command = <<-COMMAND
24
+ rails new #{project_path} \
25
+ --template="#{template}" \
26
+ --database=mysql \
27
+ --skip-test-unit
28
+ COMMAND
29
+ ENV["REPO"] = repo if repo
30
+ exec(command)
31
+ end
32
+
33
+ private
34
+
35
+ def validate_project_name
36
+ project_name = File.basename(project_path)
37
+ unless project_name =~ /^[a-z0-9_]+$/
38
+ raise InvalidInput.new("Project name must only contain [a-z0-9_]")
39
+ end
40
+ end
41
+
42
+ def validate_project_path
43
+ base_directory = Dir.pwd
44
+ full_path = File.join(base_directory, project_path)
45
+
46
+ # This is for the common case for the user's convenience; the race
47
+ # condition can still occur.
48
+ if File.exists?(full_path)
49
+ raise InvalidInput.new("Project directory (#{project_path}) already exists")
50
+ end
51
+ end
52
+
53
+ def template
54
+ File.expand_path(File.dirname(__FILE__) + "/../template/da-suspenders.rb")
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
- module DaSuspenders
2
- VERSION = "1.0.3"
1
+ module DaSuspenders
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/errors.rb CHANGED
@@ -1,12 +1,12 @@
1
- # User errors
2
-
3
- module DaSuspenders
4
- class InvalidInput < Exception; end
5
-
6
- module Errors
7
- def error_with_message(msg)
8
- STDERR.puts msg
9
- exit 1
10
- end
11
- end
12
- end
1
+ # User errors
2
+
3
+ module DaSuspenders
4
+ class InvalidInput < Exception; end
5
+
6
+ module Errors
7
+ def error_with_message(msg)
8
+ STDERR.puts msg
9
+ exit 1
10
+ end
11
+ end
12
+ end
@@ -1,173 +1,160 @@
1
- require "fileutils"
2
- require "pathname"
3
- require "trout"
4
-
5
- template_root = File.expand_path(File.join(File.dirname(__FILE__)))
6
- source_paths << File.join(template_root, "files")
7
-
8
- # Helpers
9
-
10
- def action_mailer_host(rails_env, host)
11
- inject_into_file(
12
- "config/environments/#{rails_env}.rb",
13
- "\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
14
- :before => "\nend"
15
- )
16
- end
17
-
18
- def origin
19
- "git://github.com/die-antwort/da-suspenders.git"
20
- end
21
-
22
- def trout(destination_path)
23
- parent = Pathname.new(destination_path).parent
24
- FileUtils.mkdir_p(parent) unless File.exists?(parent)
25
- run "trout checkout --source-root=template/trout #{destination_path} #{origin}"
26
- end
27
-
28
- # Actions
29
-
30
- def create_gemfile_and_install_gems
31
- say "Creating Gemfile and installing gems (this may take a while)", :yellow
32
- trout "Gemfile"
33
- run "bundle install"
34
- end
35
-
36
- def add_staging_environment
37
- say "Adding staging environment", :yellow
38
- run "cp config/environments/production.rb config/environments/staging.rb"
39
- end
40
-
41
- def setup_action_mailer
42
- say "Setting up action mailer config", :yellow
43
- action_mailer_host "development", "localhost:3000"
44
- action_mailer_host "test", "example.com"
45
- action_mailer_host "staging", "#{app_name}.dev.die-antwort.eu"
46
- action_mailer_host "production", "FIXME"
47
- end
48
-
49
- def setup_database
50
- say "Setting up database config", :yellow
51
- template "mysql_database.yml.erb", "config/database.yml", :force => true
52
- rake "db:create"
53
- end
54
-
55
- def setup_german_locale
56
- say "Setting up german locale", :yellow
57
- trout "config/locales/de.yml"
58
- gsub_file 'config/application.rb', '# config.i18n.default_locale = :de', 'config.i18n.default_locale = :de'
59
- end
60
-
61
- def setup_viennese_timezone
62
- say "Setting up viennese timezone", :yellow
63
- gsub_file 'config/application.rb', "# config.time_zone = 'Central Time (US & Canada)'", "config.time_zone = 'Vienna'"
64
- end
65
-
66
- def disable_timestamped_migrations
67
- say "Disabling timestamped migrations", :yellow
68
- inject_into_class "config/application.rb", "Application", "\n config.active_record.timestamped_migrations = false\n\n"
69
- end
70
-
71
- def update_generators_config
72
- say "Updating config for generators", :yellow
73
- generators_config = <<-RUBY
74
- config.generators do |generate|
75
- generate.stylesheets false
76
- generate.test_framework :rspec
77
- end
78
- RUBY
79
- inject_into_class "config/application.rb", "Application", generators_config
80
- end
81
-
82
- def create_application_layout_and_views
83
- say "Creating application layout and shared views", :yellow
84
- trout "app/views/layouts/application.html.erb"
85
- trout "app/views/shared/_flashes.html.erb"
86
- end
87
-
88
- def install_misc_support_files
89
- say "Installing miscellaneous support files", :yellow
90
- trout "config/initializers/errors.rb"
91
- trout "app/helpers/body_class_helper.rb"
92
- end
93
-
94
- def install_app_config
95
- say "Installing app_config", :yellow
96
- generate "app_config:install staging"
97
- end
98
-
99
- def install_compass
100
- say "Installing compass", :yellow
101
- run "compass init rails . --sass-dir app/stylesheets --css-dir public/stylesheets -q"
102
- inside 'app/stylesheets' do
103
- remove_file 'ie.scss'
104
- remove_file 'print.scss'
105
- remove_file 'screen.scss'
106
- empty_directory 'content'
107
- empty_directory 'vendor'
108
- end
109
- trout "app/stylesheets/application.scss"
110
- trout "app/stylesheets/ie.scss"
111
- end
112
-
113
- def install_formtastic
114
- say "Installing formtastic", :yellow
115
- generate "formtastic:install"
116
- remove_file "public/stylesheets/formtastic.css"
117
- remove_file "public/stylesheets/formtastic-changes.css"
118
- trout "lib/templates/erb/scaffold/_form.html.erb"
119
- end
120
-
121
- def install_sprockets_and_jquery
122
- say "Installing sprockets, jQuery, and some other javascripts", :yellow
123
- plugin 'sprockets-rails', :git => 'git://github.com/gmoeck/sprockets-rails.git'
124
- plugin 'jrails', :git => 'git://github.com/die-antwort/jrails.git'
125
- route 'SprocketsApplication.routes(self)'
126
- remove_dir 'public/javascripts'
127
- remove_file "app/javascripts/application.js"
128
- trout "app/javascripts/application.js"
129
- trout "vendor/sprockets/modernizr/src/modernizr.js"
130
- trout "vendor/sprockets/jquery-ujs/src/rails.js"
131
- end
132
-
133
- def install_rspec_and_cucumber
134
- say "Installing rspec and cucumber", :yellow
135
- generate "rspec:install"
136
- generate "cucumber:install", "--rspec --capybara"
137
- inject_into_file "features/support/env.rb",
138
- %{Capybara.save_and_open_page_path = "tmp"\n} +
139
- %{Capybara.javascript_driver = :akephalos\n},
140
- :before => %{Capybara.default_selector = :css}
141
- inject_into_file "features/support/paths.rb",
142
- %{ when %r{"(/.*)?"}\n} +
143
- %{ $1\n\n},
144
- :before => " else"
145
- copy_file "factory_girl_steps.rb", "features/step_definitions/factory_girl_steps.rb"
146
- trout "features/step_definitions/js_steps.rb"
147
- end
148
-
149
- def cleanup
150
- say "Cleaning up", :yellow
151
- remove_file 'README'
152
- remove_file 'public/index.html'
153
- remove_file 'public/images/rails.png'
154
- end
155
-
156
- create_gemfile_and_install_gems
157
- add_staging_environment
158
- setup_database
159
- setup_german_locale
160
- setup_viennese_timezone
161
- disable_timestamped_migrations
162
- update_generators_config
163
- create_application_layout_and_views
164
- install_misc_support_files
165
- install_app_config
166
- install_compass
167
- install_formtastic
168
- install_sprockets_and_jquery
169
- install_rspec_and_cucumber
170
- cleanup
171
-
172
- say "Rails app #{app_name} has been created successully!", :blue
1
+ require "fileutils"
2
+ require "pathname"
3
+ require "trout"
4
+
5
+ template_root = File.expand_path(File.join(File.dirname(__FILE__)))
6
+ source_paths << File.join(template_root, "files")
7
+
8
+ # Helpers
9
+
10
+ def action_mailer_host(rails_env, host)
11
+ inject_into_file(
12
+ "config/environments/#{rails_env}.rb",
13
+ "\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
14
+ :before => "\nend"
15
+ )
16
+ end
17
+
18
+ def origin
19
+ ENV["REPO"].presence || "git://github.com/die-antwort/da-suspenders.git"
20
+ end
21
+
22
+ def trout(destination_path)
23
+ parent = Pathname.new(destination_path).parent
24
+ FileUtils.mkdir_p(parent) unless File.exists?(parent)
25
+ run "trout checkout --source-root=template/trout #{destination_path} #{origin}"
26
+ end
27
+
28
+ # Actions
29
+
30
+ def create_gemfile_and_install_gems
31
+ say "Creating Gemfile and installing gems (this may take a while)", :yellow
32
+ trout "Gemfile"
33
+ run "bundle install"
34
+ end
35
+
36
+ def add_staging_environment
37
+ say "Adding staging environment", :yellow
38
+ run "cp config/environments/production.rb config/environments/staging.rb"
39
+ end
40
+
41
+ def setup_action_mailer
42
+ say "Setting up action mailer config", :yellow
43
+ action_mailer_host "development", "localhost:3000"
44
+ action_mailer_host "test", "example.com"
45
+ action_mailer_host "staging", "#{app_name}.dev.die-antwort.eu"
46
+ action_mailer_host "production", "FIXME"
47
+ end
48
+
49
+ def setup_database
50
+ say "Setting up database config", :yellow
51
+ template "mysql_database.yml.erb", "config/database.yml", :force => true
52
+ rake "db:create"
53
+ end
54
+
55
+ def setup_german_locale
56
+ say "Setting up german locale", :yellow
57
+ trout "config/locales/de.yml"
58
+ gsub_file 'config/application.rb', '# config.i18n.default_locale = :de', 'config.i18n.default_locale = :de'
59
+ end
60
+
61
+ def setup_viennese_timezone
62
+ say "Setting up viennese timezone", :yellow
63
+ gsub_file 'config/application.rb', "# config.time_zone = 'Central Time (US & Canada)'", "config.time_zone = 'Vienna'"
64
+ end
65
+
66
+ def disable_timestamped_migrations
67
+ say "Disabling timestamped migrations", :yellow
68
+ inject_into_class "config/application.rb", "Application", "\n config.active_record.timestamped_migrations = false\n\n"
69
+ end
70
+
71
+ def update_generators_config
72
+ say "Updating config for generators", :yellow
73
+ generators_config = <<-RUBY
74
+ config.generators do |generate|
75
+ generate.stylesheets false
76
+ generate.test_framework :rspec
77
+ end
78
+ RUBY
79
+ inject_into_class "config/application.rb", "Application", generators_config
80
+ end
81
+
82
+ def create_application_layout_and_views
83
+ say "Creating application layout and shared views", :yellow
84
+ trout "app/views/layouts/application.html.erb"
85
+ trout "app/views/shared/_flashes.html.erb"
86
+ end
87
+
88
+ def install_misc_support_files
89
+ say "Installing miscellaneous support files", :yellow
90
+ trout "config/initializers/errors.rb"
91
+ trout "app/helpers/body_class_helper.rb"
92
+ end
93
+
94
+ def install_app_config
95
+ say "Installing app_config", :yellow
96
+ generate "app_config:install staging"
97
+ end
98
+
99
+ def install_compass
100
+ say "Installing compass", :yellow
101
+ remove_file "app/assets/stylesheets/application.css"
102
+ trout "app/assets/stylesheets/application.css.scss"
103
+ trout "app/assets/stylesheets/ie6.css.scss"
104
+ trout "app/assets/stylesheets/ie7.css.scss"
105
+ end
106
+
107
+ def install_formtastic
108
+ say "Installing formtastic", :yellow
109
+ generate "formtastic:install"
110
+ end
111
+
112
+ def install_javascripts
113
+ say "Installing application.js.coffee, modernizr and jquery-ui", :yellow
114
+ remove_file "app/assets/javascripts/application.js"
115
+ trout "app/assets/javascripts/application.js.coffee"
116
+ trout "vendor/assets/javascripts/modernizr.js"
117
+ trout "vendor/assets/javascripts/jquery-ui-1.8.16.js"
118
+ end
119
+
120
+ def install_rspec_and_cucumber
121
+ say "Installing rspec and cucumber", :yellow
122
+ generate "rspec:install"
123
+ generate "cucumber:install", "--rspec --capybara"
124
+ inject_into_file "features/support/env.rb",
125
+ %{Capybara.save_and_open_page_path = "tmp"\n} +
126
+ %{Capybara.javascript_driver = :akephalos\n},
127
+ :before => %{Capybara.default_selector = :css}
128
+ inject_into_file "features/support/paths.rb",
129
+ %{ when %r{"(/.*)?"}\n} +
130
+ %{ $1\n\n},
131
+ :before => " else"
132
+ copy_file "factory_girl_steps.rb", "features/step_definitions/factory_girl_steps.rb"
133
+ trout "features/step_definitions/js_steps.rb"
134
+ end
135
+
136
+ def cleanup
137
+ say "Cleaning up", :yellow
138
+ remove_file 'README'
139
+ remove_file 'public/index.html'
140
+ remove_file 'public/images/rails.png'
141
+ end
142
+
143
+ create_gemfile_and_install_gems
144
+ add_staging_environment
145
+ setup_database
146
+ setup_german_locale
147
+ setup_viennese_timezone
148
+ disable_timestamped_migrations
149
+ update_generators_config
150
+ create_application_layout_and_views
151
+ install_misc_support_files
152
+ install_app_config
153
+ install_compass
154
+ install_formtastic
155
+ install_javascripts
156
+ install_rspec_and_cucumber
157
+ cleanup
158
+
159
+ say "Rails app #{app_name} has been created successully!", :blue
173
160
  say "Remember to run 'rails generate hoptoad' with your API key.", :blue