Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Tutorial

botanicus edited this page Sep 13, 2010 · 16 revisions

This page is up to date for Rango 0.1, but it’s far from being finished. For now I recommend you to take a look at rango-examples

Lets Generate The Project!

Like any other frameworks, Rango has a few generators, so lets generate your new project:

rango create project blog --models=post,tag,comment --controllers=posts
[02:30:29] Running setup.rb hook
[02:30:29] Finished
[02:30:29] [project generator] Running before hooks []
[02:30:29] [project generator] Creating blog (full)
[02:30:29] Context: {:models=>["post", "tag", "comment"], :controllers=>["posts"], :name=>"blog", :orm=>"datamapper", :router=>"usher", :template_engine=>"haml"}
[02:30:29] [COPY] TODO.txt (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/TODO.txt)
[02:30:29] [COPY] templates/index.html.haml (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/templates/index.html.haml)
[02:30:30] [TEMPLATE] templates/base.html.haml (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/templates/base.html.haml.rbt)
[02:30:30] [COPY] spec/spec_helper.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/spec/spec_helper.rb)
[02:30:30] [COPY] spec/spec.opts (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/spec/spec.opts)
[02:30:30] [TEMPLATE] spec/blog/views_spec.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/spec/%name%/views_spec.rb.rbt)
[02:30:30] [TEMPLATE] spec/blog/models_spec.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/spec/%name%/models_spec.rb.rbt)
[02:30:30] [TEMPLATE] spec/blog/init_spec.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/spec/%name%/init_spec.rb.rbt)
[02:30:30] [TEMPLATE] settings_local.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/settings_local.rb.rbt)
[02:30:30] [COPY] settings.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/settings.rb)
[02:30:30] [TEMPLATE] Rakefile (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/Rakefile.rbt)
[02:30:30] [TEMPLATE] init.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/init.rb.rbt)
[02:30:30] [TEMPLATE] Gemfile (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/Gemfile.rbt)
[02:30:30] [TEMPLATE] config.ru (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/project/content/config.ru.rbt)
[02:30:30] Running postprocess.rb hook
chmod +x init.rb

chmod +x config.ru

rango create app blog --orm=datamapper --models=post,tag,comment --controllers=posts
[02:30:34] Running setup.rb hook
[02:30:34] Finished
[02:30:34] [app generator] Running before hooks []
[02:30:34] [app generator] Creating blog (full)
[02:30:34] Context: {:orm=>"datamapper", :models=>["post", "tag", "comment"], :controllers=>["posts"], :name=>"blog"}
[02:30:34] [TEMPLATE] views.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/app/content/views.rb.rbt)
[02:30:35] [TEMPLATE] models.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/app/content/models.rb.rbt)
[02:30:35] [TEMPLATE] init.rb (from /Users/botanicus/.rvm/gems/ruby/1.9.1/gems/rango-0.1.0/stubs/app/content/init.rb.rbt)

[02:30:35] Finished
Do you want to initialize Git repozitory and do initial commit? [Y/n] 
[02:30:36] Running hook SimpleTemplater::Hooks::GitRepository
git init
Initialized empty Git repository in /Users/botanicus/Desktop/tutorial/blog/.git/
git add .

git commit -a -m 'Initial import'
[master (root-commit) 955d737] Initial import
 16 files changed, 403 insertions(+), 0 deletions(-)
 create mode 100644 Gemfile
 create mode 100644 Rakefile
 create mode 100644 TODO.txt
 create mode 100644 blog/init.rb
 create mode 100644 blog/models.rb
 create mode 100644 blog/views.rb
 create mode 100755 config.ru
 create mode 100755 init.rb
 create mode 100644 settings.rb
 create mode 100644 settings_local.rb
 create mode 100644 spec/blog/init_spec.rb
 create mode 100644 spec/blog/models_spec.rb
 create mode 100644 spec/blog/views_spec.rb
 create mode 100644 spec/spec.opts
 create mode 100644 spec/spec_helper.rb
 create mode 100644 templates/base.html.haml
 create mode 100644 templates/index.html.haml

cd blog

Great, welcome to your new project. Now lets run the server:

./config.ru
LoadError during loading gems/environment: no such file to load -- gems/environment.rb
Run gem bundle to fix it.

Ups, we don’t have nothing bundled yet, so lets run the bundler:

gem bundle
Calculating dependencies...
Updating source: http://gems.rubyforge.org
Downloading addressable-2.1.1.gem
Downloading builder-2.1.2.gem
Downloading bundler-0.7.0.gem
Downloading cli-0.0.1.gem
Downloading configuration-1.1.0.gem
Downloading cucumber-0.4.4.gem
Downloading data_objects-0.10.0.gem
Downloading diff-lcs-1.1.2.gem
Downloading dm-aggregates-0.10.1.gem
Downloading dm-core-0.10.1.gem
Downloading dm-timestamps-0.10.1.gem
Downloading do_mysql-0.10.0.gem
Downloading do_sqlite3-0.10.0.gem
Downloading extlib-0.9.13.gem
Downloading fuzzyhash-0.0.9.gem
Downloading haml-2.2.14.gem
Downloading launchy-0.3.3.gem
Downloading media-path-0.1.gem
Downloading nokogiri-1.4.0.gem
Downloading polyglot-0.2.9.gem
Downloading rack-1.0.1.gem
Downloading rack-test-0.5.2.gem
Downloading racksh-0.9.4.2.gem
Downloading rake-0.8.7.gem
Downloading rango-0.1.0.gem
Downloading rspec-1.2.9.gem
Downloading rubyexts-0.0.1.gem
Downloading shotgun-0.4.gem
Downloading simple-templater-0.0.1.gem
Downloading term-ansicolor-1.0.4.gem
Downloading treetop-1.4.2.gem
Downloading usher-0.5.11.gem
Downloading webrat-0.5.3.gem
Installing builder (2.1.2)
Installing polyglot (0.2.9)
Installing treetop (1.4.2)
Installing term-ansicolor (1.0.4)
Installing diff-lcs (1.1.2)
Installing haml (2.2.14)
Installing nokogiri (1.4.0)
Building native extensions.  This could take a while...
Installing cucumber (0.4.4)

(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)

                     (::)   U P G R A D I N G    (::)

Thank you for installing cucumber-0.4.4.
Please be sure to read http://wiki.github.com/aslakhellesoy/cucumber/upgrading
for important information about this release. Happy cuking!

(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)

Installing rspec (1.2.9)
**************************************************

  Thank you for installing rspec-1.2.9

  Please be sure to read History.rdoc and Upgrade.rdoc
  for useful information about this release.

**************************************************
Installing extlib (0.9.13)
Installing dm-core (0.10.1)
Installing dm-aggregates (0.10.1)
Installing dm-timestamps (0.10.1)
Installing fuzzyhash (0.0.9)
Installing usher (0.5.11)
Installing bundler (0.7.0)
Installing rake (0.8.7)
Installing configuration (1.1.0)
Installing launchy (0.3.3)
Installing addressable (2.1.1)
Installing data_objects (0.10.0)
Installing do_mysql (0.10.0)
Building native extensions.  This could take a while...
Installing do_sqlite3 (0.10.0)
Building native extensions.  This could take a while...
Installing rubyexts (0.0.1)
Installing cli (0.0.1)
Installing media-path (0.1)
Installing simple-templater (0.0.1)
Installing rack (1.0.1)
Installing webrat (0.5.3)
Installing rack-test (0.5.2)
Installing racksh (0.9.4.2)
Installing shotgun (0.4)
Installing rango (0.1.0)
Done.

And the server again:

./config.ru
[02:10:59] Loading dependencies for development
[2009-11-25 02:11:06] INFO  WEBrick 1.3.1
[2009-11-25 02:11:06] INFO  ruby 1.9.2 (2009-07-18) [i386-darwin10.0.0]
== Shotgun starting Rack::Handler::WEBrick on :4000
[2009-11-25 02:11:06] INFO  WEBrick::HTTPServer#start: pid=59881 port=4000

Now if you will go to http://localhost:4000, you should get Welcome to Rango page. Great, so it works!

The page mention something about tests. So lets try it:

rake spec
(in /Users/botanicus/Desktop/tutorial/blog)
./bin/spec --options spec/spec.opts spec
[02:28:41] Loading dependencies for test
[02:28:46] Parsing /Users/botanicus/Desktop/tutorial/blog/config.ru
[02:28:46] Using router usher
[02:28:46] Media files are routed directly to the /
......[02:28:47] Middleware Usher::Interface::RackInterface executed
[02:28:47] Dispatching to Blog::ShowCase#index [GET /]
[02:28:47] params: {}
[02:28:47] cookies: {}
[02:28:47] session: {}
[02:28:47] Calling method Blog::ShowCase#index without arguments

[02:28:47] Rendering template index.html
[02:28:47] Extends call: base.html

[02:28:47] Rendering template base.html
[02:28:47] Middleware Usher::Interface::RackInterface finished
.[02:28:47] Middleware Usher::Interface::RackInterface executed
[02:28:47] Dispatching to Blog::ShowCase#index [GET /]
[02:28:47] params: {}
[02:28:47] cookies: {}
[02:28:47] session: {}
[02:28:47] Calling method Blog::ShowCase#index without arguments

[02:28:47] Rendering template index.html
[02:28:47] Extends call: base.html

[02:28:47] Rendering template base.html
[02:28:47] Middleware Usher::Interface::RackInterface finished

Finished in 0.220345 seconds

8 examples, 0 failures

And Write Some Code!

Our blog should has some posts listing, so lets write some tests for it. Open spec/blog/views_spec.rb and replace the last test with:

# spec/blog/views_spec.rb
it "should have an articles" do
  @response.should have_selector(".container .post") do |element|
    element.should contain("Hello World!")
  end
end

If you run rake spec again, this spec should fail. Remove the whole content block from your templates/index.html.haml and replace it by:

# templates/index.html.haml
= block(:content) do
  .container.post
    %h1 Hello World!
Clone this wiki locally