Application templates are simple ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project.
Executes an arbitrary command. Just like the backticks. Let's say you want to remove the +public/index.html+ file :
<ruby>
run "rm public/index.html"
</ruby>
h4. rake(command, options = {})
Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database :
<ruby>
rake "db:migrate"
</ruby>
You can also run rake tasks with a different Rails environment :
<ruby>
rake "db:migrate", :env => 'production'
</ruby>
Or even use sudo :
<ruby>
rake "gems:install", :sudo => true
</ruby>
h4. 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 :
<ruby>
route "map.root :controller => :person"
</ruby>
h4. inside(dir)
I have my edge rails lying at +~/commit-rails/rails+. So every time i have to manually symlink edge from my new app. But now :
<ruby>
inside('vendor') do
run "ln -s ~/commit-rails/rails rails"
end
</ruby>
So +inside()+ runs the command from the given directory.
h4. 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 :
<ruby>
lib_name = ask("What do you want to call the shiny library ?")
lib_name << ".rb" unless lib_name.index(".rb")
lib lib_name, <<-CODE
class Shiny
end
CODE
</ruby>
h4. 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 :
<ruby>
rake("rails:freeze:gems") if yes?("Freeze rails gems ?")