umlaut_journal_tocs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +37 -0
- data/app/item_decorators/umlaut_journal_tocs_decorator.rb +50 -0
- data/app/service_adaptors/journal_tocs_adapter.rb +51 -0
- data/app/views/umlaut_journal_tocs/_bento_item.html.erb +80 -0
- data/app/views/umlaut_journal_tocs/_resolve_section.html.erb +10 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +2 -0
- data/lib/tasks/umlaut_journal_tocs_tasks.rake +4 -0
- data/lib/umlaut_journal_tocs.rb +26 -0
- data/lib/umlaut_journal_tocs/engine.rb +18 -0
- data/lib/umlaut_journal_tocs/version.rb +3 -0
- data/test/controller_test.rb +36 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +17 -0
- data/test/dummy/app/assets/stylesheets/application.css +19 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/umlaut_controller.rb +136 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +60 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +45 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/umlaut_journal_tocs.rb +20 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +57 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/umlaut_services.yml +23 -0
- data/test/dummy/db/migrate/20150901192508_umlaut_init.umlaut.rb +106 -0
- data/test/dummy/db/migrate/20150901192509_umlaut_add_service_response_index.umlaut.rb +10 -0
- data/test/dummy/db/schema.rb +118 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/journal_tocs_adapter_test.rb +93 -0
- data/test/support/vcr_filter.rb +45 -0
- data/test/test_helper.rb +39 -0
- data/test/vcr_cassettes/generates_no_response.yml +49 -0
- data/test/vcr_cassettes/generates_response.yml +952 -0
- data/test/vcr_cassettes/gets_results.yml +804 -0
- data/test/vcr_cassettes/registers_proper_error.yml +40 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e60c1c166dfa1839819bbe4b9da4050c18fbd6d
|
4
|
+
data.tar.gz: e5928afdb0faed5785440e715bacc407ad37780b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0eb7c9153fafeaea474a11966c533c7e5d9317a5e56ce47167db53caba84dff66b7c6285e748d771cbb536f447e22714103de2f0860e1728296e467658e038dd
|
7
|
+
data.tar.gz: 4a5301df4714bc73cb31692a6ac17580a7afeea05c5a1e76f8b8ad856b8c6498ca1f59aad709846088c5d37f247599fe39d0d47fa91d939bacf1ef2884a99b63
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Jonathan Rochkind
|
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/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'UmlautJournalTocs'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# A bento_search item decorator customizing display for use in umlaut
|
2
|
+
# recent articles.
|
3
|
+
|
4
|
+
class UmlautJournalTocsDecorator < BentoSearch::StandardDecorator
|
5
|
+
|
6
|
+
# Always full publication date
|
7
|
+
def display_date
|
8
|
+
if self.publication_date
|
9
|
+
I18n.localize(self.publication_date, :format => "%d %b %Y")
|
10
|
+
elsif self.year
|
11
|
+
self.year.to_s
|
12
|
+
else
|
13
|
+
nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Replace link with openurl pointing to ourselves with direct-to-fulltext,
|
18
|
+
# or else nothing.
|
19
|
+
def link
|
20
|
+
if good_openurl?
|
21
|
+
self_openurl("umlaut.skip_resolve_menu_for_type" => "fulltext")
|
22
|
+
else
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
#def other_links
|
28
|
+
# links = []
|
29
|
+
#
|
30
|
+
# if good_openurl?
|
31
|
+
# links << BentoSearch::Link.new(:label => _h.umlaut_config.app_name, :url => self_openurl)
|
32
|
+
# end
|
33
|
+
#end
|
34
|
+
|
35
|
+
# helper method for ourselves, do we have enough
|
36
|
+
# metadata for a good article openurl?
|
37
|
+
def good_openurl?
|
38
|
+
self.doi.present? || self.pmid.present? ||
|
39
|
+
(self.volume.present? && self.issue.present? && self.start_page.present?)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self_openurl(extra_params = {})
|
43
|
+
_h.url_for_with_co(
|
44
|
+
{ :controller => "/resolve",
|
45
|
+
:action => :index
|
46
|
+
}.merge(extra_params),
|
47
|
+
self.to_openurl)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'bento_search'
|
2
|
+
|
3
|
+
class JournalTocsAdapter < Service
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@bento_search_engine = 'umlaut_journal_tocs'
|
7
|
+
@max_items = 40
|
8
|
+
super(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def service_types_generated
|
13
|
+
return [ServiceTypeValue[:journal_tocs_bento]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def handle(request)
|
17
|
+
unless self.class.suitable_citation?(request)
|
18
|
+
return request.dispatched(self, true)
|
19
|
+
end
|
20
|
+
|
21
|
+
searcher = BentoSearch.get_engine(@bento_search_engine)
|
22
|
+
|
23
|
+
bento_results = searcher.fetch_by_issn(request.referent.issn)
|
24
|
+
|
25
|
+
bento_results.slice!(@max_items, bento_results.length)
|
26
|
+
|
27
|
+
# We store JSON serialization of results in the display_text field
|
28
|
+
# of a single ServiceResponse, hacky but okay.
|
29
|
+
if bento_results.length > 0
|
30
|
+
request.add_service_response(
|
31
|
+
:service=>self,
|
32
|
+
:service_data => bento_results.dump_to_json,
|
33
|
+
:service_type_value => :journal_tocs_bento
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
return request.dispatched(self, true)
|
38
|
+
rescue BentoSearch::FetchError => e
|
39
|
+
Rails.logger.error("JournalTocsAdapter: Could not fetch results: #{e}")
|
40
|
+
return request.dispatched(self, false, e)
|
41
|
+
end
|
42
|
+
|
43
|
+
# A class-method because we use it standalone in our resolve
|
44
|
+
# section visbility logic.
|
45
|
+
def self.suitable_citation?(request)
|
46
|
+
# We do nothing for article-level, only journal-level
|
47
|
+
# We can do nothing without ISSN.
|
48
|
+
request.title_level_citation? && request.referent.issn.present?
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
<%#
|
2
|
+
# Custom template to display a BentoSearch::Result for the umlaut
|
3
|
+
# journal tocs recent article display.
|
4
|
+
#
|
5
|
+
# Forked from bento_search/_std_item.html.erb, but with customizations
|
6
|
+
# for what we want to display, in what DOM structure.
|
7
|
+
#
|
8
|
+
# must pass in local:
|
9
|
+
# * 'item' that's a BentoSearch::ResultItem
|
10
|
+
%>
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
<% bento_decorate(item) do |item| %>
|
15
|
+
|
16
|
+
<%# for debugging purposes, we'll include the vendor-specific unique_id, if we have
|
17
|
+
one, in a data-unique-id attribute. %>
|
18
|
+
|
19
|
+
<div class="bento_item" data-unique-id="<%= item.unique_id %>">
|
20
|
+
<b><%= link_to_unless(item.link.blank?, item.complete_title, item.link, :target => "_blank", :class => "response_link") %></b>
|
21
|
+
|
22
|
+
|
23
|
+
<div class="bento_item_body umlaut-content-indent">
|
24
|
+
|
25
|
+
<% if item.authors.present? %>
|
26
|
+
<p class="bento_item_row first_about">
|
27
|
+
<% if item.authors.present? %>
|
28
|
+
<span class="authors">
|
29
|
+
<%= item.render_authors_list %>
|
30
|
+
</span>
|
31
|
+
<% end %>
|
32
|
+
</p>
|
33
|
+
<% end %>
|
34
|
+
|
35
|
+
<% if item.abstract %>
|
36
|
+
<p class="bento_item_row abstract">
|
37
|
+
<%= item.render_summary %>
|
38
|
+
</p>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<% if item.volume.present? || item.issue.present? || item.display_date.present? || item.doi.present? %>
|
42
|
+
<p class="bento_item_row second_about">
|
43
|
+
|
44
|
+
<% if item.display_date.present? %>
|
45
|
+
<span class="date">
|
46
|
+
<%= item.display_date %>
|
47
|
+
</span>
|
48
|
+
<% end %>
|
49
|
+
|
50
|
+
<% if item.display_date.present? && (item.volume.present? || item.issue.present? || item.start_page.present? || item.doi.present?) %>
|
51
|
+
<span class="separator">—</span>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<%= item.render_citation_details %>
|
55
|
+
|
56
|
+
<% if item.doi.present? && (item.volume.present? || item.issue.present? || item.start_page.present?) && item.display_date.present? %>
|
57
|
+
<span class="separator">—</span>
|
58
|
+
<% end %>
|
59
|
+
|
60
|
+
|
61
|
+
<% if item.doi.present? %>
|
62
|
+
<span class="doi">
|
63
|
+
doi:<%= item.doi %>
|
64
|
+
</p>
|
65
|
+
<% end %>
|
66
|
+
|
67
|
+
|
68
|
+
</p>
|
69
|
+
<% end %>
|
70
|
+
|
71
|
+
|
72
|
+
<% if item.other_links.present? %>
|
73
|
+
<p class="bento_item_other_links">
|
74
|
+
<%= render :partial => "bento_search/link", :collection => item.other_links %>
|
75
|
+
</p>
|
76
|
+
<% end %>
|
77
|
+
</div>
|
78
|
+
|
79
|
+
</div>
|
80
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% responses.each do |response|
|
2
|
+
results = BentoSearch::Results.load_json(response.service_data) %>
|
3
|
+
|
4
|
+
<%= list_with_limit("umlaut_journal_tocs_list", results, :limit => 6, :ul_class => "response_list") do |item| %>
|
5
|
+
<li class="response_item">
|
6
|
+
<%= render :partial => results.display_configuration.try(:item_partial) || "umlaut_journal_tocs/bento_item", :locals => {:item => item} %>
|
7
|
+
</li>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "umlaut_journal_tocs/engine"
|
2
|
+
|
3
|
+
module UmlautJournalTocs
|
4
|
+
|
5
|
+
# Custom visibility logic for our resolve section,
|
6
|
+
# we don't want to show at all if it's not a suitable citation,
|
7
|
+
# otherwise :in_progress logic.
|
8
|
+
SectionVisibilityLogic = lambda do |section_renderer|
|
9
|
+
return false unless JournalTocsAdapter.suitable_citation?(section_renderer.request)
|
10
|
+
|
11
|
+
# :in_progress logic
|
12
|
+
return (! section_renderer.responses_empty?) || section_renderer.services_in_progress?
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def self.resolve_section_definition
|
17
|
+
{
|
18
|
+
:div_id => "journal_tocs_bento",
|
19
|
+
:html_area => :main,
|
20
|
+
:partial => "umlaut_journal_tocs/resolve_section",
|
21
|
+
:service_type_values => [:journal_tocs_bento],
|
22
|
+
:visibility => SectionVisibilityLogic
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'umlaut'
|
2
|
+
require 'bento_search'
|
3
|
+
|
4
|
+
module UmlautJournalTocs
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
engine_name "umlaut_journal_tocs"
|
7
|
+
|
8
|
+
initializer "umlaut_journal_tocs.add_service_types" do |app|
|
9
|
+
require 'service_type_value'
|
10
|
+
ServiceTypeValue.merge_hash!( {"journal_tocs_bento" => {}} )
|
11
|
+
end
|
12
|
+
|
13
|
+
initializer "umlaut_journal_tocs.backtrace_cleaner", :before => "umlaut.backtrace_cleaner" do
|
14
|
+
Umlaut::Engine.config.whitelisted_backtrace[self.root] = self.engine_name
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ControllerTest < ActionController::TestCase
|
4
|
+
self.use_transactional_fixtures = false
|
5
|
+
extend TestWithCassette
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@controller = ResolveController.new
|
9
|
+
end
|
10
|
+
|
11
|
+
test_with_cassette("gets results") do
|
12
|
+
get :index, {"issn" => "17588936"}
|
13
|
+
|
14
|
+
assert_response :success
|
15
|
+
|
16
|
+
# Has at least one response item in the classes we expect
|
17
|
+
sample_item = assert_select(".umlaut-section.journal_tocs_bento .response_list .response_item .bento_item")
|
18
|
+
|
19
|
+
assert_select(sample_item, "a.response_link")
|
20
|
+
assert_select(sample_item, ".abstract")
|
21
|
+
|
22
|
+
# Has a list_with_limit
|
23
|
+
assert_select(".journal_tocs_bento .collapsible")
|
24
|
+
end
|
25
|
+
|
26
|
+
test_with_cassette("not for article-level") do
|
27
|
+
get :index, { jtitle: 'JAMA', genre: 'article', issn: '1538-3598', volume: '1', issue: '1', spage:'1'}
|
28
|
+
|
29
|
+
# No response content
|
30
|
+
assert_select(".umlaut-section.journal_tocs_bento .response_list .response_item .bento_item", false)
|
31
|
+
|
32
|
+
# No section on page at all.
|
33
|
+
assert_select(".umlaut-section.journal_tocs_bento", false)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
// Umlaut javascript required for proper functionality. The 'umlaut' file
|
3
|
+
// also forces require of jquery and jquery-ui, dependencies.
|
4
|
+
//= require 'umlaut'
|
5
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
6
|
+
// listed below.
|
7
|
+
//
|
8
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
9
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
10
|
+
//
|
11
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
12
|
+
// compiled file.
|
13
|
+
//
|
14
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
15
|
+
// about supported directives.
|
16
|
+
//
|
17
|
+
//= require_tree .
|
@@ -0,0 +1,19 @@
|
|
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*
|
16
|
+
* The base Umlaut styles:
|
17
|
+
*= require 'umlaut'
|
18
|
+
*
|
19
|
+
*/
|