citero_engine 3.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +105 -0
  4. data/Rakefile +46 -0
  5. data/app/assets/javascripts/citero_engine.js +6 -0
  6. data/app/assets/javascripts/citero_engine/submit_external_form.js +12 -0
  7. data/app/controllers/citero_engine/citero_engine_controller.rb +190 -0
  8. data/app/helpers/citero_engine/application_helper.rb +7 -0
  9. data/app/models/citero_engine/citation.rb +17 -0
  10. data/app/models/citero_engine/push_format.rb +19 -0
  11. data/app/models/citero_engine/resource_key.rb +13 -0
  12. data/app/views/citero_engine/cite/_external_form.html.erb +16 -0
  13. data/app/views/citero_engine/cite/external_form.html.erb +1 -0
  14. data/config/initializers/mime_types.rb +4 -0
  15. data/config/routes.rb +3 -0
  16. data/lib/citero_engine.rb +3 -0
  17. data/lib/citero_engine/core_ext.rb +21 -0
  18. data/lib/citero_engine/engine.rb +42 -0
  19. data/lib/citero_engine/version.rb +3 -0
  20. data/lib/tasks/citero_engine_tasks.rake +4 -0
  21. data/test/dummy/README.rdoc +28 -0
  22. data/test/dummy/Rakefile +6 -0
  23. data/test/dummy/app/assets/javascripts/application.js +13 -0
  24. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  25. data/test/dummy/app/controllers/application_controller.rb +5 -0
  26. data/test/dummy/app/helpers/application_helper.rb +2 -0
  27. data/test/dummy/app/models/type_one.rb +6 -0
  28. data/test/dummy/app/models/type_two.rb +5 -0
  29. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/test/dummy/bin/bundle +3 -0
  31. data/test/dummy/bin/rails +4 -0
  32. data/test/dummy/bin/rake +4 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/config/application.rb +22 -0
  35. data/test/dummy/config/boot.rb +5 -0
  36. data/test/dummy/config/database.yml +25 -0
  37. data/test/dummy/config/environment.rb +5 -0
  38. data/test/dummy/config/environments/development.rb +37 -0
  39. data/test/dummy/config/environments/production.rb +78 -0
  40. data/test/dummy/config/environments/test.rb +39 -0
  41. data/test/dummy/config/initializers/assets.rb +8 -0
  42. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  44. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  45. data/test/dummy/config/initializers/inflections.rb +16 -0
  46. data/test/dummy/config/initializers/mime_types.rb +4 -0
  47. data/test/dummy/config/initializers/session_store.rb +3 -0
  48. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  49. data/test/dummy/config/locales/en.yml +23 -0
  50. data/test/dummy/config/routes.rb +4 -0
  51. data/test/dummy/config/secrets.yml +22 -0
  52. data/test/dummy/db/migrate/20130211192047_create_type_ones.rb +11 -0
  53. data/test/dummy/db/migrate/20130211192122_create_type_twos.rb +11 -0
  54. data/test/dummy/db/schema.rb +32 -0
  55. data/test/dummy/public/404.html +67 -0
  56. data/test/dummy/public/422.html +67 -0
  57. data/test/dummy/public/500.html +66 -0
  58. data/test/dummy/public/favicon.ico +0 -0
  59. data/test/dummy/test/fixtures/type_ones.yml +36 -0
  60. data/test/dummy/test/fixtures/type_twos.yml +11 -0
  61. data/test/dummy/test/unit/citero_engine_record_test.rb +9 -0
  62. data/test/dummy/test/unit/record_test.rb +7 -0
  63. data/test/dummy/test/unit/type_one_test.rb +24 -0
  64. data/test/dummy/test/unit/type_two_test.rb +16 -0
  65. data/test/fixtures/ex_cite/citations.yml +11 -0
  66. data/test/functional/citero_engine/export_citations_controller_test.rb +160 -0
  67. data/test/integration/navigation_test.rb +10 -0
  68. data/test/test_helper.rb +36 -0
  69. data/test/unit/citero_engine/citation_test.rb +4 -0
  70. data/test/unit/helpers/citero_engine/cite_helper_test.rb +6 -0
  71. metadata +345 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffa88a8a357723e174633e79ff08dd9f9ea746d9
4
+ data.tar.gz: ff31e9b0c4d87298f5f6955244a30b66ce7df705
5
+ SHA512:
6
+ metadata.gz: 479e5cacf4d085166b8a20be9fb5e5f5eb262ed7040a083e0ba747ec13ee70eb48a925ccd86c6517eec9f69598d540229ce965ac6371967a5557e9f3645e3d3f
7
+ data.tar.gz: 6449dbcb3be1a90abd2f43eaa0fa9a8cdecde5685330665ec9fdb327e908fec5541e4b6d700a70068c2542693e9eff93037fb71168708685057e7c3b1f4d9990
@@ -0,0 +1,20 @@
1
+ Copyright 2013 NYU Division of Libraries
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.
@@ -0,0 +1,105 @@
1
+ CiteroEngine Engine Gem
2
+ ======================
3
+ [![Build Status](http://jenkins.library.nyu.edu/buildStatus/icon?job=citero_engine Staging Test)](http://jenkins.library.nyu.edu/view/Citero/job/citero_engine%20Staging%20Test/)
4
+ [![Build Status](https://travis-ci.org/NYULibraries/citero_engine.png?branch=master)](https://travis-ci.org/NYULibraries/citero_engine)
5
+ [![CircleCI](https://circleci.com/gh/NYULibraries/citero_engine.svg?style=svg)](https://circleci.com/gh/NYULibraries/citero_engine)
6
+ [![Coverage Status](https://coveralls.io/repos/NYULibraries/citero_engine/badge.png?branch=master)](https://coveralls.io/r/NYULibraries/citero_engine?branch=master)
7
+ [![Dependency Status](https://gemnasium.com/NYULibraries/citero_engine.png)](https://gemnasium.com/NYULibraries/citero_engine)
8
+ [![Gem Version](https://badge.fury.io/rb/citero_engine.png)](http://badge.fury.io/rb/citero_engine)
9
+ [![Code Climate](https://codeclimate.com/github/NYULibraries/citero_engine.png)](https://codeclimate.com/github/NYULibraries/citero_engine)
10
+
11
+ A JRuby wrapper for the citero tool, enables use of the citero tool in JRuby distributed as a Rails 3 Engine Gem.
12
+
13
+ Install
14
+ ==========
15
+
16
+ Mount the engine gem to your rails project like so:
17
+
18
+ ```ruby
19
+ mount CiteroEngine::Engine, :at => '/MOUNT_LOCATION'
20
+ ```
21
+
22
+ You'll need to require the [jquery-rails](https://github.com/rails/jquery-rails) gem also.
23
+
24
+ In your Gemfile
25
+
26
+ ```ruby
27
+ gem "jquery-rails"
28
+ ```
29
+
30
+ Formats supported
31
+ ========
32
+ Currently supporting PNX, RIS, CSF, BiBTeX, OpenURL, XERXES_XML, and EasyBib JSON.
33
+
34
+ Currently supports the following services RefWorks, EasyBib, EndNote.
35
+
36
+
37
+ How to use
38
+ ========
39
+
40
+ There are two methods to use this engine. To use the ActiveRecord method, first you must have a record that implements acts\_as\_citable.
41
+
42
+ Otherwise, you can POST or GET to /MOUNT\_LOCATION/export_citations(/:to_format)(/:id) with the parameters data[] and from\_format[] defined.
43
+ The data[] array and the from\_format[] array must correspond to each other, that is, each element, e, in data[] is of from\_format format[e].
44
+
45
+ Finally, you can send an OpenURL request, simply define the :to_format and pass in the query string.
46
+
47
+ Services
48
+ ========
49
+
50
+ Some services, such as Endnote, RefWorks, and EasyBib are already included in citero_engine. These services are configurable right out of the box for your needs.
51
+
52
+ There are two ways to use services, rendering and redirect. The render method will render a view with a 200 response, and the redirect will, as expected,
53
+ redirect to another page with a 302 response.
54
+
55
+ To configure a built-in service, such as Endnote, Refworks, or EasyBib, simply modify the following objects
56
+
57
+ ```ruby
58
+ CiteroEngine.easybib
59
+ CiteroEngine.refworks
60
+ CiteroEngine.endnote
61
+ ```
62
+
63
+ The available options are as follow, with available defaults shown
64
+
65
+ ```ruby
66
+ :name => 'Service' # What you want to call this service, and how it will be accessed, i.e. 'easybibpush'
67
+ :to_format => # The format that the service is expecting
68
+ :action => 'render' # Either :redirect or :render is supported
69
+ :template => 'citero_engine/cite/external_form' # The template view to render. You are free to use your own, citero_engine provides one for free!
70
+ :url => # The url to redirect to or the url to send the form to
71
+ :method => 'POST' # This is the form action
72
+ :enctype => 'application/x-www-form-urlencoded' # This is the enctype for the form
73
+ :element_name => 'data' # The default view constructs a form that automatically posts, this is the name of the textbox.
74
+ :callback_protocol => :http # The protocol the callback url is to use for this application. Defaults to :http, supports :https
75
+
76
+ alias :protocol :callback_protocol # An alias, should you wish to use this outdated version.
77
+ ```
78
+ To add a new service, simply
79
+
80
+ ```ruby
81
+ easybib = PushFormat.new( :name => :easybibpush, :to_format => :easybib, :action => :render, :template => "citero_engine/cite/external_form", :url => "http://www.easybib.com/cite/bulk")
82
+ CiteroEngine.push_formats['easybib'] = easybib
83
+ ```
84
+ Examples
85
+ ========
86
+
87
+ Mounted at root (/)
88
+
89
+ GET, POST (ActiveRecord, will download RIS)
90
+ http://localhost:3000/export_citations?to_format=ris&id[]=1
91
+ http://localhost:3000/export_citations/ris/1
92
+
93
+ GET, POST (ActiveRecord, will push to refworks)
94
+ http://localhost:3000/export_citations?to_format=refworks&id[]=1
95
+ http://localhost:3000/export_citations/refworks/1
96
+
97
+ GET, POST (Non ActiveRecord, will download RIS)
98
+ http://localhost:3000/export_citations?to_format=ris&from_format[]=csf&from_format[]=csf&data[]=itemType%3A%20book&data[]=itemType%3A%20journalArticle
99
+ GET, POST (Non ActiveRecord, will push to refworks)
100
+ http://localhost:3000/export_citations?to_format=refworks&from_format[]=csf&from_format[]=csf&data[]=itemType%3A%20book&data[]=itemType%3A%20journalArticle
101
+
102
+ OpenURL (Non ActiveRecord, will download RIS)
103
+ http://localhost:3000/export_citations?to_format=ris&url_ver=Z39.88-2004&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx&ctx_ver=Z39.88-2004&ctx_tim=2012-11-20T13%3A40%3A11-05%3A00&ctx_id=&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rft.genre=journal&rft.issn=0893-3456&rft.jtitle=Los+Alamos+monitor&rft.language=eng&rft.object_id=991042747005504&rft.object_type=JOURNAL&rft.page=1&rft.place=Los+Alamos%2C+N.M.&rft.pub=%5BH.+Markley+McMahon%5D&rft.stitle=ALAMOS+MONITOR+%28LOS+ALAMOS%2C+NM%29&rft.title=Los+Alamos+monitor&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft_id=L&req.ip=127.0.0.1
104
+ OpenURL (Non AciveRecord, will push to refworks)
105
+ http://localhost:3000/export_citations?to_format=refworks&url_ver=Z39.88-2004&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx&ctx_ver=Z39.88-2004&ctx_tim=2012-11-20T13%3A40%3A11-05%3A00&ctx_id=&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&rft.genre=journal&rft.issn=0893-3456&rft.jtitle=Los+Alamos+monitor&rft.language=eng&rft.object_id=991042747005504&rft.object_type=JOURNAL&rft.page=1&rft.place=Los+Alamos%2C+N.M.&rft.pub=%5BH.+Markley+McMahon%5D&rft.stitle=ALAMOS+MONITOR+%28LOS+ALAMOS%2C+NM%29&rft.title=Los+Alamos+monitor&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft_id=L&req.ip=127.0.0.1
@@ -0,0 +1,46 @@
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 = 'CiteroEngine'
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
+ require 'rspec/core/rake_task'
43
+ RSpec::Core::RakeTask.new(:spec) do |t|
44
+ t.ruby_opts = "--debug --dev"
45
+ end
46
+ task default: :spec
@@ -0,0 +1,6 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // This engine requires jquery.
5
+ //= require jquery
6
+ //= require_tree './citero_engine'
@@ -0,0 +1,12 @@
1
+ // A simple function to allow us to automatically submit forms for
2
+ // pushing to other services such as EasyBib and RefWorks.
3
+ jQuery(document).ready(function($) {
4
+ submit_external_form();
5
+ // Automatically submit the form.
6
+ function submit_external_form() {
7
+ // Hide the page
8
+ $("body").hide();
9
+ $form = $(".external_form");
10
+ $form.trigger("submit");
11
+ }
12
+ });
@@ -0,0 +1,190 @@
1
+ require "citero_engine/engine"
2
+ require 'digest/sha1'
3
+ require 'open-uri'
4
+ module CiteroEngine
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 CiteroEngineController < 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 "citero_engine/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 = CiteroEngine.acts_as_citable_class.find_by_id id if CiteroEngine.acts_as_citable_class.respond_to? :find_by_id
40
+ (record.nil?) ? (raise(ArgumentError, "This ID cannot be found.")) : record
41
+ end
42
+ end
43
+
44
+ # Constructs new citation objects with only the citation key set, returns an array
45
+ def resource_citation
46
+ resources = []
47
+ return resources if params[:resource_key].nil?
48
+ resources << Rails.cache.fetch(params[:resource_key])
49
+ resources.flatten!
50
+ resources.collect do |key|
51
+ citation = CiteroEngine.acts_as_citable_class.new()
52
+ citation.resource_key = key
53
+ citation
54
+ end
55
+ end
56
+
57
+ # Constructs new citation objects with data and source format set (the citation key is constructed automatically), returns an array
58
+ def format_citation
59
+ (params[:from_format].nil? || params[:data].nil?) ? [] :
60
+ params[:from_format].collect.with_index do |format, index|
61
+ CiteroEngine.acts_as_citable_class.new CiteroEngine.acts_as_citable_class.data_field.to_sym => params[:data].to_a[index], CiteroEngine.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, format)
62
+ end
63
+ end
64
+
65
+ # Returns a single citation object with data and format set as the url and openurl respectively
66
+ def open_url_citation
67
+ CiteroEngine.acts_as_citable_class.new CiteroEngine.acts_as_citable_class.data_field.to_sym => CGI::unescape(request.protocol+request.host_with_port+request.fullpath), CiteroEngine.acts_as_citable_class.format_field.to_sym => (whitelist_formats :from, 'openurl')
68
+ end
69
+
70
+ # Maps the output and caches it, alternatively it fetches the already cached result. Seperates each output with two new lines.
71
+ # Raises an argument error if any error is caught in mapping (usually the formats are messed up)
72
+ def map
73
+ @output ||= citations.collect { |citation| Rails.cache.fetch(citation.resource_key+to_format) { citation.send(to_format) } }.join_and_enclose *delimiters
74
+ rescue Exception => exc
75
+ raise ArgumentError, "#{exc}\n Data or source format not provided and/or mismatched. [citations => #{citations}, to_format => #{@to_format}] "
76
+ end
77
+
78
+ # Maps then decides wether its a push request or a download, catches all bad argument errors
79
+ def index
80
+ map
81
+ serve
82
+ rescue ArgumentError => exc
83
+ handle_invalid_arguments exc
84
+ end
85
+
86
+ # Pushes to a web service if that is what was requested else it downloads
87
+ def serve
88
+ @push_to ? push : download
89
+ end
90
+
91
+ # Cleans the user input and finds the associated method for that format
92
+ def whitelist_formats direction, format
93
+ # if the params are nil then it returns nil
94
+ if direction.nil? || format.nil?
95
+ return
96
+ end
97
+ # if the to format is found, it returns the method name for that to format
98
+ format_sym = format.downcase.to_sym
99
+ if (direction == :to && (Citero.to_formats.include?(format_sym) || Citero.citation_styles.include?(format_sym)))
100
+ return "to_#{format_sym}"
101
+ # if the from format is found, it returns just that because the object already knows what method to call
102
+ elsif (direction == :from && Citero.from_formats.include?(format_sym))
103
+ return format.downcase
104
+ end
105
+ # if the format is still not found, it might be a push request, check if that is the case
106
+ if CiteroEngine.push_formats.include? format_sym
107
+ @push_to = CiteroEngine.push_formats[format_sym]
108
+ @to_format = @push_to.to_format.downcase
109
+ return "#{direction.to_s}_#{@to_format}"
110
+ end
111
+ end
112
+
113
+ # For debugging purposes prints out the error. Also sends bad request header
114
+ def handle_invalid_arguments exc
115
+ logger.debug exc
116
+ head :bad_request
117
+ end
118
+
119
+ # Redirects or calls a predefined method depending on the webservice selected
120
+ def push
121
+ # for redirects
122
+ if @push_to.action.eql? :redirect
123
+ # Openurl is data
124
+ @data = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
125
+ # and redirect to the url supplied by the webservice and the callback url
126
+ redirect_to @push_to.url+callback, :status => 303
127
+ elsif @push_to.action.eql? :render
128
+ # call the method this service needs
129
+ render_push
130
+ end
131
+ end
132
+
133
+ # sends the data with utf-8 encoding
134
+ def download
135
+ send_data @output.force_encoding('UTF-8'), :filename => filename, :type => @to_format.formatize.to_sym
136
+ end
137
+
138
+ # The callback url is defined here
139
+ def callback
140
+ # Starts with current url minus the querystring..
141
+ callback = "#{export_citations_url.gsub(/https?/, @push_to.callback_protocol.to_s)}?"
142
+ resource_keys = []
143
+ citations.each do |citation|
144
+ if !citation.respond_to? :new_record || citation.new_record?
145
+ resource_keys << citation.resource_key
146
+ end
147
+ end
148
+ unless resource_keys.empty?
149
+ resource_key = Digest::SHA1.hexdigest(resource_keys.sort.join)
150
+ Rails.cache.write(resource_key,resource_keys)
151
+ callback += "resource_key=#{resource_key}&"
152
+ end
153
+ citations.each do |citation|
154
+ # then adds a resource key for each cached resource
155
+ callback += (!citation.respond_to? :new_record || citation.new_record?) ? "" : "id[]=#{citation.id}&"
156
+ end
157
+ # and finally the to format
158
+ callback += "to_format=#{@to_format.formatize}"
159
+ # url encode and return
160
+ ERB::Util.url_encode(callback)
161
+ end
162
+
163
+ # Creates the filename and extension. Few are application specific
164
+ def filename
165
+ name = "export"
166
+ case @to_format
167
+ when "to_bibtex"
168
+ name += ".bib"
169
+ when "to_easybib"
170
+ name += ".json"
171
+ else
172
+ name += "." + @to_format.formatize
173
+ end
174
+ name
175
+ end
176
+
177
+ def render_push
178
+ render :layout => false, :template => @push_to.template
179
+ end
180
+
181
+ def delimiters
182
+ case @to_format
183
+ when "to_easybib"
184
+ return [",\n","[","]"]
185
+ else
186
+ return ["\n\n"]
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,7 @@
1
+ module CiteroEngine
2
+ module ApplicationHelper
3
+ def build_external_form
4
+ return "<textarea name=\"#{@push_to.element_name}\" id=\"#{@push_to.element_name}\">#{@output}</textarea>"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module CiteroEngine
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,19 @@
1
+ module CiteroEngine
2
+ # Citation class, holds data from format and/or resource key
3
+ class PushFormat
4
+ # Required fields
5
+ attr_accessor :name, :to_format, :action, :template, :url, :method, :enctype, :element_name, :callback_protocol
6
+ alias :protocol= :callback_protocol=
7
+ def initialize args = {}
8
+ self.name = (args[:name] or 'Service')
9
+ self.to_format = args[:to_format]
10
+ self.action = (args[:action] or :render)
11
+ self.template = (args[:template] or "citero_engine/cite/external_form")
12
+ self.url = args[:url]
13
+ self.method = (args[:method] or "POST")
14
+ self.enctype = (args[:enctype] or "application/x-www-form-urlencoded")
15
+ self.element_name = (args[:element_name] or "data")
16
+ self.callback_protocol = (args[:protocol] or :http)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module CiteroEngine
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