Skip to content

Commit

Permalink
Replace #optimize_indentation calls with String#indent
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
ricardotk002 committed Apr 30, 2018
1 parent aaca4ef commit 462525c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/install/coffee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
before: "module.exports"

say "Updating webpack paths to include .coffee file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .coffee", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .coffee\n".indent(4), after: /extensions:\n/

say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/coffee/hello_coffee.coffee",
Expand Down
2 changes: 1 addition & 1 deletion lib/install/elm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
run "yarn run elm package install -- --yes"

say "Updating webpack paths to include .elm file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .elm", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .elm\n".indent(4), after: /extensions:\n/

say "Updating Elm source location"
gsub_file "elm-package.json", /\"\.\"\n/,
Expand Down
2 changes: 1 addition & 1 deletion lib/install/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
before: "module.exports"

say "Updating webpack paths to include .erb file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .erb", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .erb\n".indent(4), after: /extensions:\n/

say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/erb/hello_erb.js.erb",
Expand Down
2 changes: 1 addition & 1 deletion lib/install/react.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"

say "Updating webpack paths to include .jsx file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .jsx", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .jsx\n".indent(4), after: /extensions:\n/

say "Installing all react dependencies"
run "yarn add react react-dom babel-preset-react prop-types"
Expand Down
20 changes: 10 additions & 10 deletions lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

say "Adding configurations"

check_yarn_integrity_config = ->(value) { <<CONFIG }
check_yarn_integrity_config = ->(value) { <<CONFIG.indent(2) }
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = #{value}
CONFIG
Expand All @@ -26,18 +26,18 @@
environment check_yarn_integrity_config.call("true"), env: :development
environment check_yarn_integrity_config.call("false"), env: :production
else
inject_into_file "config/environments/development.rb", optimize_indentation(check_yarn_integrity_config.call("true"), 2), after: "Rails.application.configure do", verbose: false
inject_into_file "config/environments/production.rb", optimize_indentation(check_yarn_integrity_config.call("false"), 2), after: "Rails.application.configure do", verbose: false
inject_into_file "config/environments/development.rb", "\n#{check_yarn_integrity_config.call("true")}", after: "Rails.application.configure do", verbose: false
inject_into_file "config/environments/production.rb", "\n#{check_yarn_integrity_config.call("false")}", after: "Rails.application.configure do", verbose: false
end

if File.exists?(".gitignore")
append_to_file ".gitignore", optimize_indentation(<<-EOS)
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity
EOS
append_to_file ".gitignore", <<-EOS
/public/packs
/public/packs-test
/node_modules
yarn-debug.log*
.yarn-integrity
EOS
end

say "Installing all JavaScript dependencies"
Expand Down
4 changes: 2 additions & 2 deletions lib/install/typescript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"

say "Updating webpack paths to include .ts file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .ts", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /extensions:\n/

say "Updating webpack paths to include .tsx file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .tsx", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /extensions:\n/

say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
Expand Down
2 changes: 1 addition & 1 deletion lib/install/vue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
before: "module.exports"

say "Updating webpack paths to include .vue file extension"
insert_into_file Webpacker.config.config_path, optimize_indentation("- .vue", 4), after: /extensions:\n/
insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /extensions:\n/

say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
copy_file "#{__dir__}/examples/vue/hello_vue.js",
Expand Down

0 comments on commit 462525c

Please sign in to comment.