blacklight_oembed 0.0.2

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,42 @@
1
+ BlacklightOembed: oEmbed provider plugin for Blacklight
2
+
3
+ = Description
4
+
5
+ The BlacklightOembed plugin provides an oembed endpoint for Blacklight records. oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly. [http://oembed.com/](http://oembed.com/)
6
+
7
+ = Requirements
8
+
9
+ A Rails app using Blacklight >3.x.
10
+
11
+ = Installation
12
+
13
+ Add
14
+
15
+ gem "blacklight_oembed"
16
+
17
+ to your Gemfile and run "bundle install".
18
+
19
+ Then, run "rails generate blacklight_oembed" to install the oEmbed configuration and hooks into the CatalogController.
20
+
21
+ = Configuration
22
+
23
+ See ./config/initializers/blacklight_config for oEmbed configuration options, where you can list the default set of document formats (which must be available for every document served).
24
+
25
+ == Injection
26
+
27
+ 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.
28
+
29
+ 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_oembed.rb#inject! to see exactly what's going on.
30
+
31
+ In any initializer, you can set:
32
+
33
+ BlacklightOembed.omit_inject = true
34
+
35
+ 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.
36
+
37
+ You can also turn off injection of individual components, which could be more useful:
38
+
39
+ BlacklightOembed.omit_inject = {
40
+ :routes => false,
41
+ }
42
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,3 @@
1
+ <iframe src="<%= embed_catalog_url(:id => document[:id]) %>">
2
+
3
+ </iframe>
@@ -0,0 +1,2 @@
1
+ <%= tag :link, :rel => 'alternate', :type => 'text/xml+oembed', :title => 'oEmbed Profile', :href => oembed_url(:format => 'xml', :url => url_for()) %>
2
+ <%= tag :link, :rel => 'alternate', :type => 'text/json+oembed', :title => 'oEmbed Profile', :href => oembed_url(:format => 'json', :url => url_for()) %>
@@ -0,0 +1 @@
1
+ <%= @oembed[:html] %>
@@ -0,0 +1,7 @@
1
+ xml.instruct!
2
+
3
+ xml.oembed do
4
+ @oembed.each do |key, value|
5
+ xml.tag! key, value
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), "lib/blacklight_oembed/version")
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "blacklight_oembed"
6
+ s.version = BlacklightOembed::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 oembed 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,3 @@
1
+ BlacklightOembed::Engine.routes.draw do
2
+
3
+ end
@@ -0,0 +1,37 @@
1
+ # Meant to be applied on top of a controller that implements
2
+ # Blacklight::SolrHelper.
3
+ module BlacklightOembed::ControllerExtension
4
+ def self.included(some_class)
5
+ some_class.helper_method :oembed_config
6
+ some_class.before_filter do
7
+ extra_head_content << render_to_string(:partial => 'oembed/autodiscovery_link.html')
8
+ end
9
+ end
10
+
11
+ def oembed
12
+ url = Rails.application.routes.recognize_path(URI.parse(params[:url]).path,:method=>:get)
13
+ @response, @document = get_solr_response_for_doc_id(url[:id])
14
+
15
+ @oembed = @document.to_oembed({:provider_name => @template.application_name, :provider_url => @template.root_url})
16
+
17
+ @oembed.select { |key,value| value.is_a? Proc }.each do |key, value|
18
+ @oembed[key] = value.call(self)
19
+ end
20
+
21
+ respond_to do |format|
22
+ format.html { render 'oembed/oembed', :layout => false }
23
+ format.xml { render 'oembed/oembed' }
24
+ format.json { render :json => @oembed.to_json }
25
+ end
26
+
27
+ end
28
+
29
+ # Uses Blacklight.config, needs to be modified when
30
+ # that changes to be controller-based. This is the only method
31
+ # in this plugin that accesses Blacklight.config, single point
32
+ # of contact.
33
+ def oembed_config
34
+ Blacklight.config[:oembed] || {}
35
+ end
36
+
37
+ end
@@ -0,0 +1,13 @@
1
+ require 'blacklight'
2
+ require 'blacklight_oembed'
3
+ require 'rails'
4
+
5
+ module BlacklightOembed
6
+ class Engine < Rails::Engine
7
+ config.to_prepare do
8
+ unless BlacklightOembed.omit_inject[:routes]
9
+ Blacklight::Routes.send(:include, BlacklightOembed::RouteSets)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module BlacklightOembed
2
+ module RouteSets
3
+ protected
4
+ def catalog
5
+ add_routes do |options|
6
+ match 'catalog/oembed', :to => "catalog#oembed", :as => 'oembed'
7
+ end
8
+
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module BlacklightOembed::Solr::Document::Oembed
2
+ def self.extended(document)
3
+ BlacklightOembed::Solr::Document::Oembed.register_export_formats( document )
4
+ end
5
+
6
+ def self.register_export_formats(document)
7
+ end
8
+
9
+ def to_oembed(oembed)
10
+ semantic_values = self.to_semantic_values
11
+ ({
12
+ :version => '1.0',
13
+ :type =>' link',
14
+ :title => semantic_values[:title],
15
+ :author_name => semantic_values[:author],
16
+ }).merge(oembed)
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module BlacklightOembed::Solr::Document::OembedRich
2
+ def self.extended(document)
3
+ BlacklightOembed::Solr::Document::OembedRich.register_export_formats( document )
4
+ end
5
+
6
+ def self.register_export_formats(document)
7
+ end
8
+
9
+ def to_oembed(oembed)
10
+ semantic_values = self.to_semantic_values
11
+ ({
12
+ :version => '1.0',
13
+ :type => oembed_type,
14
+ :provider_name => '',
15
+ :provider_url => '',
16
+ :title => semantic_values[:title],
17
+ :author_name => semantic_values[:author],
18
+ :html => (Proc.new do |controller|
19
+ template = controller.instance_variable_get("@template");
20
+ template.with_format(:html) {
21
+ template.render_document_partial(self, 'oembed')
22
+ }
23
+ end)
24
+ }).merge(oembed)
25
+ end
26
+
27
+ def oembed_type
28
+ 'rich'
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module BlacklightOembed::Solr::Document
2
+ autoload :Oembed, 'blacklight_oembed/solr/document/oembed'
3
+ autoload :OembedRich, 'blacklight_oembed/solr/document/oembed_rich'
4
+ end
@@ -0,0 +1,4 @@
1
+ module BlacklightOembed::Solr
2
+ autoload :Document, 'blacklight_oembed/solr/document'
3
+
4
+ end
@@ -0,0 +1,10 @@
1
+ module BlacklightOembed
2
+ unless BlacklightOembed.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,20 @@
1
+ # BlacklightOembed
2
+
3
+ module BlacklightOembed
4
+ autoload :ControllerExtension, 'blacklight_oembed/controller_extension'
5
+ autoload :Solr, 'blacklight_oembed/solr'
6
+ autoload :RouteSets, 'blacklight_oembed/route_sets'
7
+
8
+ require 'blacklight_oembed/version'
9
+ require 'blacklight_oembed/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
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blacklight_oembed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Beer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2156048820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156048820
25
+ - !ruby/object:Gem::Dependency
26
+ name: blacklight
27
+ requirement: &2156047800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2156047800
36
+ description:
37
+ email:
38
+ - chris_beer@wgbh.org
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - MIT-LICENSE
44
+ - README.rdoc
45
+ - Rakefile
46
+ - VERSION
47
+ - app/views/catalog/_oembed_partials/_default.html.erb
48
+ - app/views/oembed/_autodiscovery_link.html.erb
49
+ - app/views/oembed/oembed.html.erb
50
+ - app/views/oembed/oembed.xml.builder
51
+ - blacklight_oembed.gemspec
52
+ - config/routes.rb
53
+ - lib/blacklight_oembed.rb
54
+ - lib/blacklight_oembed/controller_extension.rb
55
+ - lib/blacklight_oembed/engine.rb
56
+ - lib/blacklight_oembed/route_sets.rb
57
+ - lib/blacklight_oembed/solr.rb
58
+ - lib/blacklight_oembed/solr/document.rb
59
+ - lib/blacklight_oembed/solr/document/oembed.rb
60
+ - lib/blacklight_oembed/solr/document/oembed_rich.rb
61
+ - lib/blacklight_oembed/version.rb
62
+ homepage: http://projectblacklight.org/
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project: blacklight
82
+ rubygems_version: 1.8.10
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Blacklight oembed plugin
86
+ test_files: []