ex_cite 1.0.1 → 1.1.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 +1 -1
- data/app/controllers/ex_cite/export_citations_controller.rb +18 -14
- data/app/helpers/ex_cite/application_helper.rb +1 -8
- data/app/models/ex_cite/push_format.rb +7 -5
- data/app/views/ex_cite/cite/_external_form.html.erb +3 -3
- data/config/initializers/mime_types.rb +7 -1
- data/lib/ex_cite/core_ext.rb +4 -15
- data/lib/ex_cite/engine.rb +12 -26
- data/lib/ex_cite/version.rb +1 -1
- data/test/dummy/log/development.log +405 -0
- data/test/dummy/log/test.log +86349 -0
- data/test/dummy/test/unit/ex_cite_record_test.rb +5 -3
- data/test/dummy/tmp/cache/15C/AE1/468286998ed7e41613b5b638604d0d418e16f000to_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/23D/251/794c17bcbef330a90c5063ca7b881b06685047aeto_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/24E/D11/1e1a808df870f039ac20fd161b9c4ea0a3a12101to_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/2A6/8D1/affd98a65c2fce8403f2d2776024add085305dc8to_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/2E8/121/5c66e1737c71a44c1c2c0c53aacfdbe21a47d22dto_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/2FA/431/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/336/B71/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_refworks_tagged +4 -0
- data/test/dummy/tmp/cache/36A/321/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_refworks_tagged +5 -0
- data/test/dummy/tmp/cache/3BC/4C1/794c17bcbef330a90c5063ca7b881b06685047aeto_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/403/6D1/b665552cd9b09a9c72e20a7f3ab1c8e786e23f99to_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/425/491/affd98a65c2fce8403f2d2776024add085305dc8to_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/479/4F1/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/4B5/B31/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/4E9/FE1/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_chicago_author_date +4 -0
- data/test/dummy/tmp/cache/C60/020/468286998ed7e41613b5b638604d0d418e16f000to_csl +1 -0
- data/test/dummy/tmp/cache/D31/D60/794c17bcbef330a90c5063ca7b881b06685047aeto_apa +3 -0
- data/test/dummy/tmp/cache/D39/F20/794c17bcbef330a90c5063ca7b881b06685047aeto_mla +3 -0
- data/test/dummy/tmp/cache/D41/ED0/794c17bcbef330a90c5063ca7b881b06685047aeto_csl +1 -0
- data/test/dummy/tmp/cache/D78/870/b665552cd9b09a9c72e20a7f3ab1c8e786e23f99to_apa +3 -0
- data/test/dummy/tmp/cache/D80/A30/b665552cd9b09a9c72e20a7f3ab1c8e786e23f99to_mla +3 -0
- data/test/dummy/tmp/cache/D9A/430/affd98a65c2fce8403f2d2776024add085305dc8to_apa +3 -0
- data/test/dummy/tmp/cache/DA2/5F0/affd98a65c2fce8403f2d2776024add085305dc8to_mla +3 -0
- data/test/dummy/tmp/cache/DAA/5A0/affd98a65c2fce8403f2d2776024add085305dc8to_csl +1 -0
- data/test/dummy/tmp/cache/DEC/D60/5c66e1737c71a44c1c2c0c53aacfdbe21a47d22dto_csl +1 -0
- data/test/dummy/tmp/cache/DEE/090/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_apa +3 -0
- data/test/dummy/tmp/cache/DF6/250/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_mla +3 -0
- data/test/dummy/tmp/cache/DFE/200/ca02f65b1e44e0da798cff8e53adb7a70211fe70to_csl +1 -0
- data/test/dummy/tmp/cache/E2A/AD0/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_apa +3 -0
- data/test/dummy/tmp/cache/E32/C90/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_mla +3 -0
- data/test/dummy/tmp/cache/E3A/C40/af5dc25c4cb1c5d8a1fd83234ecf9fcb76f23952to_csl +1 -0
- data/test/dummy/tmp/cache/E5E/B80/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_apa +3 -0
- data/test/dummy/tmp/cache/E66/D40/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_mla +3 -0
- data/test/dummy/tmp/cache/E6E/CF0/c9d431e57fa51ecef5d8dfed8ead3fa142c71284to_csl +1 -0
- data/test/functional/ex_cite/export_citations _controller_test.rb +36 -11
- data/test/test_helper.rb +9 -8
- metadata +74 -11
- data/config/initializers/citation.rb +0 -7
data/MIT-LICENSE
CHANGED
|
@@ -13,7 +13,7 @@ module ExCite
|
|
|
13
13
|
|
|
14
14
|
# Sends bad request if there is no destination format
|
|
15
15
|
def valid_to_format?
|
|
16
|
-
head :bad_request unless to_format
|
|
16
|
+
head :bad_request unless to_format
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Checks to see if destination format is valid and stores it in a class variable
|
|
@@ -37,6 +37,7 @@ module ExCite
|
|
|
37
37
|
(params[:id].nil?) ? [] :
|
|
38
38
|
params[:id].collect do |id|
|
|
39
39
|
record = ExCite.acts_as_citable_class.find_by_id id if ExCite.acts_as_citable_class.respond_to? :find_by_id
|
|
40
|
+
(record.nil?) ? (raise(ArgumentError, "This ID cannot be found.")) : record
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
|
|
@@ -44,9 +45,9 @@ module ExCite
|
|
|
44
45
|
def resource_citation
|
|
45
46
|
(params[:resource_key].nil?) ? [] :
|
|
46
47
|
params[:resource_key].collect do |key|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
citation = ExCite.acts_as_citable_class.new()
|
|
49
|
+
citation.resource_key = key
|
|
50
|
+
citation
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
|
|
@@ -66,9 +67,7 @@ module ExCite
|
|
|
66
67
|
# Maps the output and caches it, alternatively it fetches the already cached result. Seperates each output with two new lines.
|
|
67
68
|
# Raises an argument error if any error is caught in mapping (usually the formats are messed up)
|
|
68
69
|
def map
|
|
69
|
-
@output ||=
|
|
70
|
-
# citations.collect { |citation| Rails.cache.fetch(citation.resource_key+to_format) { citation.send(to_format) } }.join "\n\n"
|
|
71
|
-
citations.collect { |citation| citation.send(to_format) }.join "\n\n"
|
|
70
|
+
@output ||= citations.collect { |citation| Rails.cache.fetch(citation.resource_key+to_format) { citation.send(to_format) } }.join_and_enclose *delimiters
|
|
72
71
|
rescue Exception => exc
|
|
73
72
|
raise ArgumentError, "#{exc}\n Data or source format not provided and/or mismatched. [citations => #{citations}, to_format => #{@to_format}] "
|
|
74
73
|
end
|
|
@@ -93,7 +92,7 @@ module ExCite
|
|
|
93
92
|
return
|
|
94
93
|
end
|
|
95
94
|
# 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))
|
|
95
|
+
if (direction == :to && (Citero.to_formats.include?(format.downcase) || Citero.citation_styles.include?(format.downcase)))
|
|
97
96
|
return "#{:to.to_s}_#{format.downcase}"
|
|
98
97
|
# if the from format is found, it returns just that because the object already knows what method to call
|
|
99
98
|
elsif (direction == :from && Citero.from_formats.include?(format.downcase))
|
|
@@ -109,7 +108,6 @@ module ExCite
|
|
|
109
108
|
|
|
110
109
|
# For debugging purposes prints out the error. Also sends bad request header
|
|
111
110
|
def handle_invalid_arguments exc
|
|
112
|
-
p exc
|
|
113
111
|
logger.debug exc
|
|
114
112
|
head :bad_request
|
|
115
113
|
end
|
|
@@ -124,7 +122,7 @@ module ExCite
|
|
|
124
122
|
redirect_to @push_to.url+callback, :status => 303
|
|
125
123
|
elsif @push_to.action.eql? :render
|
|
126
124
|
# call the method this service needs
|
|
127
|
-
render_push
|
|
125
|
+
render_push
|
|
128
126
|
end
|
|
129
127
|
end
|
|
130
128
|
|
|
@@ -161,11 +159,17 @@ module ExCite
|
|
|
161
159
|
name
|
|
162
160
|
end
|
|
163
161
|
|
|
164
|
-
def render_push
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
def render_push
|
|
163
|
+
render :template => @push_to.template
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def delimiters
|
|
167
|
+
case @to_format
|
|
168
|
+
when "to_easybib", "to_csl"
|
|
169
|
+
return [",\n","[","]"]
|
|
170
|
+
else
|
|
171
|
+
return ["\n\n"]
|
|
167
172
|
end
|
|
168
|
-
render :template => push.template
|
|
169
173
|
end
|
|
170
174
|
end
|
|
171
175
|
end
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
module ExCite
|
|
2
2
|
module ApplicationHelper
|
|
3
3
|
def build_external_form
|
|
4
|
-
|
|
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
|
|
4
|
+
return "<textarea name=\"#{@push_to.element_name}\" id=\"#{@push_to.element_name}\">#{@output}</textarea>"
|
|
12
5
|
end
|
|
13
6
|
end
|
|
14
7
|
end
|
|
@@ -2,14 +2,16 @@ module ExCite
|
|
|
2
2
|
# Citation class, holds data from format and/or resource key
|
|
3
3
|
class PushFormat
|
|
4
4
|
# Required fields
|
|
5
|
-
attr_accessor :name, :to_format, :action, :
|
|
5
|
+
attr_accessor :name, :to_format, :action, :template, :url, :method, :enctype, :element_name
|
|
6
6
|
def initialize args = {}
|
|
7
|
-
self.name = args[:name]
|
|
7
|
+
self.name = (args[:name] or 'Service')
|
|
8
8
|
self.to_format = args[:to_format]
|
|
9
|
-
self.action = args[:action]
|
|
10
|
-
self.
|
|
11
|
-
self.template = args[:template]
|
|
9
|
+
self.action = (args[:action] or :render)
|
|
10
|
+
self.template = (args[:template] or "ex_cite/cite/external_form")
|
|
12
11
|
self.url = args[:url]
|
|
12
|
+
self.method = (args[:method] or "POST")
|
|
13
|
+
self.enctype = (args[:enctype] or "application/x-www-form-urlencoded")
|
|
14
|
+
self.element_name = (args[:element_name] or "data")
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
});
|
|
11
11
|
<% end %>
|
|
12
12
|
<div class="inner_form_dialog">
|
|
13
|
-
<form id="<%= @id %>" action="<%= @
|
|
14
|
-
<h2
|
|
13
|
+
<form id="<%= @id %>" action="<%= @push_to.url %>" method="<%= @push_to.method %>" class="external_form" enctype="<%= @push_to.enctype %>">
|
|
14
|
+
<h2>Push to <%= @push_to.name.capitalize %></h2>
|
|
15
15
|
<div class="formError">
|
|
16
16
|
<%= @error || flash[:error] %>
|
|
17
17
|
</div>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<legend><%= @legend %></legend>
|
|
20
20
|
<%= raw build_external_form %>
|
|
21
21
|
<div class="section">
|
|
22
|
-
<%= submit_tag @name%>
|
|
22
|
+
<%= submit_tag "Push to #{@push_to.name.capitalize}"%>
|
|
23
23
|
</div>
|
|
24
24
|
</fieldset>
|
|
25
25
|
</form>
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
Mime::Type.register "application/x-url", :openurl
|
|
2
2
|
Mime::Type.register "text/plain", :csf
|
|
3
|
-
Mime::Type.register "application/json", :easybib
|
|
3
|
+
Mime::Type.register "application/json", :easybib
|
|
4
|
+
Mime::Type.register "text/plain", :refworks_tagged
|
|
5
|
+
Mime::Type.register "application/json", :csl
|
|
6
|
+
|
|
7
|
+
Mime::Type.register "text/html", :apa
|
|
8
|
+
Mime::Type.register "text/html", :mla
|
|
9
|
+
Mime::Type.register "text/html", :chicago_author_date
|
data/lib/ex_cite/core_ext.rb
CHANGED
|
@@ -10,23 +10,12 @@ String.class_eval do
|
|
|
10
10
|
def to_a
|
|
11
11
|
self.split('',1)
|
|
12
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
13
|
end
|
|
27
14
|
|
|
28
15
|
Array.class_eval do
|
|
29
|
-
def
|
|
30
|
-
|
|
16
|
+
def join_and_enclose seperator, *args
|
|
17
|
+
left_end = (args[0] or "")
|
|
18
|
+
right_end = (args[1] or left_end)
|
|
19
|
+
left_end + self.join(seperator) + right_end
|
|
31
20
|
end
|
|
32
21
|
end
|
data/lib/ex_cite/engine.rb
CHANGED
|
@@ -4,6 +4,7 @@ require "acts_as_citable"
|
|
|
4
4
|
module ExCite
|
|
5
5
|
mattr_accessor :acts_as_citable_class
|
|
6
6
|
mattr_accessor :push_formats
|
|
7
|
+
mattr_accessor :endnote, :easybib, :refworks
|
|
7
8
|
def self.acts_as_citable_class
|
|
8
9
|
@@acts_as_citable_class.constantize
|
|
9
10
|
end
|
|
@@ -12,33 +13,18 @@ module ExCite
|
|
|
12
13
|
isolate_namespace ExCite
|
|
13
14
|
engine_name "ex_cite"
|
|
14
15
|
ExCite.acts_as_citable_class = "ExCite::Citation"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
config.before_initialize do
|
|
17
|
+
ExCite.easybib ||= PushFormat.new( :name => :easybibpush, :to_format => :easybib, :url => "http://www.easybib.com/cite/bulk")
|
|
18
|
+
ExCite.endnote ||= PushFormat.new :name => :endnote, :to_format => :ris, :action => :redirect, :url => 'http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl='
|
|
19
|
+
ExCite.refworks ||= PushFormat.new( :name => :refworks, :to_format => :refworks_tagged, :element_name=> 'ImportData', :url => "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RefWorks%20Tagged%20Format&encoding=65001")
|
|
20
|
+
formats = Hash[ExCite.easybib.name => ExCite.easybib, ExCite.endnote.name => ExCite.endnote, ExCite.refworks.name => ExCite.refworks]
|
|
21
|
+
ExCite.push_formats = formats
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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]
|
|
24
|
+
|
|
25
|
+
ActiveSupport.on_load(:after_initialize) do
|
|
26
|
+
ActiveRecord::Base.class_eval do
|
|
27
|
+
include ResourceKey
|
|
28
|
+
end
|
|
43
29
|
end
|
|
44
30
|
end
|
data/lib/ex_cite/version.rb
CHANGED