Skip to content

Commit

Permalink
Added a generator option to remove the public/index.html file when ge…
Browse files Browse the repository at this point in the history
…nerating a new Rails application

The option is:
-i, [--skip-index-html]        # Skip public/index.html file
  • Loading branch information
ivanvanderbyl authored and Malcolm Locke committed Mar 21, 2012
1 parent b49a7dd commit 5c1109a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions railties/lib/rails/generators/app_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def self.add_shared_options_for(name)
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
:desc => "Skip JavaScript files"

class_option :skip_index_html, :type => :boolean, :aliases => "-I", :default => false,
:desc => "Skip public/index.html and app/assets/images/rails.png files"

class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"

Expand Down
5 changes: 5 additions & 0 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def log

def public_directory
directory "public", "public", :recursive => false
if options[:skip_index_html]
remove_file "public/index.html"
remove_file 'app/assets/images/rails.png'
git_keep 'app/assets/images'
end
end

def script
Expand Down
7 changes: 7 additions & 0 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ def test_inclusion_of_javascript_runtime
end
end

def test_generator_if_skip_index_html_is_given
run_generator [destination_root, "--skip-index-html"]
assert_no_file "public/index.html"
assert_no_file "app/assets/images/rails.png"
assert_file "app/assets/images/.gitkeep"
end

def test_creation_of_a_test_directory
run_generator
assert_file 'test'
Expand Down

15 comments on commit 5c1109a

@spastorino
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just seen this and I want to suggest something different.
What about reverting this commit, removing index.html and defining a rails engine inside railties that you can mount in '/' if the routes.rb file has still no routes defined ?.

@jeremy
Copy link
Member

@jeremy jeremy commented on 5c1109a May 8, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not need to be an engine, it can be a simple rack app. And it sounds like a good idea. :)

Checking if a route exists can be cumbersome... so we could simply append the route (at the bottom), then as soon as someone defines a new "/", it won't be matched anymore.

@steveklabnik
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 @josevalim

@spastorino
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim true :) and agreed. Not sure about always adding "/" though, because if the user doesn't add a root route it will end having that index view in production.
Anyway we can just generate the "index" route inside config/route.rb itself suggesting the user to just change that.

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guilleiguaran
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spastorino add it only for development environment like /rails/info/properties

@spastorino
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good bros

@jeremy
Copy link
Member

@jeremy jeremy commented on 5c1109a May 8, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim
Copy link
Contributor

@josevalim josevalim commented on 5c1109a May 8, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremy
Copy link
Member

@jeremy jeremy commented on 5c1109a May 8, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guilleiguaran
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reinh
Copy link

@reinh reinh commented on 5c1109a Nov 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to the 👍s

Also 👍 to the feature.

@wpeterson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thumbs Up

Please sign in to comment.