Module: BlacklightUnapi::ControllerExtension

Defined in:
lib/blacklight_unapi/controller_extension.rb

Overview

Meant to be applied on top of a controller that implements Blacklight::SolrHelper.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(some_class) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/blacklight_unapi/controller_extension.rb', line 4

def self.included(some_class)
  some_class.helper_method :unapi_config
  some_class.helper BlacklightUnapiHelper
  some_class.helper BlacklightUnapi::ViewHelperExtension
  some_class.before_filter do
    extra_head_content << view_context.auto_discovery_link_tag(:unapi, unapi_url, {:type => 'application/xml',  :rel => 'unapi-server', :title => 'unAPI' })
  end
end

Instance Method Details

#unapiObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blacklight_unapi/controller_extension.rb', line 13

def unapi
  @export_formats = unapi_default_export_formats
  @format = params[:format]

  if params[:id]
    @response, @document = get_solr_response_for_doc_id
    @export_formats = @document.export_formats
  end
	
  unless @format
    render 'unapi/formats.xml.builder', :layout => false and return
  end

	
  respond_to do |format|
    format.all do
      send_data @document.export_as(@format), :type => @document.export_formats[@format][:content_type], :disposition => 'inline' if @document.will_export_as @format
    end
  end
end

#unapi_configObject

Uses Blacklight.config, needs to be modified when that changes to be controller-based. This is the only method in this plugin that accesses Blacklight.config, single point of contact.



38
39
40
# File 'lib/blacklight_unapi/controller_extension.rb', line 38

def unapi_config   
  Blacklight.config[:unapi] || {}
end

#unapi_default_export_formatsObject



42
43
44
# File 'lib/blacklight_unapi/controller_extension.rb', line 42

def unapi_default_export_formats
  unapi_config
end