Templates Externos

$ ls
Rakefile               example2-16.rb         views
config.ru

$ cat example2-16.rb 
require 'sinatra/base'

class App < Sinatra::Base
  get '/index' do 
    puts "Visiting #{request.url}"
    erb :index
  end
end

$ cat views/index.erb 
<!DOCTYPE html>
<html> 
  <head>
    <meta charset="UTF-8">
    <title>Inline template</title> 
  </head>
  <body> 
    <h1>Worked!</h1>
  </body> 
</html>

$ cat config.ru 
require './example2-16'

run App

$ cat Rakefile 
task :default => :server

desc "run server"
task :server do
  sh "rackup"
end

desc "make a get / request via curl"
task :root do
  sh "curl -v localhost:9292"
end

desc "make a get /index request via curl"
task :index do 
  sh "curl -v localhost:9292/index"
end

$ rake server
rackup
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
Visiting http://localhost:9292/index
127.0.0.1 - - [03/Jul/2013 22:30:16] "GET /index HTTP/1.1" 200 157 0.0774

$ rake index
curl -v localhost:9292/index
* About to connect() to localhost port 9292 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 9292 (#0)
> GET /index HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8x zlib/1.2.5
> Host: localhost:9292
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Content-Length: 157
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Connection: keep-alive
< Server: thin 1.5.1 codename Straight Razor
< 
<!DOCTYPE html>
<html> 
  <head>
    <meta charset="UTF-8">
    <title>Inline template</title> 
  </head>
  <body> 
    <h1>Worked!</h1>
  </body> 
</html>

* Connection #0 to host localhost left intact
* Closing connection #0



Casiano Rodriguez León 2015-01-07