Permalink
Browse files

get a list of gems when filling out the gemfile

  • Loading branch information...
1 parent b7ca9b5 commit f77e211a01b56adbe2a408d9a6636931c0aee093 @tenderlove tenderlove committed Oct 27, 2013
View
37 railties/lib/rails/generators/app_base.rb
@@ -136,22 +136,35 @@ def comment_if(value)
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
View
4 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -162,6 +162,10 @@ def initialize(*args)
end
end
+ def gemfile_gems
+ rails_gemfile_entry
+ end
+
public_task :set_default_accessors!
public_task :create_root
View
14 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 -%>

0 comments on commit f77e211

Please sign in to comment.