Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added a generator option to remove the public/index.html file when generating a new application #2649

Closed
wants to merge 5 commits into from
@ivanvanderbyl

Unless you'e new to Rails you know what the index.html file says and you don't look at it, and more often than not you forget to remove it before firing up rails server expecting to see your freshly crafted index view for welcome_controller.

So isn't it about time we had an option to remove it along with being able to skip-javascript and skip-bundle?

The option I've added is:
-I, [--skip-index-html] # Skip public/index.html file

Thanks to @parndt for pointing me to right files, and @radar for annoyance.

I know I targeted master (It's my first patch) but can we have this in Rails 3.1.1? or sooner?

@ivanvanderbyl ivanvanderbyl Added a generator option to remove the public/index.html file when ge…
…nerating a new Rails application

The option is:
-i, [--skip-index-html]        # Skip public/index.html file
6343134
@parndt

I am massively in favour of this patch!

@dmathieu
Collaborator

+1

@terrcin

+1

@dasch

Please add a test to railties/test/generators/app_generator_test.rb:

  def test_generator_if_skip_index_html_is_given
    run_generator [destination_root, "--skip-index-html"]
    assert_no_file "public/index.html"
  end
@josevalim
Owner

Yes, it lacks tests.

@josevalim josevalim closed this
@josevalim josevalim reopened this
@ivanvanderbyl

Tests added, Thanks @dasch

@malclocke

Agree, with the exception that the option should be uppercase (-I rather than -i) so it matches the other --skip-* options:

-G, [--skip-git]               # Skip Git ignores and keeps
-O, [--skip-active-record]     # Skip Active Record files
-T, [--skip-test-unit]         # Skip Test::Unit files
-S, [--skip-sprockets]         # Skip Sprockets files
-J, [--skip-javascript]        # Skip JavaScript files
@ivanvanderbyl

@malclocke I originally wrote it with -I and decided to change it to -i for being a less important skip. But on second thoughts -I is better for consistency. I'll update it now.

@parndt

I agree @malclocke, I like -I better too. Thanks Ivan!

@fl00r

Love it

@twe4ked

+1

@guilleiguaran

@ivanvanderbyl squash all the commits in a single one

@parndt

What on earth for?

@guilleiguaran

@ivanvanderbyl squashing all the commits in a single one will do it easier to backport (ex. to Rails 3.1.x)

@parndt

Ah, I missed the fact that this pull request targets 'master' and not '3-1-stable'

@guilleiguaran

@parndt Probably this won't be backported to 3.1.0 (right now Rails Core Team is very strict about the commits in this branch), but maybe nice have this in 3.1.1

@vijaydev
Collaborator

Adding documentation would be nice too :)

@ivanvanderbyl

@vijaydev Where are the Rails generators documented?

@vijaydev
Collaborator

I expected the generators guide to cover these, but I can't find them. So I'm not sure if they are documented at all :(

@ivanvanderbyl

I personally think this is pretty self documenting by running rails new --help

@MikeRuby

I +1 this.

@fajrif

+1

@elomarns

It would be nice also delete rails.png, as it's useless without the index.html.

@parndt
@elomarns

@parndt Maybe useless is a bit too strong, but probably most developers delete rails.png too, so I think it would be nice to delete it when deleting index.html.

@parndt
@josevalim
Owner
@parndt
@parndt

@josevalim @elomarns I have a pull request at #3039 for --skip-public-assets

@henrikhodne

What's the status on this?

@josevalim
Owner

NIce, but we need to rebase those commits into one to reflect just the final changes, thanks.

@parndt
@henrikhodne

It makes the commit history clearer, and it's easier to merge.

@josevalim
Owner

It has some benefits. For example, if we eventually need to do a git log, we will be able to see the whole unit of work, the feature implementation plus its tests. Also, the fact --skip-index-html is removing the image file is a bit weird. It should be something like --skip-public-assets. Thanks.

@parndt

@josevalim it's just 4 commits, 3 from Ivan and 1 from me, plus a pull request merge. It effectively shows the history of the issue's solution and if you squashed it it would remove one author for no real purpose? I'm confused as to why one commit is more useful. :-)

@parndt

@josevalim this is what happend to --skip-public-assets in my previous pull request: #3039

@arunagw
Collaborator

Just to follow up this one. What's happening to this PR.

@jrochkind

+1, I'd like to see this too.

@simi

@josevalim still waiting for rebasing into 1 commit ?

@evanfarrar

I approve of this action.

@zires

Cool :)

@malclocke

Pull request #5530 has the commits from this pull request squashed and rebased as requested by @josevalim

@parndt

thanks @malclocke !

@ahawkins

@rafaelfranca can you close this PR because #5530 has all the requested changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 23, 2011
  1. @ivanvanderbyl

    Added a generator option to remove the public/index.html file when ge…

    ivanvanderbyl authored
    …nerating a new Rails application
    
    The option is:
    -i, [--skip-index-html]        # Skip public/index.html file
  2. @ivanvanderbyl

    Added tests to assert that --skip-index-html removes public/index.htm…

    ivanvanderbyl authored
    …l when generating a new application
  3. @ivanvanderbyl
Commits on Sep 15, 2011
  1. @parndt
  2. @ivanvanderbyl

    Merge pull request #1 from parndt/feature/remove-static-index-after-g…

    ivanvanderbyl authored
    …enerate
    
    Extended --skip-index-html to also remove app/assets/images/rails.png
This page is out of date. Refresh to see the latest.
View
3  railties/lib/rails/generators/app_base.rb
@@ -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"
View
5 railties/lib/rails/generators/rails/app/app_generator.rb
@@ -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
View
7 railties/test/generators/app_generator_test.rb
@@ -198,6 +198,13 @@ def test_generator_if_skip_sprockets_is_given
assert_file "test/performance/browsing_test.rb"
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'
Something went wrong with that request. Please try again.