From f77e211a01b56adbe2a408d9a6636931c0aee093 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 27 Oct 2013 15:11:54 -0300 Subject: get a list of gems when filling out the gemfile --- railties/lib/rails/generators/app_base.rb | 37 +++++++++++++++------- .../rails/generators/rails/app/app_generator.rb | 4 +++ .../rails/generators/rails/app/templates/Gemfile | 14 +++++++- 3 files changed, 42 insertions(+), 13 deletions(-) (limited to 'railties') 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 -%> -- cgit v1.2.3