diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-27 15:11:54 -0300 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-27 15:11:54 -0300 |
commit | f77e211a01b56adbe2a408d9a6636931c0aee093 (patch) | |
tree | a35d26acb192661af3c7d7d4d06b1a5da72dae9a /railties | |
parent | b7ca9b52fe23f979ca5c60039faeac3d844e3ee3 (diff) | |
download | rails-f77e211a01b56adbe2a408d9a6636931c0aee093.tar.gz rails-f77e211a01b56adbe2a408d9a6636931c0aee093.tar.bz2 rails-f77e211a01b56adbe2a408d9a6636931c0aee093.zip |
get a list of gems when filling out the gemfile
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 37 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/Gemfile | 14 |
3 files changed, 42 insertions, 13 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 28a1a0b0f5..6154b2068b 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -136,22 +136,35 @@ module Rails options[value] ? '# ' : '' end + GemfileGem = Struct.new(:name, :comment, :version, :path, :github) do + def self.github(name, github) + new(name, nil, nil, nil, github) + end + + def self.path(name, path) + new(name, nil, nil, path) + end + + def padding(max_width) + ' ' * (max_width - name.length + 2) + end + end + def rails_gemfile_entry if options.dev? - <<-GEMFILE.strip_heredoc - gem 'rails', path: '#{Rails::Generators::RAILS_DEV_PATH}' - gem 'arel', github: 'rails/arel' - GEMFILE + [ + GemfileGem.path('rails', Rails::Generators::RAILS_DEV_PATH), + GemfileGem.github('arel', 'rails/arel'), + ] elsif options.edge? - <<-GEMFILE.strip_heredoc - gem 'rails', github: 'rails/rails' - gem 'arel', github: 'rails/arel' - GEMFILE + [ + GemfileGem.path('rails', 'rails/rails'), + GemfileGem.path('arel', 'rails/arel'), + ] else - <<-GEMFILE.strip_heredoc - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' - gem 'rails', '#{Rails::VERSION::STRING}' - GEMFILE + [ + GemfileGem.new('rails', "Bundle edge Rails instead: gem 'rails', github: 'rails/rails'", Rails::VERSION::STRING) + ] end end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 4e92f56b2d..42b9fe9a34 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -162,6 +162,10 @@ module Rails end end + def gemfile_gems + rails_gemfile_entry + end + public_task :set_default_accessors! public_task :create_root diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index 4048930c8d..21dc915aab 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,6 +1,18 @@ source 'https://rubygems.org' -<%= rails_gemfile_entry -%> +<% max_width = gemfile_gems.map { |g| g.name.length }.max -%> +<% gemfile_gems.each do |gem| -%> +<%= gem.comment -%> +<% if gem.version -%> +gem '<%= gem.name %>',<%= gem.padding(max_width) %>'<%= gem.version %>' +<% elsif gem.path -%> +gem '<%= gem.name %>',<%= gem.padding(max_width) %>path: '<%= gem.path %>' +<% elsif gem.github -%> +gem '<%= gem.name %>',<%= gem.padding(max_width) %>github: '<%= gem.github %>' +<% else -%> +gem '<%= gem.name %>' +<% end -%> +<% end -%> <%= database_gemfile_entry -%> |