ex_cite 1.0.0
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/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +43 -0
- data/app/assets/javascripts/ex_cite/application.js +15 -0
- data/app/assets/javascripts/ex_cite/cite.js +2 -0
- data/app/assets/stylesheets/ex_cite/application.css +13 -0
- data/app/assets/stylesheets/ex_cite/cite.css +4 -0
- data/app/controllers/ex_cite/export_citations_controller.rb +171 -0
- data/app/helpers/ex_cite/application_helper.rb +14 -0
- data/app/models/ex_cite/citation.rb +17 -0
- data/app/models/ex_cite/push_format.rb +15 -0
- data/app/models/ex_cite/resource_key.rb +13 -0
- data/app/views/ex_cite/cite/_external_form.html.erb +26 -0
- data/app/views/ex_cite/cite/external_form.html.erb +1 -0
- data/app/views/layouts/ex_cite/application.html.erb +14 -0
- data/config/initializers/citation.rb +7 -0
- data/config/initializers/mime_types.rb +3 -0
- data/config/routes.rb +3 -0
- data/lib/ex_cite/core_ext.rb +32 -0
- data/lib/ex_cite/engine.rb +44 -0
- data/lib/ex_cite/version.rb +3 -0
- data/lib/tasks/ex_cite_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/type_one.rb +7 -0
- data/test/dummy/app/models/type_two.rb +6 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +20 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130211192047_create_type_ones.rb +11 -0
- data/test/dummy/db/migrate/20130211192122_create_type_twos.rb +11 -0
- data/test/dummy/db/schema.rb +32 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +128 -0
- data/test/dummy/log/test.log +9156 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/type_ones.yml +36 -0
- data/test/dummy/test/fixtures/type_twos.yml +11 -0
- data/test/dummy/test/unit/ex_cite_record_test.rb +7 -0
- data/test/dummy/test/unit/record_test.rb +7 -0
- data/test/dummy/test/unit/type_one_test.rb +7 -0
- data/test/dummy/test/unit/type_two_test.rb +7 -0
- data/test/dummy/tmp/cache/00B/8A1/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_easybib +1 -0
- data/test/dummy/tmp/cache/031/0D1/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_openurl +1 -0
- data/test/dummy/tmp/cache/C5A/FC0/468286998ed7e41613b5b638604d0d418e16f000to_csf +3 -0
- data/test/dummy/tmp/cache/C6C/220/468286998ed7e41613b5b638604d0d418e16f000to_ris +4 -0
- data/test/dummy/tmp/cache/CA2/960/1d506e64f277826763665b38ce9f7000cb23673fto_ris +4 -0
- data/test/dummy/tmp/cache/CEF/FF0/de17f25829c0b9d278f4a4b873a9765a81e10481to_csf +3 -0
- data/test/dummy/tmp/cache/CF2/440/1ad5e264e5a423b07ab635982e79e35290b85c41to_ris +4 -0
- data/test/dummy/tmp/cache/D3B/E70/794c17bcbef330a90c5063ca7b881b06685047aeto_csf +3 -0
- data/test/dummy/tmp/cache/D4D/0D0/794c17bcbef330a90c5063ca7b881b06685047aeto_ris +4 -0
- data/test/dummy/tmp/cache/D5E/ED0/1e1a808df870f039ac20fd161b9c4ea0a3a12101to_ris +4 -0
- data/test/dummy/tmp/cache/D86/BF0/6c38bce413d92f7b510f508f23f947e0be53c60fto_ris +9 -0
- data/test/dummy/tmp/cache/D9C/600/468286998ed7e41613b5b638604d0d418e16f000to_bibtex +2 -0
- data/test/dummy/tmp/cache/DA4/540/affd98a65c2fce8403f2d2776024add085305dc8to_csf +3 -0
- data/test/dummy/tmp/cache/DB6/7A0/affd98a65c2fce8403f2d2776024add085305dc8to_ris +4 -0
- data/test/dummy/tmp/cache/DB8/5B0/a14aff18a493e0f4e01c75d4f39ea2426ff17c89to_ris +9 -0
- data/test/dummy/tmp/cache/DF8/1A0/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_csf +1 -0
- data/test/dummy/tmp/cache/DFD/850/468286998ed7e41613b5b638604d0d418e16f000to_easybib +1 -0
- data/test/dummy/tmp/cache/E0A/400/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_ris +4 -0
- data/test/dummy/tmp/cache/E0F/540/ea6c0a7650e32439bef1894db08c8bbf09a2fac6to_ris +4 -0
- data/test/dummy/tmp/cache/E23/080/468286998ed7e41613b5b638604d0d418e16f000to_openurl +1 -0
- data/test/dummy/tmp/cache/E34/BE0/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_csf +3 -0
- data/test/dummy/tmp/cache/E46/8B0/35f6ed07eec1943f18d5c970502033f3087000a1to_easybib +1 -0
- data/test/dummy/tmp/cache/E46/E40/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_ris +4 -0
- data/test/dummy/tmp/cache/E4E/C40/e493a26438256bfe6a011042b33e1577252cfb89to_easybib +1 -0
- data/test/dummy/tmp/cache/E60/9B0/cc141d92caee81bd0601a5ee365fdf9ec31d23bbto_ris +4 -0
- data/test/dummy/tmp/cache/E68/C90/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_csf +4 -0
- data/test/dummy/tmp/cache/E7A/EF0/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_ris +5 -0
- data/test/dummy/tmp/cache/E7D/EE0/794c17bcbef330a90c5063ca7b881b06685047aeto_bibtex +2 -0
- data/test/dummy/tmp/cache/EDE/F40/794c17bcbef330a90c5063ca7b881b06685047aeto_easybib +1 -0
- data/test/dummy/tmp/cache/EE6/960/affd98a65c2fce8403f2d2776024add085305dc8to_bibtex +2 -0
- data/test/dummy/tmp/cache/F04/770/794c17bcbef330a90c5063ca7b881b06685047aeto_openurl +1 -0
- data/test/dummy/tmp/cache/F3A/580/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_bibtex +2 -0
- data/test/dummy/tmp/cache/F47/050/affd98a65c2fce8403f2d2776024add085305dc8to_easybib +1 -0
- data/test/dummy/tmp/cache/F57/080/32620a8c5f851fed6e2f8a0aa39e6b9d747d7f94to_easybib +1 -0
- data/test/dummy/tmp/cache/F6D/880/affd98a65c2fce8403f2d2776024add085305dc8to_openurl +1 -0
- data/test/dummy/tmp/cache/F76/B00/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_bibtex +2 -0
- data/test/dummy/tmp/cache/F88/580/a303145d2d5cdb18031c0f7cde5d0c3eb5673addto_easybib +1 -0
- data/test/dummy/tmp/cache/F9B/1B0/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_easybib +1 -0
- data/test/dummy/tmp/cache/FAA/570/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_bibtex +3 -0
- data/test/dummy/tmp/cache/FAF/0C0/5c66e1737c71a44c1c2c0c53aacfdbe21a47d22dto_openurl +1 -0
- data/test/dummy/tmp/cache/FC1/9E0/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_openurl +1 -0
- data/test/dummy/tmp/cache/FD7/AF0/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_easybib +1 -0
- data/test/dummy/tmp/cache/FFD/320/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_openurl +1 -0
- data/test/dummy/tmp/cache/assets/C88/210/sprockets%2F3472207be8196858ab6481c8dd11d565 +0 -0
- data/test/dummy/tmp/cache/assets/CA5/4B0/sprockets%2F67891927e7bd2bf4c3101f0601b64c13 +0 -0
- data/test/dummy/tmp/cache/assets/CAA/B20/sprockets%2F16b93e59165164c8025e7bc0d9a0820d +0 -0
- data/test/dummy/tmp/cache/assets/CB8/590/sprockets%2Fa012427e7a6889d39e712c35d3b395e6 +0 -0
- data/test/dummy/tmp/cache/assets/CDA/530/sprockets%2F80873e6605453beaef3e0c77101d51f4 +0 -0
- data/test/dummy/tmp/cache/assets/D0A/C10/sprockets%2F0cdf5169c4f0a054b8a2983d235bf734 +0 -0
- data/test/dummy/tmp/cache/assets/D0A/F70/sprockets%2F14de97f92b1a1c729c25b2f1a334c828 +0 -0
- data/test/dummy/tmp/cache/assets/D1A/C50/sprockets%2Ff78583ed1a84891a6231df3970bb4c5f +0 -0
- data/test/dummy/tmp/cache/assets/D28/3C0/sprockets%2F739cc596997bde456b65f5e4660b45ca +0 -0
- data/test/dummy/tmp/cache/assets/D43/AB0/sprockets%2Fe82e6c7f76371a3bb54b224891fecc25 +0 -0
- data/test/dummy/tmp/cache/assets/DA6/710/sprockets%2F8d5e918def34872c4e7c204b2fce32dd +0 -0
- data/test/dummy/tmp/cache/assets/DE6/DC0/sprockets%2F5bcaed820e6cbee0a0e092561ce0e25a +0 -0
- data/test/dummy/tmp/cache/assets/DF9/B40/sprockets%2F61ea80c2ba85ceb6a249ea3ea3fe5c59 +0 -0
- data/test/dummy/tmp/cache/assets/F28/980/sprockets%2Fcd4defde398dcfb53eea6dd7ba9ad6af +0 -0
- data/test/fixtures/ex_cite/citations.yml +11 -0
- data/test/functional/ex_cite/export_citations _controller_test.rb +123 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +35 -0
- data/test/unit/ex_cite/citation_test.rb +32 -0
- data/test/unit/helpers/ex_cite/cite_helper_test.rb +6 -0
- metadata +478 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2012 YOURNAME
|
|
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
data/Rakefile
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
17
|
+
rdoc.rdoc_dir = 'doc'
|
|
18
|
+
rdoc.title = 'ExCite'
|
|
19
|
+
rdoc.options << '--line-numbers'
|
|
20
|
+
rdoc.options << '--markup markdown'
|
|
21
|
+
rdoc.rdoc_files.include('README.md')
|
|
22
|
+
rdoc.rdoc_files.include('app/**/*.rb')
|
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
27
|
+
load 'rails/tasks/engine.rake'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Bundler::GemHelper.install_tasks
|
|
32
|
+
|
|
33
|
+
require 'rake/testtask'
|
|
34
|
+
|
|
35
|
+
Rake::TestTask.new(:test) do |t|
|
|
36
|
+
t.libs << 'lib'
|
|
37
|
+
t.libs << 'test'
|
|
38
|
+
t.pattern = 'test/**/*_test.rb'
|
|
39
|
+
t.verbose = false
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
task :default => :test
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// the compiled file.
|
|
9
|
+
//
|
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
|
12
|
+
//
|
|
13
|
+
//= require jquery
|
|
14
|
+
//= require jquery_ujs
|
|
15
|
+
//= require_tree .
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
|
10
|
+
*
|
|
11
|
+
*= require_self
|
|
12
|
+
*= require_tree .
|
|
13
|
+
*/
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
require "ex_cite/engine"
|
|
2
|
+
require 'digest/sha1'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
module ExCite
|
|
5
|
+
# Logic behind the webservice. First it gathers all the resource keys and creates Citation objects out of them and then
|
|
6
|
+
# it gathers any and all from formats and data variables that were sent via post and creates an array out of them. If the
|
|
7
|
+
# array is still empty it uses the URL as an OpenURL. It then loops through the array and translates and caches (or fetches)
|
|
8
|
+
# each one using acts_as_citable. It then either downloads the data or redirects to another webservice.
|
|
9
|
+
class ExportCitationsController < ActionController::Base
|
|
10
|
+
# There must be a destination format, or else this whole thing doesnt make sense
|
|
11
|
+
before_filter :valid_to_format?
|
|
12
|
+
layout "ex_cite/application"
|
|
13
|
+
|
|
14
|
+
# Sends bad request if there is no destination format
|
|
15
|
+
def valid_to_format?
|
|
16
|
+
head :bad_request unless to_format
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Checks to see if destination format is valid and stores it in a class variable
|
|
20
|
+
def to_format
|
|
21
|
+
@to_format ||= whitelist_formats :to, params[:to_format]
|
|
22
|
+
end
|
|
23
|
+
private :to_format
|
|
24
|
+
|
|
25
|
+
# Constructs an array containing all the citations
|
|
26
|
+
def citations
|
|
27
|
+
unless defined? @citations
|
|
28
|
+
@citations = record_citation + resource_citation + format_citation
|
|
29
|
+
if @citations.empty?
|
|
30
|
+
@citations << open_url_citation
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
@citations.compact
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def record_citation
|
|
37
|
+
(params[:id].nil?) ? [] :
|
|
38
|
+
params[:id].collect do |id|
|
|
39
|
+
record = ExCite.acts_as_citable_class.find_by_id id if ExCite.acts_as_citable_class.respond_to? :find_by_id
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Constructs new citation objects with only the citation key set, returns an array
|
|
44
|
+
def resource_citation
|
|
45
|
+
(params[:resource_key].nil?) ? [] :
|
|
46
|
+
params[:resource_key].collect do |key|
|
|
47
|
+
citation = ExCite.acts_as_citable_class.new()
|
|
48
|
+
citation.resource_key = key
|
|
49
|
+
citation
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Constructs new citation objects with data and source format set (the citation key is constructed automatically), returns an array
|
|
54
|
+
def format_citation
|
|
55
|
+
(params[:from_format].nil? || params[:data].nil?) ? [] :
|
|
56
|
+
params[:from_format].collect.with_index do |format, index|
|
|
57
|
+
# p ActsAsCitableClass.format_field
|
|
58
|
+
ExCite.acts_as_citable_class.new ExCite.acts_as_citable_class.data_field.to_sym => params[:data].to_a[index], ExCite.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, format)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Returns a single citation object with data and format set as the url and openurl respectively
|
|
63
|
+
def open_url_citation
|
|
64
|
+
ExCite.acts_as_citable_class.new ExCite.acts_as_citable_class.data_field.to_sym => CGI::unescape(request.protocol+request.host_with_port+request.fullpath), ExCite.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, 'openurl')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Maps the output and caches it, alternatively it fetches the already cached result. Seperates each output with two new lines.
|
|
68
|
+
# Raises an argument error if any error is caught in mapping (usually the formats are messed up)
|
|
69
|
+
def map
|
|
70
|
+
@output ||=
|
|
71
|
+
citations.collect { |citation| Rails.cache.fetch(citation.resource_key+to_format) { citation.send(to_format) } }.join "\n\n"
|
|
72
|
+
rescue Exception => exc
|
|
73
|
+
raise ArgumentError, "#{exc}\n Data or source format not provided and/or mismatched. [citations => #{citations}, to_format => #{@to_format}]"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Maps then decides wether its a push request or a download, catches all bad argument errors
|
|
77
|
+
def index
|
|
78
|
+
map
|
|
79
|
+
serve
|
|
80
|
+
rescue ArgumentError => exc
|
|
81
|
+
handle_invalid_arguments exc
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Pushes to a web service if that is what was requested else it downloads
|
|
85
|
+
def serve
|
|
86
|
+
@push_to ? push : download
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Cleans the user input and finds the associated method for that format
|
|
90
|
+
def whitelist_formats direction, format
|
|
91
|
+
# if the params are nil then it returns nil
|
|
92
|
+
if direction.nil? || format.nil?
|
|
93
|
+
return
|
|
94
|
+
end
|
|
95
|
+
# if the to format is found, it returns the method name for that to format
|
|
96
|
+
if (direction == :to && Citero.to_formats.include?(format.downcase))
|
|
97
|
+
return "#{:to.to_s}_#{format.downcase}"
|
|
98
|
+
# if the from format is found, it returns just that because the object already knows what method to call
|
|
99
|
+
elsif (direction == :from && Citero.from_formats.include?(format.downcase))
|
|
100
|
+
return format.downcase
|
|
101
|
+
end
|
|
102
|
+
# if the format is still not found, it might be a push request, check if that is the case
|
|
103
|
+
if ExCite.push_formats.include? format.to_sym
|
|
104
|
+
@push_to = ExCite.push_formats[format.to_sym]
|
|
105
|
+
@to_format = @push_to.to_format.downcase
|
|
106
|
+
return "#{direction.to_s}_#{@to_format}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# For debugging purposes prints out the error. Also sends bad request header
|
|
111
|
+
def handle_invalid_arguments exc
|
|
112
|
+
p exc
|
|
113
|
+
logger.debug exc
|
|
114
|
+
head :bad_request
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Redirects or calls a predefined method depending on the webservice selected
|
|
118
|
+
def push
|
|
119
|
+
# for redirects
|
|
120
|
+
if @push_to.action.eql? :redirect
|
|
121
|
+
# Openurl is data
|
|
122
|
+
@data = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
|
|
123
|
+
# and redirect to the url supplied by the webservice and the callback url
|
|
124
|
+
redirect_to @push_to.url+callback, :status => 303
|
|
125
|
+
elsif @push_to.action.eql? :render
|
|
126
|
+
# call the method this service needs
|
|
127
|
+
render_push @push_to
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# sends the data with utf-8 encoding
|
|
132
|
+
def download
|
|
133
|
+
send_data @output.force_encoding('UTF-8'), :filename => filename, :type => @to_format.formatize.to_sym
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# The callback url is defined here
|
|
137
|
+
def callback
|
|
138
|
+
# Starts with current url minus the querystring..
|
|
139
|
+
callback = "#{export_citations_url}?"
|
|
140
|
+
citations.collect do |citation|
|
|
141
|
+
# then adds a resource key for each cached resource
|
|
142
|
+
callback += (!citation.respond_to? :new_record || citation.new_record?) ? "resource_key[]=#{citation.resource_key}&" : "id[]=#{citation.id}&"
|
|
143
|
+
end
|
|
144
|
+
# and finally the to format
|
|
145
|
+
callback += "to_format=#{@to_format.formatize}"
|
|
146
|
+
# url encode and return
|
|
147
|
+
ERB::Util.url_encode(callback)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Creates the filename and extension. Few are application specific
|
|
151
|
+
def filename
|
|
152
|
+
name = "export"
|
|
153
|
+
case @to_format
|
|
154
|
+
when "to_bibtex"
|
|
155
|
+
name += ".bib"
|
|
156
|
+
when "to_easybib"
|
|
157
|
+
name += ".json"
|
|
158
|
+
else
|
|
159
|
+
name += "." + @to_format.formatize
|
|
160
|
+
end
|
|
161
|
+
name
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def render_push push
|
|
165
|
+
push.vars.each do |key, value|
|
|
166
|
+
instance_variable_set "@#{key}", value.outputize(@output)
|
|
167
|
+
end
|
|
168
|
+
render :template => push.template
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module ExCite
|
|
2
|
+
module ApplicationHelper
|
|
3
|
+
def build_external_form
|
|
4
|
+
f = ""
|
|
5
|
+
@elements.each do |element|
|
|
6
|
+
# Return input element for no js and not textarea
|
|
7
|
+
f += "<input name=\"#{element[:name]}\" type=\"#{(element[:type].nil?) ? "text" : element[:type]}\" value='#{element[:value]}' />" unless (element[:type] and element[:type].eql?("textarea"))
|
|
8
|
+
# Return textarea element for no js and type=textarea
|
|
9
|
+
f += "<textarea name=\"#{element[:name]}\" id=\"#{element[:name]}\">#{element[:value]}</textarea>" unless (element[:type].nil? or not element[:type].eql?("textarea"))
|
|
10
|
+
end
|
|
11
|
+
return f
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module ExCite
|
|
2
|
+
# Citation class, holds data from format and/or resource key
|
|
3
|
+
class Citation
|
|
4
|
+
extend ActsAsCitable
|
|
5
|
+
include ResourceKey
|
|
6
|
+
# Required fields
|
|
7
|
+
attr_accessor :data, :from_format
|
|
8
|
+
acts_as_citable do |c|
|
|
9
|
+
c.format_field = :from_format
|
|
10
|
+
end
|
|
11
|
+
def initialize args = {}
|
|
12
|
+
self.data = args[:data]
|
|
13
|
+
self.from_format = args[:from_format]
|
|
14
|
+
self.resource_key = args[:resource_key]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module ExCite
|
|
2
|
+
# Citation class, holds data from format and/or resource key
|
|
3
|
+
class PushFormat
|
|
4
|
+
# Required fields
|
|
5
|
+
attr_accessor :name, :to_format, :action, :vars, :template, :url
|
|
6
|
+
def initialize args = {}
|
|
7
|
+
self.name = args[:name]
|
|
8
|
+
self.to_format = args[:to_format]
|
|
9
|
+
self.action = args[:action]
|
|
10
|
+
self.vars = args[:vars]
|
|
11
|
+
self.template = args[:template]
|
|
12
|
+
self.url = args[:url]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module ExCite
|
|
2
|
+
module ResourceKey
|
|
3
|
+
def self.included(klass)
|
|
4
|
+
klass.class_eval do
|
|
5
|
+
attr_writer :resource_key
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
# Construct a resource key if it doesn't already exist
|
|
9
|
+
def resource_key
|
|
10
|
+
@resource_key ||= Digest::SHA1.hexdigest(_data)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%= javascript_tag do %>
|
|
2
|
+
jQuery(document).ready(function($) {
|
|
3
|
+
submit_external_form();
|
|
4
|
+
function submit_external_form() {
|
|
5
|
+
// Hide the page
|
|
6
|
+
$("body").hide();
|
|
7
|
+
$form = $(".external_form");
|
|
8
|
+
$form.trigger("submit");
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
<% end %>
|
|
12
|
+
<div class="inner_form_dialog">
|
|
13
|
+
<form id="<%= @id %>" action="<%= @action %>" method="<%= @method %>" class="external_form" enctype="<%= @enctype %>">
|
|
14
|
+
<h2><%= @name %></h2>
|
|
15
|
+
<div class="formError">
|
|
16
|
+
<%= @error || flash[:error] %>
|
|
17
|
+
</div>
|
|
18
|
+
<fieldset>
|
|
19
|
+
<legend><%= @legend %></legend>
|
|
20
|
+
<%= raw build_external_form %>
|
|
21
|
+
<div class="section">
|
|
22
|
+
<%= submit_tag @name%>
|
|
23
|
+
</div>
|
|
24
|
+
</fieldset>
|
|
25
|
+
</form>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div class="no_js"><%= render :partial=>"ex_cite/cite/external_form" %></div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>ExCite</title>
|
|
5
|
+
<%= stylesheet_link_tag "ex_cite/application", :media => "all" %>
|
|
6
|
+
<%= javascript_include_tag "ex_cite/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
String.class_eval do
|
|
2
|
+
def formatize
|
|
3
|
+
self.split('_',2).last.strip
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def collect &block
|
|
7
|
+
self.split('',1).collect &block
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_a
|
|
11
|
+
self.split('',1)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def outputize output
|
|
15
|
+
if self.include? "@output"
|
|
16
|
+
self.gsub!("@output", output)
|
|
17
|
+
end
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
Hash.class_eval do
|
|
23
|
+
def outputize output
|
|
24
|
+
self.values.each {|val| val.outputize output}
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Array.class_eval do
|
|
29
|
+
def outputize output
|
|
30
|
+
self.each {|val| val.outputize output}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require 'ex_cite/core_ext'
|
|
2
|
+
require "acts_as_citable"
|
|
3
|
+
|
|
4
|
+
module ExCite
|
|
5
|
+
mattr_accessor :acts_as_citable_class
|
|
6
|
+
mattr_accessor :push_formats
|
|
7
|
+
def self.acts_as_citable_class
|
|
8
|
+
@@acts_as_citable_class.constantize
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Engine < Rails::Engine
|
|
12
|
+
isolate_namespace ExCite
|
|
13
|
+
engine_name "ex_cite"
|
|
14
|
+
ExCite.acts_as_citable_class = "ExCite::Citation"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.config &block
|
|
18
|
+
if block
|
|
19
|
+
yield self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.push_formats
|
|
24
|
+
@easybib ||= PushFormat.new( :name => :easybibpush, :to_format => :easybib, :action => :render, :template => "ex_cite/cite/external_form",
|
|
25
|
+
:vars => Hash[
|
|
26
|
+
"elements" => [{:name => 'data', :value => "[ @output ]", :type => 'textarea'}],
|
|
27
|
+
"name" => "Push to EasyBib",
|
|
28
|
+
"action" => "http://www.easybib.com/cite/bulk",
|
|
29
|
+
"method" => "POST",
|
|
30
|
+
"enctype" => "application/x-www-form-urlencoded"
|
|
31
|
+
])
|
|
32
|
+
@endnote ||= PushFormat.new :name => :endnote, :to_format => :ris, :action => :redirect, :url => 'http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl='
|
|
33
|
+
# @refworks ||= PushFormat.new :name => :refworks, :to_format => :ris, :action => :redirect, :url => 'http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RIS%20Format&encoding=65001&url='
|
|
34
|
+
@refworks ||= PushFormat.new( :name => :refworks, :to_format => :ris, :action => :render, :template => "ex_cite/cite/external_form",
|
|
35
|
+
:vars => Hash[
|
|
36
|
+
"elements" => [{:name => 'ImportData', :value => "@output", :type => 'textarea'}],
|
|
37
|
+
"name" => "ExportRWForm",
|
|
38
|
+
"action" => "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RefWorks%20Tagged%20Format&encoding=65001",
|
|
39
|
+
"method" => "POST",
|
|
40
|
+
"enctype" => "application/x-www-form-urlencoded"
|
|
41
|
+
])
|
|
42
|
+
@@push_formats ||= Hash[@easybib.name => @easybib, @endnote.name => @endnote, @refworks.name => @refworks]
|
|
43
|
+
end
|
|
44
|
+
end
|