wbzyl-rack-static-assets 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.markdown +91 -0
- data/examples/apache-virtualhost.conf +18 -0
- data/examples/app1/app1.rb +11 -0
- data/examples/app1/config.ru +22 -0
- data/examples/app1/public/images/tatry1.jpg +0 -0
- data/examples/app1/public/javascripts/app1.js +1 -0
- data/examples/app1/public/stylesheets/app1.css +14 -0
- data/examples/app1/public/stylesheets/src/bronzed_olive.png +0 -0
- data/examples/app1/tmp/always_restart.txt +0 -0
- data/examples/app1/views/index.erb +3 -0
- data/examples/app1/views/layout.erb +17 -0
- data/examples/app2/app2.rb +12 -0
- data/examples/app2/config.ru +7 -0
- data/examples/app2/public/images/tatry2.jpg +0 -0
- data/examples/app2/public/javascripts/app2.js +1 -0
- data/examples/app2/public/stylesheets/app2.css +18 -0
- data/examples/app2/public/stylesheets/src/skating.png +0 -0
- data/examples/app2/tmp/always_restart.txt +0 -0
- data/examples/app2/views/index.erb +3 -0
- data/examples/app2/views/layout.erb +17 -0
- data/examples/mapp1/config.ru +14 -0
- data/examples/mapp1/mapp.rb +24 -0
- data/examples/mapp1/public/images/tatry1.jpg +0 -0
- data/examples/mapp1/public/javascripts/mapp.js +1 -0
- data/examples/mapp1/public/stylesheets/mapp.css +14 -0
- data/examples/mapp1/public/stylesheets/src/background.png +0 -0
- data/examples/mapp1/tmp/always_restart.txt +0 -0
- data/examples/mapp1/views/app.erb +3 -0
- data/examples/mapp1/views/layout.erb +23 -0
- data/examples/mapp2/config.ru +14 -0
- data/examples/mapp2/mapp.rb +21 -0
- data/examples/mapp2/public/images/tatry2.jpg +0 -0
- data/examples/mapp2/public/javascripts/mapp.js +1 -0
- data/examples/mapp2/public/stylesheets/mapp.css +14 -0
- data/examples/mapp2/public/stylesheets/src/background.png +0 -0
- data/examples/mapp2/tmp/always_restart.txt +0 -0
- data/examples/mapp2/views/layout.erb +16 -0
- data/examples/mapp2/views/mapp.erb +3 -0
- data/examples/mconfig.ru +19 -0
- data/lib/rack/static-assets.rb +76 -0
- metadata +126 -0
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            (The MIT License)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2009 Wlodek Bzyl
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            'Software'), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
         | 
| 19 | 
            +
            IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
         | 
| 20 | 
            +
            CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
         | 
| 21 | 
            +
            TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
         | 
| 22 | 
            +
            SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.markdown
    ADDED
    
    | @@ -0,0 +1,91 @@ | |
| 1 | 
            +
            # *StaticAssets* Middleware
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            To install it, run:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                sudo gem install wbzyl-sinatra-static-assets -s http://gems.github.com
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            To use, include it in a Sinatra application:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                require 'rubygems'
         | 
| 10 | 
            +
                gem 'static-assets-middleware'
         | 
| 11 | 
            +
                require 'rack/static_assets'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## When you will need this gem?
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            In short, whenever two or more applications are deployed to sub-URI
         | 
| 16 | 
            +
            with Phussion Passenger.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            This means, that we want these applications to be mounted
         | 
| 19 | 
            +
            under one host, `http://example.org` in the example below:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                http://example.org/app1
         | 
| 22 | 
            +
                http://example.org/app2
         | 
| 23 | 
            +
                ...
         | 
| 24 | 
            +
                http://example.org/tests/app3
         | 
| 25 | 
            +
                http://example.org/secret/app3
         | 
| 26 | 
            +
                ...
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            See Phusion Passenger users guide, [Deploying a Rack-based Ruby 
         | 
| 29 | 
            +
            application](http://www.modrails.com/documentation/Users guide Apache.html#_deploying_a_rack_based_ruby_application),
         | 
| 30 | 
            +
            Deploying to a sub URI.
         | 
| 31 | 
            +
             | 
| 32 | 
            +
             | 
| 33 | 
            +
            *How to fix broken images/CSS/JavaScript URIs in sub-URI deployments*
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Some people experience broken images and other broken static assets
         | 
| 36 | 
            +
            when they deploy their application to a sub-URI
         | 
| 37 | 
            +
            (i.e. http://mysite.com/railsapp/). The reason for this usually is
         | 
| 38 | 
            +
            that you used a static URI for your image in the views. This means
         | 
| 39 | 
            +
            your img source probably refers to something like /images/foo.jpg. The
         | 
| 40 | 
            +
            leading slash means that it's an absolute URI: you're telling the
         | 
| 41 | 
            +
            browser to always load http://mysite.com/images/foo.jpg no matter
         | 
| 42 | 
            +
            what. The problem is that the image is actually at
         | 
| 43 | 
            +
            http://mysite.com/railsapp/images/foo.jpg. There are two ways to fix
         | 
| 44 | 
            +
            this.
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            The second and highly recommended way is to always use Rails helper
         | 
| 47 | 
            +
            methods to output tags for static assets. These helper methods
         | 
| 48 | 
            +
            automatically take care of prepending the base URI that you've
         | 
| 49 | 
            +
            deployed the application to. For images there is `image_tag`, for
         | 
| 50 | 
            +
            JavaScript there is `javascript_include_tag` and for CSS there is
         | 
| 51 | 
            +
            `stylesheet_link_tag`. In the above example you would simply remove the
         | 
| 52 | 
            +
            `<img>` HTML tag and replace it with inline Ruby like this:
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                <%= image_tag("foo.jpg") %>
         | 
| 55 | 
            +
             | 
| 56 | 
            +
            This will generate the proper image tag to
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                $RAILS_ROOT/public/images/foo.jpg 
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            so that your images will always work
         | 
| 61 | 
            +
            no matter what sub-URI you've deployed to.
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            ## Deploying to a sub URI
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            Add to */etc/hosts*:
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                127.0.0.1       localhost.localdomain localhost sinatra.local
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            Sym link the application:
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                ln -s ~/public_git/forks/sinatra-static-assets/examples/app1/public /srv/www/sinatra/app1
         | 
| 72 | 
            +
                ln -s ~/public_git/forks/sinatra-static-assets/examples/app2/public /srv/www/sinatra/app2
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            Add to */etc/httpd/conf.d/sinatra.conf*
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                <VirtualHost *:80>
         | 
| 77 | 
            +
                  ServerName sinatra.local
         | 
| 78 | 
            +
                  DocumentRoot /srv/www/sinatra
         | 
| 79 | 
            +
                
         | 
| 80 | 
            +
                  RackBaseURI /app1
         | 
| 81 | 
            +
                  RackBaseURI /app2
         | 
| 82 | 
            +
                </VirtualHost>
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            Now, goto to `http://sinatra.local/app1` or `http://sinatra.local/app2`.
         | 
| 85 | 
            +
             | 
| 86 | 
            +
             | 
| 87 | 
            +
            ## TODO
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            1. Append a timestamp to the URI to better facilitate HTTP
         | 
| 90 | 
            +
               caching. For more information, see the Rails API docs.
         | 
| 91 | 
            +
             | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            <VirtualHost *:80>
         | 
| 2 | 
            +
              ServerName sinatra.local
         | 
| 3 | 
            +
              DocumentRoot /srv/www/sinatra
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              RackBaseURI /app1
         | 
| 6 | 
            +
              RackBaseURI /app2
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              #<Location /app1>
         | 
| 9 | 
            +
              #  PassengerAppRoot /path-to-app1-root
         | 
| 10 | 
            +
              #</Location> 
         | 
| 11 | 
            +
              #
         | 
| 12 | 
            +
              #    or
         | 
| 13 | 
            +
              #
         | 
| 14 | 
            +
              #<Directory /app1>
         | 
| 15 | 
            +
              #  PassengerAppRoot /path-to-app1-root
         | 
| 16 | 
            +
              #</Directory> 
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            </VirtualHost>
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            # run with:  thin --rackup config.ru -p 4567 start
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #use Rack::Static, :urls => ["/stylesheets", "/javascripts", "/images"], :root => "public"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'app1'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            use Rack::ShowExceptions
         | 
| 8 | 
            +
            use Rack::Lint
         | 
| 9 | 
            +
            use Rack::ContentLength
         | 
| 10 | 
            +
            use Rack::StaticAssets, :logging => true
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            App = Rack::Builder.new do 
         | 
| 13 | 
            +
              map '/tatry' do
         | 
| 14 | 
            +
                run Sinatra::Application
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
              map '/gallery' do
         | 
| 18 | 
            +
                run Sinatra::Application
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end  
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            run App
         | 
| Binary file | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            /* app1.js */
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            html {
         | 
| 2 | 
            +
              margin: 0;
         | 
| 3 | 
            +
              padding: 0;
         | 
| 4 | 
            +
              background: #ABA418 url(src/bronzed_olive.png);
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            body {
         | 
| 8 | 
            +
              width: 600px;
         | 
| 9 | 
            +
              margin: 1em auto;
         | 
| 10 | 
            +
              padding: 1em 2em;
         | 
| 11 | 
            +
              border: black solid 1px;
         | 
| 12 | 
            +
              background-color: #D1C704;
         | 
| 13 | 
            +
              font: normal 14px/1.6 Arial, Helvetica, sans-serif;
         | 
| 14 | 
            +
            }
         | 
| Binary file | 
| 
            File without changes
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta http-equiv="content-type" content="text/html; charset=utf-8">
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                <link charset="utf-8" href="/stylesheets/app1.css" media="screen" rel="stylesheet" type="text/css">
         | 
| 7 | 
            +
                <script charset="utf-8" src="/javascripts/app1.js" type="text/javascript"></script>
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                <title><%= @title %></title>
         | 
| 10 | 
            +
              </head>
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              <body>
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                <%= yield %>
         | 
| 15 | 
            +
                
         | 
| 16 | 
            +
              </body>
         | 
| 17 | 
            +
            </html>
         | 
| Binary file | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            /* app1.js */
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            /*
         | 
| 2 | 
            +
                Theme for app2: http://www.colourlovers.com/palette/81363/rainy
         | 
| 3 | 
            +
            */
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            html {
         | 
| 6 | 
            +
              margin: 0;
         | 
| 7 | 
            +
              padding: 0;
         | 
| 8 | 
            +
              background: #659DF1 url(src/skating.png);
         | 
| 9 | 
            +
            }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            body {
         | 
| 12 | 
            +
              width: 600px;
         | 
| 13 | 
            +
              margin: 1em auto;
         | 
| 14 | 
            +
              padding: 1em 2em;
         | 
| 15 | 
            +
              border: black solid 1px;
         | 
| 16 | 
            +
              background-color: #D8E8FF;
         | 
| 17 | 
            +
              font: normal 14px/1.6 Arial, Helvetica, sans-serif;
         | 
| 18 | 
            +
            }
         | 
| Binary file | 
| 
            File without changes
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta http-equiv="content-type" content="text/html; charset=utf-8">
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                <link charset="utf-8" href="/stylesheets/app2.css" media="screen" rel="stylesheet" type="text/css">
         | 
| 7 | 
            +
                <script charset="utf-8" src="/javascripts/app2.js" type="text/javascript"></script>
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                <title><%= @title %></title>
         | 
| 10 | 
            +
              </head>
         | 
| 11 | 
            +
              
         | 
| 12 | 
            +
              <body>
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                <%= yield %>
         | 
| 15 | 
            +
                
         | 
| 16 | 
            +
              </body>
         | 
| 17 | 
            +
            </html>
         | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sinatra/base'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            gem 'sinatra-static-assets'
         | 
| 6 | 
            +
            require 'sinatra/static_assets'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Sinatra
         | 
| 9 | 
            +
              class Mapp1 < Sinatra::Base
         | 
| 10 | 
            +
                helpers Sinatra::UrlForHelper
         | 
| 11 | 
            +
                helpers Sinatra::StaticAssets
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                set :app_file,  __FILE__
         | 
| 14 | 
            +
                set :static, true  
         | 
| 15 | 
            +
                
         | 
| 16 | 
            +
                #set :root, File.dirname(__FILE__)
         | 
| 17 | 
            +
                #set :views, Proc.new { File.join(root, "views") }
         | 
| 18 | 
            +
                
         | 
| 19 | 
            +
                get '/' do
         | 
| 20 | 
            +
                  @title = "Tatra Mountains, Błyszcz (2159 m)"
         | 
| 21 | 
            +
                  erb :app
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
            end
         | 
| Binary file | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            /* mapp1 */
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            html {
         | 
| 2 | 
            +
              margin: 0;
         | 
| 3 | 
            +
              padding: 0;
         | 
| 4 | 
            +
              background: #ABA418 url(src/background.png);
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            body {
         | 
| 8 | 
            +
              width: 600px;
         | 
| 9 | 
            +
              margin: 1em auto;
         | 
| 10 | 
            +
              padding: 1em 2em;
         | 
| 11 | 
            +
              border: black solid 1px;
         | 
| 12 | 
            +
              background-color: #D1C704;
         | 
| 13 | 
            +
              font: normal 14px/1.6 Arial, Helvetica, sans-serif;
         | 
| 14 | 
            +
            }
         | 
| Binary file | 
| 
            File without changes
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta http-equiv="content-type" content="text/html; charset=utf-8">
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            <!-- does not work
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                <link charset="utf-8" href="/stylesheets/mapp.css" media="screen" rel="stylesheet" type="text/css">
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            -->
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                <%= stylesheet_link_tag "/stylesheets/mapp.css" %>
         | 
| 13 | 
            +
                <%= javascript_script_tag "/javascripts/mapp.js" %>
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                <title><%= @title %></title>
         | 
| 16 | 
            +
              </head>
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              <body>
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                <%= yield %>
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
              </body>
         | 
| 23 | 
            +
            </html>
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            # -*- coding: utf-8 -*-
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'sinatra/base'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            gem 'sinatra-static-assets'
         | 
| 6 | 
            +
            require 'sinatra/static_assets'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            module Sinatra
         | 
| 9 | 
            +
              class Mapp2 < Sinatra::Base
         | 
| 10 | 
            +
                helpers Sinatra::UrlForHelper
         | 
| 11 | 
            +
                helpers Sinatra::StaticAssets
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                set :app_file,  __FILE__
         | 
| 14 | 
            +
                set :static, true  
         | 
| 15 | 
            +
                
         | 
| 16 | 
            +
                get '/' do
         | 
| 17 | 
            +
                  @title = "Tatra Mountains, Dolina Gąsienicowa (1500 m)"
         | 
| 18 | 
            +
                  erb :mapp
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| Binary file | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            /* mapp.js */
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            html {
         | 
| 2 | 
            +
              margin: 0;
         | 
| 3 | 
            +
              padding: 0;
         | 
| 4 | 
            +
              background: #ABA418 url(src/background.png);
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            body {
         | 
| 8 | 
            +
              width: 600px;
         | 
| 9 | 
            +
              margin: 1em auto;
         | 
| 10 | 
            +
              padding: 1em 2em;
         | 
| 11 | 
            +
              border: black solid 1px;
         | 
| 12 | 
            +
              background-color: #D8E8FF;
         | 
| 13 | 
            +
              font: normal 14px/1.6 Arial, Helvetica, sans-serif;
         | 
| 14 | 
            +
            }
         | 
| Binary file | 
| 
            File without changes
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" http://www.w3.org/TR/html4/strict.dtd">
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta http-equiv="content-type" content="text/html; charset=utf-8">
         | 
| 5 | 
            +
                <%= stylesheet_link_tag "/stylesheets/mapp.css" %>
         | 
| 6 | 
            +
                <%= javascript_script_tag "/javascripts/mapp.js" %>
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                <title><%= @title %></title>
         | 
| 9 | 
            +
              </head>
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
              <body>
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                <%= yield %>
         | 
| 14 | 
            +
                
         | 
| 15 | 
            +
              </body>
         | 
| 16 | 
            +
            </html>
         | 
    
        data/examples/mconfig.ru
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            require 'mapp1/mapp'
         | 
| 2 | 
            +
            require 'mapp2/mapp'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Mapp = Rack::Builder.new do
         | 
| 5 | 
            +
              use Rack::ShowExceptions
         | 
| 6 | 
            +
              use Rack::Lint
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              #use Rack::Static, :urls => ["/stylesheets", "/images"], :root => "public"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              map '/mapp1' do
         | 
| 11 | 
            +
                run Sinatra::Mapp1.new
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              map '/mapp2' do
         | 
| 15 | 
            +
                run Sinatra::Mapp2.new
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            run Mapp
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            require 'rack/utils'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            gem 'hpricot', '>=0.8.1'
         | 
| 4 | 
            +
            require 'hpricot'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Rack
         | 
| 7 | 
            +
              class StaticAssets
         | 
| 8 | 
            +
                include Rack::Utils
         | 
| 9 | 
            +
                
         | 
| 10 | 
            +
                FORMAT = %{%s - [%s] [%s] "%s %s%s %s" (%s) %d %d %0.4f\n}
         | 
| 11 | 
            +
                
         | 
| 12 | 
            +
                def initialize(app, opts = {})
         | 
| 13 | 
            +
                  @app = app
         | 
| 14 | 
            +
                  
         | 
| 15 | 
            +
                  @opts = { :assets => "http://www.google.com/jsapi" }
         | 
| 16 | 
            +
                  @opts.merge! opts
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def call(env)
         | 
| 20 | 
            +
                  began_at = Time.now
         | 
| 21 | 
            +
                  status, headers, response = @app.call(env)
         | 
| 22 | 
            +
                  headers = HeaderHash.new(headers)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
         | 
| 25 | 
            +
                     !headers['transfer-encoding'] &&
         | 
| 26 | 
            +
                      headers['content-type'] &&
         | 
| 27 | 
            +
                      headers['content-type'].include?("text/html")
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                    content = ""
         | 
| 30 | 
            +
                    response.each { |part| content += part }
         | 
| 31 | 
            +
                    doc = Hpricot(content)
         | 
| 32 | 
            +
                    
         | 
| 33 | 
            +
            #         nodes = doc.search(@opts[:element])
         | 
| 34 | 
            +
            #         nodes.each do |node|
         | 
| 35 | 
            +
            #           s = node.inner_html || "[++where is the code?++]"
         | 
| 36 | 
            +
            #           node.parent.swap(send(@highlighter, s))
         | 
| 37 | 
            +
            #         end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                    body = doc.to_html
         | 
| 40 | 
            +
                    
         | 
| 41 | 
            +
                    # headers['content-length'] = body.bytesize.to_s
         | 
| 42 | 
            +
                    headers.delete('content-length') # will be set by Rack::ContentLength
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    log(env, status, headers, began_at) if @opts[:logging]
         | 
| 45 | 
            +
                    [status, headers, [body]]
         | 
| 46 | 
            +
                  else
         | 
| 47 | 
            +
                    [status, headers, response]  
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
                
         | 
| 51 | 
            +
                private
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def log(env, status, headers, began_at)
         | 
| 54 | 
            +
                  # lilith.local [coderay] text/html [26/may/2009 12:00:00] "GET / HTTP/1.1" 200 ? ?\n
         | 
| 55 | 
            +
                  now = Time.now
         | 
| 56 | 
            +
                   logger = env['rack.errors']
         | 
| 57 | 
            +
                  logger.write FORMAT % [
         | 
| 58 | 
            +
                    env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
         | 
| 59 | 
            +
                    "static assets",
         | 
| 60 | 
            +
                    now.strftime("%d/%b/%Y %H:%M:%S"),
         | 
| 61 | 
            +
                    env["REQUEST_METHOD"],
         | 
| 62 | 
            +
                    env["PATH_INFO"],
         | 
| 63 | 
            +
                    env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
         | 
| 64 | 
            +
                    env["HTTP_VERSION"],
         | 
| 65 | 
            +
                    headers["content-type"] || "unknown",
         | 
| 66 | 
            +
                    status.to_s[0..3],
         | 
| 67 | 
            +
                    headers['content-length'],
         | 
| 68 | 
            +
                    now - began_at
         | 
| 69 | 
            +
                  ]
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
                
         | 
| 72 | 
            +
                def rewrite_asset_tag(element)
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
                
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,126 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: wbzyl-rack-static-assets
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors: 
         | 
| 7 | 
            +
            - Wlodek Bzyl
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            date: 2009-05-31 00:00:00 -07:00
         | 
| 13 | 
            +
            default_executable: 
         | 
| 14 | 
            +
            dependencies: 
         | 
| 15 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 16 | 
            +
              name: rack
         | 
| 17 | 
            +
              type: :runtime
         | 
| 18 | 
            +
              version_requirement: 
         | 
| 19 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 20 | 
            +
                requirements: 
         | 
| 21 | 
            +
                - - ">="
         | 
| 22 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            +
                    version: 1.0.0
         | 
| 24 | 
            +
                version: 
         | 
| 25 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 26 | 
            +
              name: hpricot
         | 
| 27 | 
            +
              type: :runtime
         | 
| 28 | 
            +
              version_requirement: 
         | 
| 29 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 30 | 
            +
                requirements: 
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 33 | 
            +
                    version: 0.8.1
         | 
| 34 | 
            +
                version: 
         | 
| 35 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 36 | 
            +
              name: rack-test
         | 
| 37 | 
            +
              type: :development
         | 
| 38 | 
            +
              version_requirement: 
         | 
| 39 | 
            +
              version_requirements: !ruby/object:Gem::Requirement 
         | 
| 40 | 
            +
                requirements: 
         | 
| 41 | 
            +
                - - ">="
         | 
| 42 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 43 | 
            +
                    version: 0.3.0
         | 
| 44 | 
            +
                version: 
         | 
| 45 | 
            +
            description: Static Assets Middleware is useful.
         | 
| 46 | 
            +
            email: matwb@univ.gda.pl
         | 
| 47 | 
            +
            executables: []
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            extensions: []
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            extra_rdoc_files: 
         | 
| 52 | 
            +
            - LICENSE
         | 
| 53 | 
            +
            - README.markdown
         | 
| 54 | 
            +
            files: 
         | 
| 55 | 
            +
            - examples/apache-virtualhost.conf
         | 
| 56 | 
            +
            - examples/app1/app1.rb
         | 
| 57 | 
            +
            - examples/app1/config.ru
         | 
| 58 | 
            +
            - examples/app1/public/images/tatry1.jpg
         | 
| 59 | 
            +
            - examples/app1/public/javascripts/app1.js
         | 
| 60 | 
            +
            - examples/app1/public/stylesheets/app1.css
         | 
| 61 | 
            +
            - examples/app1/public/stylesheets/src/bronzed_olive.png
         | 
| 62 | 
            +
            - examples/app1/tmp/always_restart.txt
         | 
| 63 | 
            +
            - examples/app1/views/index.erb
         | 
| 64 | 
            +
            - examples/app1/views/layout.erb
         | 
| 65 | 
            +
            - examples/app2/app2.rb
         | 
| 66 | 
            +
            - examples/app2/config.ru
         | 
| 67 | 
            +
            - examples/app2/public/images/tatry2.jpg
         | 
| 68 | 
            +
            - examples/app2/public/javascripts/app2.js
         | 
| 69 | 
            +
            - examples/app2/public/stylesheets/app2.css
         | 
| 70 | 
            +
            - examples/app2/public/stylesheets/src/skating.png
         | 
| 71 | 
            +
            - examples/app2/tmp/always_restart.txt
         | 
| 72 | 
            +
            - examples/app2/views/index.erb
         | 
| 73 | 
            +
            - examples/app2/views/layout.erb
         | 
| 74 | 
            +
            - examples/mapp1/config.ru
         | 
| 75 | 
            +
            - examples/mapp1/mapp.rb
         | 
| 76 | 
            +
            - examples/mapp1/public/images/tatry1.jpg
         | 
| 77 | 
            +
            - examples/mapp1/public/javascripts/mapp.js
         | 
| 78 | 
            +
            - examples/mapp1/public/stylesheets/mapp.css
         | 
| 79 | 
            +
            - examples/mapp1/public/stylesheets/src/background.png
         | 
| 80 | 
            +
            - examples/mapp1/tmp/always_restart.txt
         | 
| 81 | 
            +
            - examples/mapp1/views/app.erb
         | 
| 82 | 
            +
            - examples/mapp1/views/layout.erb
         | 
| 83 | 
            +
            - examples/mapp2/config.ru
         | 
| 84 | 
            +
            - examples/mapp2/mapp.rb
         | 
| 85 | 
            +
            - examples/mapp2/public/images/tatry2.jpg
         | 
| 86 | 
            +
            - examples/mapp2/public/javascripts/mapp.js
         | 
| 87 | 
            +
            - examples/mapp2/public/stylesheets/mapp.css
         | 
| 88 | 
            +
            - examples/mapp2/public/stylesheets/src/background.png
         | 
| 89 | 
            +
            - examples/mapp2/tmp/always_restart.txt
         | 
| 90 | 
            +
            - examples/mapp2/views/layout.erb
         | 
| 91 | 
            +
            - examples/mapp2/views/mapp.erb
         | 
| 92 | 
            +
            - examples/mconfig.ru
         | 
| 93 | 
            +
            - lib/rack/static-assets.rb
         | 
| 94 | 
            +
            - LICENSE
         | 
| 95 | 
            +
            - README.markdown
         | 
| 96 | 
            +
            has_rdoc: false
         | 
| 97 | 
            +
            homepage: http://github.com/wbzyl/rack-static-assets
         | 
| 98 | 
            +
            post_install_message: 
         | 
| 99 | 
            +
            rdoc_options: 
         | 
| 100 | 
            +
            - --charset=UTF-8
         | 
| 101 | 
            +
            require_paths: 
         | 
| 102 | 
            +
            - lib
         | 
| 103 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 104 | 
            +
              requirements: 
         | 
| 105 | 
            +
              - - ">="
         | 
| 106 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 107 | 
            +
                  version: "0"
         | 
| 108 | 
            +
              version: 
         | 
| 109 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 110 | 
            +
              requirements: 
         | 
| 111 | 
            +
              - - ">="
         | 
| 112 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 113 | 
            +
                  version: "0"
         | 
| 114 | 
            +
              version: 
         | 
| 115 | 
            +
            requirements: []
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            rubyforge_project: 
         | 
| 118 | 
            +
            rubygems_version: 1.2.0
         | 
| 119 | 
            +
            signing_key: 
         | 
| 120 | 
            +
            specification_version: 3
         | 
| 121 | 
            +
            summary: Rack Static Assets Middleware
         | 
| 122 | 
            +
            test_files: 
         | 
| 123 | 
            +
            - examples/app2/app2.rb
         | 
| 124 | 
            +
            - examples/mapp2/mapp.rb
         | 
| 125 | 
            +
            - examples/mapp1/mapp.rb
         | 
| 126 | 
            +
            - examples/app1/app1.rb
         |