Sha256: 4dd51cc5c4e4b7bb763d596757aa5300f5f1b1681cf03f88513d75d9a8a65a0f

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# Meant to be applied on top of a controller that implements
# Blacklight::SolrHelper. 
module BlacklightUnapi::ControllerExtension
  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

  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

  # 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. 
  def unapi_config   
    self.blacklight_config[:unapi] || {}
  end

  def unapi_default_export_formats
    unapi_config
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blacklight_unapi-0.0.3 lib/blacklight_unapi/controller_extension.rb