aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/generators.md
diff options
context:
space:
mode:
authorAgis Anastasopoulos <corestudiosinc@gmail.com>2012-11-16 12:08:59 +0200
committerAgis Anastasopoulos <corestudiosinc@gmail.com>2012-11-16 12:08:59 +0200
commit85482e126db1c905c36998676884540fcb118c8c (patch)
tree2c5ec140382974fa822c7e2bd39bcb91dc1b6405 /guides/source/generators.md
parentfe661915157ccdb9dc5db752edbb511dc9ddc193 (diff)
downloadrails-85482e126db1c905c36998676884540fcb118c8c.tar.gz
rails-85482e126db1c905c36998676884540fcb118c8c.tar.bz2
rails-85482e126db1c905c36998676884540fcb118c8c.zip
Switch to 1.9 hash syntax & remove some parentheses when it reads nicer
Diffstat (limited to 'guides/source/generators.md')
-rw-r--r--guides/source/generators.md66
1 files changed, 33 insertions, 33 deletions
diff --git a/guides/source/generators.md b/guides/source/generators.md
index d56bbe853c..6226e73f1a 100644
--- a/guides/source/generators.md
+++ b/guides/source/generators.md
@@ -164,7 +164,7 @@ Rails own generators are flexible enough to let you customize scaffolding. They
config.generators do |g|
g.orm :active_record
g.template_engine :erb
- g.test_framework :test_unit, :fixture => true
+ g.test_framework :test_unit, fixture: true
end
```
@@ -206,7 +206,7 @@ Our first customization on the workflow will be to stop generating stylesheets a
config.generators do |g|
g.orm :active_record
g.template_engine :erb
- g.test_framework :test_unit, :fixture => false
+ g.test_framework :test_unit, fixture: false
g.stylesheets false
end
```
@@ -253,7 +253,7 @@ Which is what we expected. We can now tell scaffold to use our new helper genera
config.generators do |g|
g.orm :active_record
g.template_engine :erb
- g.test_framework :test_unit, :fixture => false
+ g.test_framework :test_unit, fixture: false
g.stylesheets false
g.helper :my_helper
end
@@ -292,7 +292,7 @@ Now, when the helper generator is invoked and TestUnit is configured as the test
```ruby
# 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!
@@ -316,7 +316,7 @@ and revert the last change in `config/application.rb`:
config.generators do |g|
g.orm :active_record
g.template_engine :erb
- g.test_framework :test_unit, :fixture => false
+ g.test_framework :test_unit, fixture: false
g.stylesheets false
end
```
@@ -334,7 +334,7 @@ We can easily simulate this behavior by changing our `config/application.rb` onc
config.generators do |g|
g.orm :active_record
g.template_engine :erb
- g.test_framework :shoulda, :fixture => false
+ g.test_framework :shoulda, fixture: false
g.stylesheets false
# Add a fallback!
@@ -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".
```ruby
-gem("rspec-rails", :group => "test")
-gem("cucumber-rails", :group => "test")
+gem "rspec-rails", group: "test"
+gem "cucumber-rails", group: "test"
if yes?("Would you like to install Devise?")
- gem("devise")
- generate("devise:install")
+ gem "devise"
+ generate "devise:install"
model_name = ask("What would you like the user model to be called? [user]")
model_name = "user" if model_name.blank?
- generate("devise", model_name)
+ generate "devise", model_name
end
```
@@ -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.
```ruby
-gem("rspec", :group => "test", :version => "2.1.0")
-gem("devise", "1.1.5")
+gem "rspec", group: "test", version: "2.1.0"
+gem "devise", "1.1.5"
```
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:
```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`:
```ruby
-gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master"
+gem "devise", git: "git://github.com/plataformatec/devise", branch: "master"
```
### `gem_group`
@@ -466,7 +466,7 @@ add_source "http://gems.github.com"
Injects a block of code into a defined position in your file.
```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"
RUBY
end
@@ -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:
```ruby
-application(nil, :env => "development") do
+application(nil, env: "development") do
"config.asset_host = 'http://localhost:3000'"
end
```
@@ -514,9 +514,9 @@ Runs the specified git command:
```ruby
git :init
-git :add => "."
-git :commit => "-m First commit!"
-git :add => "onefile.rb", :rm => "badfile.cxx"
+git add: "."
+git commit: "-m First commit!"
+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.
@@ -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.
```ruby
-vendor("sekrit.rb", '#top secret stuff')
+vendor "sekrit.rb", '#top secret stuff'
```
This method also takes a block:
```ruby
-vendor("seeds.rb") do
+vendor "seeds.rb" do
"puts 'in ur app, seeding ur database'"
end
```
@@ -542,13 +542,13 @@ end
Places a file into `lib` which contains the specified code.
```ruby
-lib("special.rb", 'p Rails.root')
+lib "special.rb", "p Rails.root"
```
This method also takes a block:
```ruby
-lib("super_special.rb") do
+lib "super_special.rb" do
puts "Super special!"
end
```
@@ -558,15 +558,15 @@ end
Creates a Rake file in the `lib/tasks` directory of the application.
```ruby
-rakefile("test.rake", 'hello there')
+rakefile "test.rake", "hello there"
```
This method also takes a block:
```ruby
-rakefile("test.rake") do
+rakefile "test.rake" do
%Q{
- task :rock => :environment do
+ task rock: :environment do
puts "Rockin'"
end
}
@@ -578,13 +578,13 @@ end
Creates an initializer in the `config/initializers` directory of the application:
```ruby
-initializer("begin.rb", "puts 'this is the beginning'")
+initializer "begin.rb", "puts 'this is the beginning'"
```
This method also takes a block:
```ruby
-initializer("begin.rb") do
+initializer "begin.rb" do
puts "Almost done!"
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.
```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")
Runs the specified Rake task.
```ruby
-rake("db:migrate")
+rake "db:migrate"
```
Available options are:
@@ -624,7 +624,7 @@ capify!
Adds text to the `config/routes.rb` file:
```ruby
-route("resources :people")
+route "resources :people"
```
### `readme`
@@ -632,5 +632,5 @@ route("resources :people")
Output the contents of a file in the template's `source_path`, usually a README.
```ruby
-readme("README")
+readme "README"
```