publish_my_data 1.3.0 → 1.3.1
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/app/controllers/publish_my_data/resources_controller.rb +22 -14
 - data/app/views/layouts/publish_my_data/error.html.haml +1 -1
 - data/config/routes.rb +2 -1
 - data/lib/publish_my_data/version.rb +1 -1
 - data/spec/dummy/log/test.log +17560 -0
 - data/spec/factories/resource_factories.rb +12 -1
 - data/spec/features/viewing_resources_spec.rb +19 -1
 - metadata +3 -4
 - data/app/controllers/publish_my_data/errors_controller.rb +0 -10
 
| 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
       1 
2 
     | 
    
         
             
            require_dependency "publish_my_data/application_controller"
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            module PublishMyData
         
     | 
| 
         @@ -25,16 +26,11 @@ module PublishMyData 
     | 
|
| 
       25 
26 
     | 
    
         
             
                # /resource?uri=http://foo.bar
         
     | 
| 
       26 
27 
     | 
    
         
             
                def show
         
     | 
| 
       27 
28 
     | 
    
         
             
                  # RubyProf.start
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
29 
     | 
    
         
             
                  uri = params[:uri]
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                  if uri.present?
         
     | 
| 
       32 
32 
     | 
    
         
             
                    begin
         
     | 
| 
       33 
     | 
    
         
            -
                       
     | 
| 
       34 
     | 
    
         
            -
                      
         
     | 
| 
       35 
     | 
    
         
            -
                      respond_with(resource) do |format|
         
     | 
| 
       36 
     | 
    
         
            -
                        format.html { render_resource(resource) }
         
     | 
| 
       37 
     | 
    
         
            -
                      end
         
     | 
| 
      
 33 
     | 
    
         
            +
                      find_and_render_resource(uri, local: uri.starts_with?('http://' + PublishMyData.local_domain))
         
     | 
| 
       38 
34 
     | 
    
         
             
                    rescue Tripod::Errors::ResourceNotFound
         
     | 
| 
       39 
35 
     | 
    
         
             
                      # if it's not there
         
     | 
| 
       40 
36 
     | 
    
         
             
                      respond_to do |format|
         
     | 
| 
         @@ -53,7 +49,7 @@ module PublishMyData 
     | 
|
| 
       53 
49 
     | 
    
         
             
                # http://example.com/id/blah
         
     | 
| 
       54 
50 
     | 
    
         
             
                def id
         
     | 
| 
       55 
51 
     | 
    
         
             
                  respond_to do |format|
         
     | 
| 
       56 
     | 
    
         
            -
                    format.any(:html, :rdf, :ttl, :nt, :json) do 
     | 
| 
      
 52 
     | 
    
         
            +
                    format.any(:html, :rdf, :ttl, :nt, :json) do
         
     | 
| 
       57 
53 
     | 
    
         
             
                      redirect_to "/doc/#{params[:path]}", :status=> 303
         
     | 
| 
       58 
54 
     | 
    
         
             
                    end
         
     | 
| 
       59 
55 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -62,11 +58,15 @@ module PublishMyData 
     | 
|
| 
       62 
58 
     | 
    
         
             
                # http://example.com/doc/blah
         
     | 
| 
       63 
59 
     | 
    
         
             
                def doc
         
     | 
| 
       64 
60 
     | 
    
         
             
                  uri = Resource.uri_from_host_and_doc_path(request.host, params[:path], params[:format])
         
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 61 
     | 
    
         
            +
                  find_and_render_resource(uri, local: true)
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                # Make a last ditch attempt to dereference the requested url as
         
     | 
| 
      
 65 
     | 
    
         
            +
                # the resource uri.  If it's not found we 404 with ResourceNotFound.
         
     | 
| 
      
 66 
     | 
    
         
            +
                #
         
     | 
| 
      
 67 
     | 
    
         
            +
                # routes.rb maps this as the final catch-all route.
         
     | 
| 
      
 68 
     | 
    
         
            +
                def attempt_local_dereference
         
     | 
| 
      
 69 
     | 
    
         
            +
                  find_and_render_resource(request.original_url, local: true)
         
     | 
| 
       70 
70 
     | 
    
         
             
                end
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
                private
         
     | 
| 
         @@ -90,7 +90,15 @@ module PublishMyData 
     | 
|
| 
       90 
90 
     | 
    
         
             
                  criteria
         
     | 
| 
       91 
91 
     | 
    
         
             
                end
         
     | 
| 
       92 
92 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
                # Attempt to find the resource with uri, and render it as HTML if
         
     | 
| 
      
 94 
     | 
    
         
            +
                # it is found.  If it's not found a
         
     | 
| 
      
 95 
     | 
    
         
            +
                # ResourceNotFound exception will be thrown.
         
     | 
| 
      
 96 
     | 
    
         
            +
                def find_and_render_resource(uri, opts)
         
     | 
| 
      
 97 
     | 
    
         
            +
                  resource = PublishMyData::Resource.find(uri, local: true)
         
     | 
| 
       95 
98 
     | 
    
         | 
| 
      
 99 
     | 
    
         
            +
                  respond_with(resource) do |format|
         
     | 
| 
      
 100 
     | 
    
         
            +
                    format.html { render_resource(resource) }
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
              end
         
     | 
| 
       96 
104 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            = render template: 'layouts/publish_my_data/application'
         
     | 
| 
      
 1 
     | 
    
         
            +
            = render template: 'layouts/publish_my_data/application'
         
     | 
    
        data/config/routes.rb
    CHANGED
    
    | 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
       1 
2 
     | 
    
         
             
            PublishMyData::Engine.routes.draw do
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
              # resource show
         
     | 
| 
         @@ -58,5 +59,5 @@ PublishMyData::Engine.routes.draw do 
     | 
|
| 
       58 
59 
     | 
    
         
             
              #match "/search"                       => "searches#index",        :as => 'search'
         
     | 
| 
       59 
60 
     | 
    
         | 
| 
       60 
61 
     | 
    
         
             
              #http://techoctave.com/c7/posts/36-rails-3-0-rescue-from-routing-error-solution
         
     | 
| 
       61 
     | 
    
         
            -
              match '* 
     | 
| 
      
 62 
     | 
    
         
            +
              match '*path', :to => 'resources#attempt_local_dereference'
         
     | 
| 
       62 
63 
     | 
    
         
             
            end
         
     |