blacklight_unapi 0.0.1rc1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Chris Beer <chris_beer@wgbh.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ BlacklightUnapi: unAPI provider plugin for Blacklight
2
+
3
+ = Description
4
+
5
+ The BlacklightUnapi plugin provides an unapi endpoint for Blacklight records. unAPI is a tiny HTTP API for the few basic operations necessary to copy discrete, identified content from any kind of web application.
6
+
7
+ = Requirements
8
+
9
+ A Rails app using Blacklight >3.x.
10
+
11
+ = Installation
12
+
13
+ Add
14
+
15
+ gem "blacklight_highlight"
16
+
17
+ to your Gemfile and run "bundle install".
18
+
19
+ Then, run "rails generate blacklight_unapi" to install the unAPI configuration and hooks into the CatalogController.
20
+
21
+ = Configuration
22
+
23
+ See ./config/initializers/blacklight_config for unAPI configuration options, where you can list the default set of document formats (which must be available for every document served). By default, this is only OAI Dublin Core.
24
+
25
+
26
+ == Injection
27
+
28
+ This plugin assumes it is in a Blacklight Rails app, uses Blacklight methods, Rails methods, and standard ruby module includes to inject it's behaviors into the app.
29
+
30
+ You can turn off this injection if you like, although it will make the plugin less (or non-) functional unless you manually do similar injection. See lib/blacklight_unapi.rb#inject! to see exactly what's going on.
31
+
32
+ In any initializer, you can set:
33
+
34
+ BlacklightUnapi.omit_inject = true
35
+
36
+ to turn off all injection. The plugin will be completely non-functional if you do this, of course. But perhaps you could try to re-use some of it's classes in a non-Blacklight, highly hacked Blacklight, or even non-Rails application this way.
37
+
38
+ You can also turn off injection of individual components, which could be more useful:
39
+
40
+ BlacklightUnapi.omit_inject = {
41
+ :routes => false,
42
+ }
43
+
44
+ = Tests
45
+
46
+ There are none. This is bad I know, sorry.
47
+
48
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rake'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1rc1
@@ -0,0 +1,5 @@
1
+ module BlacklightUnapiHelper
2
+ def render_document_unapi_microformat document, options = {}
3
+ render :partial =>'unapi/microformat', :locals => {:document => document}.merge(options)
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ <%= content_tag :abbr, '', :class => 'unapi-id', :title => document.id %>
@@ -0,0 +1,6 @@
1
+ xml.instruct!
2
+ xml.formats(({:id => @document.id} if @document) || {}) do
3
+ @export_formats.each do |shortname, meta|
4
+ xml.format :name => shortname, :type => meta[:content_type]
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), "lib/blacklight_unapi/version")
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "blacklight_unapi"
6
+ s.version = BlacklightUnapi::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Chris Beer"]
9
+ s.email = ["chris_beer@wgbh.org"]
10
+ s.homepage = "http://projectblacklight.org/"
11
+ s.summary = "Blacklight unapi plugin"
12
+
13
+ s.rubyforge_project = "blacklight"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+
21
+ s.add_dependency "rails", "~> 3.0"
22
+ s.add_dependency "blacklight"
23
+ end
24
+
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # We want to add a new collection action to Catalog, without over-writing
2
+ # # what's already there. This SEEMS to do it.
3
+ ActionController::Routing::Routes.draw do |map|
4
+ end
5
+
@@ -0,0 +1,46 @@
1
+ # Meant to be applied on top of a controller that implements
2
+ # Blacklight::SolrHelper.
3
+ module BlacklightUnapi::ControllerExtension
4
+ def self.included(some_class)
5
+ some_class.helper_method :unapi_config
6
+ some_class.helper BlacklightUnapiHelper
7
+ some_class.helper BlacklightUnapi::ViewHelperExtension
8
+ some_class.before_filter do
9
+ extra_head_content << view_context.auto_discovery_link_tag(:unapi, unapi_url, {:type => 'application/xml', :rel => 'unapi-server', :title => 'unAPI' })
10
+ end
11
+ end
12
+
13
+ def unapi
14
+ @export_formats = unapi_default_export_formats
15
+ @format = params[:format]
16
+
17
+ if params[:id]
18
+ @response, @document = get_solr_response_for_doc_id
19
+ @export_formats = @document.export_formats
20
+ end
21
+
22
+ unless @format
23
+ render 'unapi/formats.xml.builder', :layout => false and return
24
+ end
25
+
26
+
27
+ respond_to do |format|
28
+ format.all do
29
+ send_data @document.export_as(@format), :type => @document.export_formats[@format][:content_type], :disposition => 'inline' if @document.will_export_as @format
30
+ end
31
+ end
32
+ end
33
+
34
+ # Uses Blacklight.config, needs to be modified when
35
+ # that changes to be controller-based. This is the only method
36
+ # in this plugin that accesses Blacklight.config, single point
37
+ # of contact.
38
+ def unapi_config
39
+ Blacklight.config[:unapi] || {}
40
+ end
41
+
42
+ def unapi_default_export_formats
43
+ unapi_config
44
+ end
45
+
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'blacklight'
2
+ require 'blacklight_unapi'
3
+ require 'rails'
4
+
5
+ module BlacklightUnapi
6
+ class Engine < Rails::Engine
7
+ config.to_prepare do
8
+ unless BlacklightUnapi.omit_inject[:routes]
9
+ Blacklight::Routes.send(:include, BlacklightUnapi::RouteSets)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module BlacklightUnapi
2
+ module RouteSets
3
+ protected
4
+ def catalog
5
+ add_routes do |options|
6
+ match 'catalog/unapi', :to => "catalog#unapi", :as => 'unapi'
7
+ end
8
+
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ module BlacklightUnapi
2
+ unless BlacklightUnapi.const_defined? :VERSION
3
+ def self.version
4
+ @version ||= File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).chomp
5
+ end
6
+
7
+ VERSION = self.version
8
+ end
9
+ end
10
+
@@ -0,0 +1,5 @@
1
+ module BlacklightUnapi::ViewHelperExtension
2
+ def render_document_partial doc, action_name, *args
3
+ (super(doc, action_name, *args) + render_document_unapi_microformat(doc)).html_safe
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # BlacklightUnapi
2
+
3
+ module BlacklightUnapi
4
+ autoload :ControllerExtension, 'blacklight_unapi/controller_extension'
5
+ autoload :ViewHelperExtension, 'blacklight_unapi/view_helper_extension'
6
+ autoload :RouteSets, 'blacklight_unapi/route_sets'
7
+
8
+ require 'blacklight_unapi/version'
9
+ require 'blacklight_unapi/engine'
10
+
11
+ @omit_inject = {}
12
+
13
+ def self.omit_inject=(value)
14
+ value = Hash.new(true) if value == true
15
+ @omit_inject = value
16
+ end
17
+
18
+ def self.omit_inject ; @omit_inject ; end
19
+
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+ require 'rails/generators/migration'
4
+
5
+ class BlacklightUnapiGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+
10
+ argument :controller_name, :type => :string, :default => "CatalogController"
11
+
12
+ def inject_catalog_controller_extension
13
+ file_path = "app/controllers/#{controller_name.underscore}.rb"
14
+ if File.exists? file_path
15
+ inject_into_file file_path, :after => "include Blacklight::Catalog" do
16
+ "\n include BlacklightUnapi::ControllerExtension\n"
17
+ end
18
+ end
19
+ end
20
+
21
+ def inject_unapi_configuration
22
+ insert_into_file 'config/initializers/blacklight_config.rb', :after => "config[:spell_max] = 5\n" do <<EOF
23
+
24
+ # Add documents to the list of object formats that are supported for all objects.
25
+ # This parameter is a hash, identical to the Blacklight::Solr::Document#export_formats
26
+ # output; keys are format short-names that can be exported. Hash includes:
27
+ # :content-type => mime-content-type
28
+
29
+ config[:unapi] = {
30
+ 'oai_dc_xml' => { :content_type => 'text/xml' }
31
+ }
32
+ EOF
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacklight_unapi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15424031
5
+ prerelease: 5
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - rc
11
+ - 1
12
+ version: 0.0.1rc1
13
+ platform: ruby
14
+ authors:
15
+ - Chris Beer
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-08-08 00:00:00 -04:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: rails
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 7
32
+ segments:
33
+ - 3
34
+ - 0
35
+ version: "3.0"
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: blacklight
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description:
53
+ email:
54
+ - chris_beer@wgbh.org
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - VERSION
66
+ - app/helpers/blacklight_unapi_helper.rb
67
+ - app/views/unapi/_microformat.html.erb
68
+ - app/views/unapi/formats.xml.builder
69
+ - blacklight_unapi.gemspec
70
+ - config/routes.rb
71
+ - lib/blacklight_unapi.rb
72
+ - lib/blacklight_unapi/controller_extension.rb
73
+ - lib/blacklight_unapi/engine.rb
74
+ - lib/blacklight_unapi/route_sets.rb
75
+ - lib/blacklight_unapi/version.rb
76
+ - lib/blacklight_unapi/view_helper_extension.rb
77
+ - lib/generators/blacklight_unapi/blacklight_unapi_generator.rb
78
+ has_rdoc: true
79
+ homepage: http://projectblacklight.org/
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">"
100
+ - !ruby/object:Gem::Version
101
+ hash: 25
102
+ segments:
103
+ - 1
104
+ - 3
105
+ - 1
106
+ version: 1.3.1
107
+ requirements: []
108
+
109
+ rubyforge_project: blacklight
110
+ rubygems_version: 1.6.2
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Blacklight unapi plugin
114
+ test_files: []
115
+