Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize indentation for generator actions #30166

Merged

Conversation

yhirano55
Copy link
Contributor

@yhirano55 yhirano55 commented Aug 9, 2017

Summary

I've found that indentations are broken on environment method that is generator's one of actions.

Example template

environment "config.x.a = 1"
environment "config.x.b = 2"
environment do
  <<~RUBY
    config.x.c = 3
    config.x.d = 4
    config.x.e = 5
  RUBY
end

environment "config.x.a = 1", env: "development"
environment "config.x.b = 2", env: "development"
environment nil, env: "development" do
  <<~RUBY
    config.x.c = 3
    config.x.d = 4
    config.x.e = 5
  RUBY
end

Command

$ bin/rails app:template LOCATION=./template.rb

Before

It seems that it's not supported to be used on multiple lines.

$ git diff
diff --git a/config/application.rb b/config/application.rb
index f150d0f..41ae6f8 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -8,6 +8,12 @@ Bundler.require(*Rails.groups)

 module Foobar
   class Application < Rails::Application
+    config.x.c = 3
+config.x.d = 4
+config.x.e = 5
+
+    config.x.b = 2
+    config.x.a = 1
     # Initialize configuration defaults for originally generated Rails version.
     config.load_defaults 5.1

diff --git a/config/environments/development.rb b/config/environments/development.rb
index 2c15c69..f6b467c 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -1,4 +1,10 @@
 Rails.application.configure do
+  config.x.c = 3
+config.x.d = 4
+config.x.e = 5
+
+  config.x.b = 2
+  config.x.a = 1
   # Settings specified here will take precedence over those in config/application.rb.

   # In the development environment your application's code is reloaded on

After

$ git diff
diff --git a/config/application.rb b/config/application.rb
index f150d0f..2254e12 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -8,6 +8,11 @@ Bundler.require(*Rails.groups)

 module Foobar
   class Application < Rails::Application
+    config.x.c = 3
+    config.x.d = 4
+    config.x.e = 5
+    config.x.b = 2
+    config.x.a = 1
     # Initialize configuration defaults for originally generated Rails version.
     config.load_defaults 5.1

diff --git a/config/environments/development.rb b/config/environments/development.rb
index 2c15c69..bf1d891 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -1,4 +1,9 @@
 Rails.application.configure do
+  config.x.c = 3
+  config.x.d = 4
+  config.x.e = 5
+  config.x.b = 2
+  config.x.a = 1
   # Settings specified here will take precedence over those in config/application.rb.

   # In the development environment your application's code is reloaded on

Other Information

This is my use case.

application do
  <<~RUBY
    config.encoding  = "utf-8"
    config.time_zone = "UTC"
    config.active_record.default_timezone = :utc
    config.autoload_paths   += %W(\#{config.root}/lib)
    config.eager_load_paths += %W(\#{config.root}/lib)
  RUBY
end

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@yhirano55 yhirano55 force-pushed the fix_generator_method_environment branch from d1b368d to f952328 Compare August 11, 2017 05:01
@yhirano55 yhirano55 changed the title Fix environment method of generator actions Optimize indentation for generator actions Aug 11, 2017
@yhirano55 yhirano55 force-pushed the fix_generator_method_environment branch 2 times, most recently from f543370 to ba37af2 Compare August 11, 2017 05:32
@yhirano55 yhirano55 force-pushed the fix_generator_method_environment branch from ba37af2 to 8bf0967 Compare August 11, 2017 06:33
@rafaelfranca rafaelfranca merged commit 8bf0967 into rails:master Aug 11, 2017
rafaelfranca added a commit that referenced this pull request Aug 11, 2017
…ment

Optimize indentation for generator actions
@yhirano55 yhirano55 deleted the fix_generator_method_environment branch April 6, 2018 17:10
ricardotk002 added a commit to ricardotk002/webpacker that referenced this pull request Apr 30, 2018
In rails#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with `String#indent`, which is what the
original method uses.
ricardotk002 added a commit to ricardotk002/webpacker that referenced this pull request Apr 30, 2018
In rails#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with the method it uses from behind:
`String#indent`
KingTiger001 added a commit to KingTiger001/Rails-web-pack-project that referenced this pull request Jan 15, 2023
In rails/webpacker#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with the method it uses from behind:
`String#indent`
smartech7 pushed a commit to smartech7/ruby-webpacker that referenced this pull request Aug 4, 2023
In rails/webpacker#1445 I introduced the
method `#optimize_indentation`, but this was added in Rails 5.2
(rails/rails#30166) and Webpacker should
support Rails 4+.

In order to have the same benefit, I'm replacing the calls to the
method `#optimize_indentation` with the method it uses from behind:
`String#indent`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants