Templates Externos en Subcarpetas

Véase en GitHub sinatra-up-and-running/tree/master/chapter2/views/external_view_files/external_in_subfolders

$ ls
Rakefile  app.rb    config.ru views

$ cat app.rb 
require 'sinatra/base'

class App < Sinatra::Base
  get '/:user/profile' do |user|
    @user = user
    erb '/user/profile'.to_sym
  end

  get '/:user/help' do |user|
    @user = user
    erb :'/user/help'
  end
end

$ cat views/user/profile.erb 
<!DOCTYPE html>
<html> 
  <head>
    <meta charset="UTF-8">
    <title>Profile Template</title> 
  </head>
  <body> 
    <h1>Profile of <%= @user %></h1>
     <%= params %>
  </body> 
</html>

$ cat views/user/help.erb 
<!DOCTYPE html>
<html> 
  <head>
    <meta charset="UTF-8">
    <title>HELP Template</title> 
  </head>
  <body> 
    <h1>Help for user <%= @user %></h1>
     <pre>
       <%= params %>
     </pre>
  </body> 
</html>

$ cat config.ru 
require './app'

run App

$ cat Rakefile 
PORT = 9292
task :default => :server

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

desc "make a get /pepe/profile request via curl"
task :profile, :name do |t, h|
  user = h['name'] || 'pepe'
  sh "curl -v localhost:#{PORT}/#{user}/profile"
end

desc "make a get /pepe/help request via curl"
task :help do 
  sh "curl -v localhost:#{PORT}/pepe/help"
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
127.0.0.1 - - [03/Jul/2013 21:40:04] "GET /Pedro/profile HTTP/1.1" 200 227 0.1077

$ rake profile[Pedro]
curl -v localhost:9292/Pedro/profile
* 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 /Pedro/profile 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: 227
< 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>Profile Template</title> 
  </head>
  <body> 
    <h1>Profile of Pedro</h1>
     {"splat"=>[], "captures"=>["Pedro"], "user"=>"Pedro"}
  </body> 
</html>


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



Casiano Rodriguez León 2015-01-07