提交 85482e12 编写于 作者: A Agis Anastasopoulos

Switch to 1.9 hash syntax & remove some parentheses when it reads nicer

上级 fe661915
...@@ -164,7 +164,7 @@ Rails own generators are flexible enough to let you customize scaffolding. They ...@@ -164,7 +164,7 @@ Rails own generators are flexible enough to let you customize scaffolding. They
config.generators do |g| config.generators do |g|
g.orm :active_record g.orm :active_record
g.template_engine :erb g.template_engine :erb
g.test_framework :test_unit, :fixture => true g.test_framework :test_unit, fixture: true
end end
``` ```
...@@ -206,7 +206,7 @@ Our first customization on the workflow will be to stop generating stylesheets a ...@@ -206,7 +206,7 @@ Our first customization on the workflow will be to stop generating stylesheets a
config.generators do |g| config.generators do |g|
g.orm :active_record g.orm :active_record
g.template_engine :erb g.template_engine :erb
g.test_framework :test_unit, :fixture => false g.test_framework :test_unit, fixture: false
g.stylesheets false g.stylesheets false
end end
``` ```
...@@ -253,7 +253,7 @@ Which is what we expected. We can now tell scaffold to use our new helper genera ...@@ -253,7 +253,7 @@ Which is what we expected. We can now tell scaffold to use our new helper genera
config.generators do |g| config.generators do |g|
g.orm :active_record g.orm :active_record
g.template_engine :erb g.template_engine :erb
g.test_framework :test_unit, :fixture => false g.test_framework :test_unit, fixture: false
g.stylesheets false g.stylesheets false
g.helper :my_helper g.helper :my_helper
end end
...@@ -292,7 +292,7 @@ Now, when the helper generator is invoked and TestUnit is configured as the test ...@@ -292,7 +292,7 @@ Now, when the helper generator is invoked and TestUnit is configured as the test
```ruby ```ruby
# Search for :helper instead of :my_helper # Search for :helper instead of :my_helper
hook_for :test_framework, :as => :helper hook_for :test_framework, as: :helper
``` ```
And now you can re-run scaffold for another resource and see it generating tests as well! And now you can re-run scaffold for another resource and see it generating tests as well!
...@@ -316,7 +316,7 @@ and revert the last change in `config/application.rb`: ...@@ -316,7 +316,7 @@ and revert the last change in `config/application.rb`:
config.generators do |g| config.generators do |g|
g.orm :active_record g.orm :active_record
g.template_engine :erb g.template_engine :erb
g.test_framework :test_unit, :fixture => false g.test_framework :test_unit, fixture: false
g.stylesheets false g.stylesheets false
end end
``` ```
...@@ -334,7 +334,7 @@ We can easily simulate this behavior by changing our `config/application.rb` onc ...@@ -334,7 +334,7 @@ We can easily simulate this behavior by changing our `config/application.rb` onc
config.generators do |g| config.generators do |g|
g.orm :active_record g.orm :active_record
g.template_engine :erb g.template_engine :erb
g.test_framework :shoulda, :fixture => false g.test_framework :shoulda, fixture: false
g.stylesheets false g.stylesheets false
# Add a fallback! # Add a fallback!
...@@ -379,15 +379,15 @@ Application Templates ...@@ -379,15 +379,15 @@ Application Templates
Now that you've seen how generators can be used _inside_ an application, did you know they can also be used to _generate_ applications too? This kind of generator is referred as a "template". Now that you've seen how generators can be used _inside_ an application, did you know they can also be used to _generate_ applications too? This kind of generator is referred as a "template".
```ruby ```ruby
gem("rspec-rails", :group => "test") gem "rspec-rails", group: "test"
gem("cucumber-rails", :group => "test") gem "cucumber-rails", group: "test"
if yes?("Would you like to install Devise?") if yes?("Would you like to install Devise?")
gem("devise") gem "devise"
generate("devise:install") generate "devise:install"
model_name = ask("What would you like the user model to be called? [user]") model_name = ask("What would you like the user model to be called? [user]")
model_name = "user" if model_name.blank? model_name = "user" if model_name.blank?
generate("devise", model_name) generate "devise", model_name
end end
``` ```
...@@ -421,8 +421,8 @@ NOTE: Methods provided by Thor are not covered this guide and can be found in [T ...@@ -421,8 +421,8 @@ NOTE: Methods provided by Thor are not covered this guide and can be found in [T
Specifies a gem dependency of the application. Specifies a gem dependency of the application.
```ruby ```ruby
gem("rspec", :group => "test", :version => "2.1.0") gem "rspec", group: "test", version: "2.1.0"
gem("devise", "1.1.5") gem "devise", "1.1.5"
``` ```
Available options are: Available options are:
...@@ -434,13 +434,13 @@ Available options are: ...@@ -434,13 +434,13 @@ Available options are:
Any additional options passed to this method are put on the end of the line: Any additional options passed to this method are put on the end of the line:
```ruby ```ruby
gem("devise", :git => "git://github.com/plataformatec/devise", :branch => "master") gem "devise", git: "git://github.com/plataformatec/devise", branch: "master"
``` ```
The above code will put the following line into `Gemfile`: The above code will put the following line into `Gemfile`:
```ruby ```ruby
gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master" gem "devise", git: "git://github.com/plataformatec/devise", branch: "master"
``` ```
### `gem_group` ### `gem_group`
...@@ -466,7 +466,7 @@ add_source "http://gems.github.com" ...@@ -466,7 +466,7 @@ add_source "http://gems.github.com"
Injects a block of code into a defined position in your file. Injects a block of code into a defined position in your file.
```ruby ```ruby
inject_into_file 'name_of_file.rb', :after => "#The code goes below this line. Don't forget the Line break at the end\n" do <<-'RUBY' inject_into_file 'name_of_file.rb', after: "#The code goes below this line. Don't forget the Line break at the end\n" do <<-'RUBY'
puts "Hello World" puts "Hello World"
RUBY RUBY
end end
...@@ -503,7 +503,7 @@ Available options are: ...@@ -503,7 +503,7 @@ Available options are:
* `:env` - Specify an environment for this configuration option. If you wish to use this option with the block syntax the recommended syntax is as follows: * `:env` - Specify an environment for this configuration option. If you wish to use this option with the block syntax the recommended syntax is as follows:
```ruby ```ruby
application(nil, :env => "development") do application(nil, env: "development") do
"config.asset_host = 'http://localhost:3000'" "config.asset_host = 'http://localhost:3000'"
end end
``` ```
...@@ -514,9 +514,9 @@ Runs the specified git command: ...@@ -514,9 +514,9 @@ Runs the specified git command:
```ruby ```ruby
git :init git :init
git :add => "." git add: "."
git :commit => "-m First commit!" git commit: "-m First commit!"
git :add => "onefile.rb", :rm => "badfile.cxx" git add: "onefile.rb", rm: "badfile.cxx"
``` ```
The values of the hash here being the arguments or options passed to the specific git command. As per the final example shown here, multiple git commands can be specified at a time, but the order of their running is not guaranteed to be the same as the order that they were specified in. The values of the hash here being the arguments or options passed to the specific git command. As per the final example shown here, multiple git commands can be specified at a time, but the order of their running is not guaranteed to be the same as the order that they were specified in.
...@@ -526,13 +526,13 @@ The values of the hash here being the arguments or options passed to the specifi ...@@ -526,13 +526,13 @@ The values of the hash here being the arguments or options passed to the specifi
Places a file into `vendor` which contains the specified code. Places a file into `vendor` which contains the specified code.
```ruby ```ruby
vendor("sekrit.rb", '#top secret stuff') vendor "sekrit.rb", '#top secret stuff'
``` ```
This method also takes a block: This method also takes a block:
```ruby ```ruby
vendor("seeds.rb") do vendor "seeds.rb" do
"puts 'in ur app, seeding ur database'" "puts 'in ur app, seeding ur database'"
end end
``` ```
...@@ -542,13 +542,13 @@ end ...@@ -542,13 +542,13 @@ end
Places a file into `lib` which contains the specified code. Places a file into `lib` which contains the specified code.
```ruby ```ruby
lib("special.rb", 'p Rails.root') lib "special.rb", "p Rails.root"
``` ```
This method also takes a block: This method also takes a block:
```ruby ```ruby
lib("super_special.rb") do lib "super_special.rb" do
puts "Super special!" puts "Super special!"
end end
``` ```
...@@ -558,15 +558,15 @@ end ...@@ -558,15 +558,15 @@ end
Creates a Rake file in the `lib/tasks` directory of the application. Creates a Rake file in the `lib/tasks` directory of the application.
```ruby ```ruby
rakefile("test.rake", 'hello there') rakefile "test.rake", "hello there"
``` ```
This method also takes a block: This method also takes a block:
```ruby ```ruby
rakefile("test.rake") do rakefile "test.rake" do
%Q{ %Q{
task :rock => :environment do task rock: :environment do
puts "Rockin'" puts "Rockin'"
end end
} }
...@@ -578,13 +578,13 @@ end ...@@ -578,13 +578,13 @@ end
Creates an initializer in the `config/initializers` directory of the application: Creates an initializer in the `config/initializers` directory of the application:
```ruby ```ruby
initializer("begin.rb", "puts 'this is the beginning'") initializer "begin.rb", "puts 'this is the beginning'"
``` ```
This method also takes a block: This method also takes a block:
```ruby ```ruby
initializer("begin.rb") do initializer "begin.rb" do
puts "Almost done!" puts "Almost done!"
end end
``` ```
...@@ -594,7 +594,7 @@ end ...@@ -594,7 +594,7 @@ end
Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator. Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator.
```ruby ```ruby
generate("scaffold", "forums title:string description:text") generate "scaffold", "forums title:string description:text"
``` ```
...@@ -603,7 +603,7 @@ generate("scaffold", "forums title:string description:text") ...@@ -603,7 +603,7 @@ generate("scaffold", "forums title:string description:text")
Runs the specified Rake task. Runs the specified Rake task.
```ruby ```ruby
rake("db:migrate") rake "db:migrate"
``` ```
Available options are: Available options are:
...@@ -624,7 +624,7 @@ capify! ...@@ -624,7 +624,7 @@ capify!
Adds text to the `config/routes.rb` file: Adds text to the `config/routes.rb` file:
```ruby ```ruby
route("resources :people") route "resources :people"
``` ```
### `readme` ### `readme`
...@@ -632,5 +632,5 @@ route("resources :people") ...@@ -632,5 +632,5 @@ route("resources :people")
Output the contents of a file in the template's `source_path`, usually a README. Output the contents of a file in the template's `source_path`, usually a README.
```ruby ```ruby
readme("README") readme "README"
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册