aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/rails_application_templates.md
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source/rails_application_templates.md')
-rw-r--r--guides/source/rails_application_templates.md37
1 files changed, 20 insertions, 17 deletions
diff --git a/guides/source/rails_application_templates.md b/guides/source/rails_application_templates.md
index 1c5148f46f..c03eb1d0be 100644
--- a/guides/source/rails_application_templates.md
+++ b/guides/source/rails_application_templates.md
@@ -1,4 +1,5 @@
-h2. Rails Application Templates
+Rails Application Templates
+===========================
Application templates are simple Ruby files containing DSL for adding gems/initializers etc. to your freshly created Rails project or an existing Rails project.
@@ -7,9 +8,10 @@ By referring to this guide, you will be able to:
* Use templates to generate/customize Rails applications
* Write your own reusable application templates using the Rails template API
-endprologue.
+--------------------------------------------------------------------------------
-h3. Usage
+Usage
+-----
To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option. This can either be path to a file or a URL.
@@ -25,7 +27,8 @@ $ rake rails:template LOCATION=~/template.rb
$ rake rails:template LOCATION=http://example.com/template.rb
```
-h3. Template API
+Template API
+------------
Rails templates API is very self explanatory and easy to understand. Here's an example of a typical Rails template:
@@ -43,7 +46,7 @@ git :commit => %Q{ -m 'Initial commit' }
The following sections outlines the primary methods provided by the API:
-h4. gem(name, options = {})
+### gem(name, options = {})
Adds a +gem+ entry for the supplied gem to the generated application’s +Gemfile+.
@@ -60,7 +63,7 @@ Please note that this will NOT install the gems for you and you will have to run
bundle install
```
-h4. gem_group(*names, &block)
+### gem_group(*names, &block)
Wraps gem entries inside a group.
@@ -72,7 +75,7 @@ gem_group :development, :test do
end
```
-h4. add_source(source, options = {})
+### add_source(source, options = {})
Adds the given source to the generated application's +Gemfile+.
@@ -82,7 +85,7 @@ For example, if you need to source a gem from "http://code.whytheluckystiff.net"
add_source "http://code.whytheluckystiff.net"
```
-h4. vendor/lib/file/initializer(filename, data = nil, &block)
+### vendor/lib/file/initializer(filename, data = nil, &block)
Adds an initializer to the generated application’s +config/initializers+ directory.
@@ -115,7 +118,7 @@ CODE
That’ll create +app/components+ directory and put +foo.rb+ in there.
-h4. rakefile(filename, data = nil, &block)
+### rakefile(filename, data = nil, &block)
Creates a new rake file under +lib/tasks+ with the supplied tasks:
@@ -133,7 +136,7 @@ end
The above creates +lib/tasks/bootstrap.rake+ with a +boot:strap+ rake task.
-h4. generate(what, args)
+### generate(what, args)
Runs the supplied rails generator with given arguments.
@@ -141,7 +144,7 @@ Runs the supplied rails generator with given arguments.
generate(:scaffold, "person", "name:string", "address:text", "age:number")
```
-h4. run(command)
+### run(command)
Executes an arbitrary command. Just like the backticks. Let's say you want to remove the +public/index.html+ file:
@@ -149,7 +152,7 @@ Executes an arbitrary command. Just like the backticks. Let's say you want to re
run "rm public/index.html"
```
-h4. rake(command, options = {})
+### rake(command, options = {})
Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database:
@@ -163,7 +166,7 @@ You can also run rake tasks with a different Rails environment:
rake "db:migrate", :env => 'production'
```
-h4. route(routing_code)
+### route(routing_code)
This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application:
@@ -171,7 +174,7 @@ This adds a routing entry to the +config/routes.rb+ file. In above steps, we gen
route "root :to => 'person#index'"
```
-h4. inside(dir)
+### inside(dir)
Enables you to run a command from the given directory. For example, if you have a copy of edge rails that you wish to symlink from your new apps, you can do this:
@@ -181,7 +184,7 @@ inside('vendor') do
end
```
-h4. ask(question)
+### ask(question)
+ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding:
@@ -195,7 +198,7 @@ end
CODE
```
-h4. yes?(question) or no?(question)
+### yes?(question) or no?(question)
These methods let you ask questions from templates and decide the flow based on the user’s answer. Lets say you want to freeze rails only if the user want to:
@@ -204,7 +207,7 @@ rake("rails:freeze:gems") if yes?("Freeze rails gems ?")
no?(question) acts just the opposite.
```
-h4. git(:command)
+### git(:command)
Rails templates let you run any git command: