blacklight 4.9.0 → 5.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +22 -12
  4. data/Gemfile +3 -40
  5. data/LICENSE +1 -2
  6. data/README.md +1 -2
  7. data/Rakefile +0 -4
  8. data/VERSION +1 -1
  9. data/app/assets/images/blacklight/logo.png +0 -0
  10. data/app/assets/javascripts/blacklight/ajax_modal.js +190 -0
  11. data/app/assets/javascripts/blacklight/blacklight.js +7 -17
  12. data/app/assets/javascripts/blacklight/checkbox_submit.js +1 -1
  13. data/app/assets/stylesheets/blacklight/{_blacklight_base.scss → _blacklight_base.css.scss} +0 -21
  14. data/app/assets/stylesheets/blacklight/_bookmark.css.scss +4 -0
  15. data/app/assets/stylesheets/blacklight/_catalog.css.scss +192 -0
  16. data/app/assets/stylesheets/blacklight/_facets.css.scss +141 -0
  17. data/app/assets/stylesheets/blacklight/{_group.scss → _group.css.scss} +1 -1
  18. data/app/assets/stylesheets/blacklight/_header.css.scss +44 -0
  19. data/app/assets/stylesheets/blacklight/_layout.css.scss +5 -0
  20. data/app/assets/stylesheets/blacklight/{_modal.scss → _modal.css.scss} +7 -7
  21. data/app/assets/stylesheets/blacklight/_search_history.css.scss +20 -0
  22. data/app/assets/stylesheets/blacklight/{blacklight.scss → blacklight.css.scss} +0 -0
  23. data/app/assets/stylesheets/blacklight/blacklight_defaults.css.scss +14 -0
  24. data/app/controllers/bookmarks_controller.rb +0 -4
  25. data/app/controllers/feedback_controller.rb +0 -4
  26. data/app/helpers/blacklight/blacklight_helper_behavior.rb +45 -155
  27. data/app/helpers/blacklight/catalog_helper_behavior.rb +8 -41
  28. data/app/helpers/blacklight/facets_helper_behavior.rb +20 -43
  29. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +2 -9
  30. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +9 -14
  31. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +6 -6
  32. data/app/views/_flash_msg.html.erb +9 -2
  33. data/app/views/_user_util_links.html.erb +29 -15
  34. data/app/views/bookmarks/_tools.html.erb +4 -7
  35. data/app/views/bookmarks/index.html.erb +3 -2
  36. data/app/views/catalog/_citation.html.erb +1 -1
  37. data/app/views/catalog/_constraints.html.erb +1 -1
  38. data/app/views/catalog/_constraints_element.html.erb +12 -8
  39. data/app/views/catalog/_did_you_mean.html.erb +2 -2
  40. data/app/views/catalog/_document_header.html.erb +3 -3
  41. data/app/views/catalog/_email_form.html.erb +10 -10
  42. data/app/views/catalog/_facet_layout.html.erb +11 -3
  43. data/app/views/catalog/_facet_limit.html.erb +7 -7
  44. data/app/views/catalog/_facet_pagination.html.erb +8 -7
  45. data/app/views/catalog/_facet_pivot.html.erb +3 -1
  46. data/app/views/catalog/_facets.html.erb +12 -9
  47. data/app/views/catalog/_paginate_compact.html.erb +1 -7
  48. data/app/views/catalog/_per_page_widget.html.erb +5 -8
  49. data/app/views/catalog/_previous_next_doc.html.erb +11 -9
  50. data/app/views/catalog/_refworks_form.html.erb +3 -4
  51. data/app/views/catalog/_results_pagination.html.erb +1 -1
  52. data/app/views/catalog/_search_form.html.erb +16 -14
  53. data/app/views/catalog/_show_sidebar.html.erb +7 -9
  54. data/app/views/catalog/_show_tools.html.erb +13 -7
  55. data/app/views/catalog/_sms_form.html.erb +8 -8
  56. data/app/views/catalog/_sort_and_per_page.html.erb +4 -6
  57. data/app/views/catalog/_sort_widget.html.erb +5 -6
  58. data/app/views/catalog/email.html.erb +1 -1
  59. data/app/views/catalog/facet.html.erb +2 -8
  60. data/app/views/catalog/index.html.erb +11 -6
  61. data/app/views/catalog/show.html.erb +5 -5
  62. data/app/views/catalog/sms.html.erb +1 -1
  63. data/app/views/catalog/sms_sent.html.erb +1 -1
  64. data/app/views/feedback/complete.html.erb +2 -2
  65. data/app/views/feedback/show.html.erb +1 -1
  66. data/app/views/kaminari/blacklight/_paginator.html.erb +1 -1
  67. data/app/views/kaminari/blacklight_compact/_paginator.html.erb +25 -5
  68. data/app/views/layouts/blacklight.html.erb +23 -23
  69. data/app/views/saved_searches/index.html.erb +2 -2
  70. data/app/views/search_history/index.html.erb +5 -7
  71. data/app/views/shared/_header_navbar.html.erb +23 -23
  72. data/blacklight.gemspec +10 -13
  73. data/config/locales/blacklight.en.yml +1 -12
  74. data/config/locales/blacklight.fr.yml +1 -12
  75. data/gemfiles/rails3.gemfile +21 -0
  76. data/gemfiles/rails4.gemfile +20 -0
  77. data/lib/blacklight.rb +0 -8
  78. data/lib/blacklight/base.rb +0 -2
  79. data/lib/blacklight/catalog.rb +6 -32
  80. data/lib/blacklight/catalog/search_context.rb +8 -48
  81. data/lib/blacklight/configurable.rb +2 -1
  82. data/lib/blacklight/configuration.rb +1 -2
  83. data/lib/blacklight/configuration/facet_field.rb +0 -2
  84. data/lib/blacklight/engine.rb +3 -3
  85. data/lib/blacklight/legacy_controller_methods.rb +1 -64
  86. data/lib/blacklight/rails/routes.rb +17 -0
  87. data/lib/blacklight/routes.rb +46 -40
  88. data/lib/blacklight/solr.rb +1 -0
  89. data/lib/blacklight/solr/document.rb +21 -42
  90. data/lib/blacklight/solr/facet_paginator.rb +30 -54
  91. data/lib/blacklight/solr/request.rb +45 -0
  92. data/lib/blacklight/solr_helper.rb +16 -53
  93. data/lib/blacklight/solr_response.rb +0 -6
  94. data/lib/blacklight/user.rb +2 -7
  95. data/lib/blacklight/utils.rb +1 -9
  96. data/lib/generators/blacklight/assets_generator.rb +0 -14
  97. data/lib/generators/blacklight/blacklight_generator.rb +17 -14
  98. data/lib/generators/blacklight/templates/blacklight.css.scss +3 -0
  99. data/lib/generators/blacklight/templates/catalog_controller.rb +4 -1
  100. data/lib/railties/blacklight.rake +3 -1
  101. data/solr/sample_solr_documents.yml +641 -0
  102. data/spec/controllers/application_controller_spec.rb +5 -21
  103. data/spec/controllers/bookmarks_controller_spec.rb +11 -11
  104. data/spec/controllers/catalog_controller_spec.rb +122 -119
  105. data/spec/controllers/search_history_controller_spec.rb +8 -8
  106. data/spec/features/alternate_controller_spec.rb +5 -5
  107. data/spec/features/facets_spec.rb +9 -0
  108. data/spec/features/record_view_spec.rb +1 -1
  109. data/spec/features/search_filters_spec.rb +97 -41
  110. data/spec/features/search_results_spec.rb +14 -17
  111. data/spec/features/search_sort_spec.rb +1 -1
  112. data/spec/helpers/blacklight_helper_spec.rb +170 -285
  113. data/spec/helpers/catalog_helper_spec.rb +57 -96
  114. data/spec/helpers/facets_helper_spec.rb +130 -152
  115. data/spec/helpers/hash_as_hidden_fields_spec.rb +9 -15
  116. data/spec/helpers/render_constraints_helper_spec.rb +5 -5
  117. data/spec/helpers/search_history_constraints_helper_spec.rb +21 -21
  118. data/spec/lib/blacklight/routes_spec.rb +25 -0
  119. data/spec/lib/blacklight/solr/request_spec.rb +37 -0
  120. data/spec/lib/blacklight/solr_response/group_response_spec.rb +2 -2
  121. data/spec/lib/blacklight_configurable_spec.rb +16 -16
  122. data/spec/lib/blacklight_configuration_spec.rb +132 -132
  123. data/spec/lib/blacklight_email_spec.rb +4 -4
  124. data/spec/lib/blacklight_sms_spec.rb +4 -4
  125. data/spec/lib/blacklight_solr_document_dublin_core_spec.rb +6 -6
  126. data/spec/lib/blacklight_solr_document_more_like_this_spec.rb +4 -4
  127. data/spec/lib/blacklight_solr_document_spec.rb +36 -36
  128. data/spec/lib/blacklight_solr_response_spec.rb +43 -48
  129. data/spec/lib/blacklight_spec.rb +6 -14
  130. data/spec/lib/blacklight_user_spec.rb +5 -9
  131. data/spec/lib/facet_paginator_spec.rb +59 -51
  132. data/spec/lib/search_fields_spec.rb +13 -13
  133. data/spec/lib/solr_helper_spec.rb +258 -304
  134. data/spec/lib/tasks/blacklight_task_spec.rb +1 -1
  135. data/spec/lib/utils_spec.rb +16 -46
  136. data/spec/models/bookmark_spec.rb +6 -7
  137. data/spec/models/record_mailer_spec.rb +16 -16
  138. data/spec/models/search_spec.rb +8 -8
  139. data/spec/models/solr_document_spec.rb +6 -77
  140. data/spec/routing/catalog_routing_spec.rb +16 -10
  141. data/spec/spec_helper.rb +7 -7
  142. data/spec/support/assert_difference.rb +2 -2
  143. data/spec/support/features.rb +0 -11
  144. data/spec/support/features/session_helpers.rb +3 -3
  145. data/spec/support/include_text.rb +2 -2
  146. data/spec/test_app_templates/Gemfile.extra +10 -2
  147. data/spec/test_app_templates/lib/generators/test_app_generator.rb +12 -18
  148. data/spec/views/catalog/_constraints_element.html.erb_spec.rb +13 -13
  149. data/spec/views/catalog/_document.html.erb_spec.rb +1 -1
  150. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -1
  151. data/spec/views/catalog/_facets.html.erb_spec.rb +13 -14
  152. data/spec/views/catalog/_index_default.erb_spec.rb +21 -21
  153. data/spec/views/catalog/_search_header.erb_spec.rb +1 -1
  154. data/spec/views/catalog/_show_default.erb_spec.rb +21 -21
  155. data/spec/views/catalog/_show_sidebar.erb_spec.rb +7 -7
  156. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +3 -3
  157. data/spec/views/catalog/index.atom.builder_spec.rb +29 -29
  158. data/spec/views/catalog/index.html.erb_spec.rb +6 -7
  159. data/tasks/blacklight.rake +8 -2
  160. metadata +84 -180
  161. data/app/assets/javascripts/blacklight/css_dropdowns.js +0 -10
  162. data/app/assets/javascripts/blacklight/facet_expand_contract.js +0 -41
  163. data/app/assets/javascripts/blacklight/lightbox_dialog.js +0 -70
  164. data/app/assets/javascripts/blacklight/select_submit.js +0 -27
  165. data/app/assets/javascripts/blacklight/zebra_stripe.js +0 -13
  166. data/app/assets/javascripts/improved-modal/bootstrap-modal.js +0 -355
  167. data/app/assets/javascripts/improved-modal/bootstrap-modalmanager.js +0 -370
  168. data/app/assets/stylesheets/blacklight/_bookmark.scss +0 -33
  169. data/app/assets/stylesheets/blacklight/_catalog.scss +0 -255
  170. data/app/assets/stylesheets/blacklight/_dropdown.scss +0 -57
  171. data/app/assets/stylesheets/blacklight/_facets.scss +0 -197
  172. data/app/assets/stylesheets/blacklight/_footer.scss +0 -0
  173. data/app/assets/stylesheets/blacklight/_header.scss +0 -53
  174. data/app/assets/stylesheets/blacklight/_layout.scss +0 -10
  175. data/app/assets/stylesheets/blacklight/_mixins.scss +0 -0
  176. data/app/assets/stylesheets/blacklight/_print.scss +0 -0
  177. data/app/assets/stylesheets/blacklight/_responsive.scss +0 -3
  178. data/app/assets/stylesheets/blacklight/_search_history.scss +0 -42
  179. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -49
  180. data/app/assets/stylesheets/blacklight/responsive_partials/_catalog.scss +0 -5
  181. data/app/assets/stylesheets/blacklight/responsive_partials/_facets.scss +0 -37
  182. data/app/assets/stylesheets/blacklight/responsive_partials/_header.scss +0 -30
  183. data/app/assets/stylesheets/improved-modal/bootstrap-modal.css +0 -217
  184. data/app/helpers/blacklight/html_head_helper_behavior.rb +0 -118
  185. data/app/helpers/html_head_helper.rb +0 -3
  186. data/app/views/catalog/_bookmark_form.html.erb +0 -7
  187. data/app/views/catalog/_marc_view.html.erb +0 -32
  188. data/app/views/catalog/librarian_view.html.erb +0 -10
  189. data/config/routes.rb +0 -17
  190. data/doc/Atom-Responses.md +0 -90
  191. data/doc/Blacklight-3.0-Release-Notes-And-Upgrade-Guide.md +0 -107
  192. data/doc/Blacklight-3.2-Release-Notes-and-Upgrade-Guide.md +0 -191
  193. data/doc/Blacklight-3.3-release-notes-and-upgrade-guide.md +0 -37
  194. data/doc/Blacklight-3.4-release-notes-and-upgrade-guide.md +0 -27
  195. data/doc/Blacklight-3.5-release-notes-and-upgrade-guide.md +0 -44
  196. data/doc/Blacklight-3.6-release-notes-and-upgrade-guide.md +0 -25
  197. data/doc/Blacklight-3.7-release-notes-and-upgrade-guide.md +0 -80
  198. data/doc/Blacklight-3.8-release-notes-and-upgrade-guide.md +0 -11
  199. data/doc/Blacklight-4.0-release-notes-and-upgrade-guide.md +0 -135
  200. data/doc/Blacklight-4.1-release-notes-and-upgrade-guide.md +0 -17
  201. data/doc/Blacklight-4.2-release-notes-and-upgrade-guide.md +0 -25
  202. data/doc/Blacklight-4.3-release-notes-and-upgrade-guide.md +0 -21
  203. data/doc/Blacklight-4.4-release-notes-and-upgrade-guide.md +0 -41
  204. data/doc/Blacklight-Add-ons.md +0 -28
  205. data/doc/Blacklight-configuration.md +0 -411
  206. data/doc/Blacklight-on-Heroku.md +0 -135
  207. data/doc/Code4Lib-2014.md +0 -48
  208. data/doc/Community-principles.md +0 -44
  209. data/doc/Configuring-and-Customizing-Blacklight.md +0 -271
  210. data/doc/Configuring-rails-routes.md +0 -13
  211. data/doc/Contributing-to-Blacklight.md +0 -25
  212. data/doc/Examples.md +0 -94
  213. data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
  214. data/doc/FAQs.md +0 -1
  215. data/doc/Home.md +0 -80
  216. data/doc/How-to-release-a-version.md +0 -29
  217. data/doc/Indexing-your-data-into-solr.md +0 -32
  218. data/doc/Integration-with-Rails-Footnotes.md +0 -20
  219. data/doc/Internationalization.md +0 -32
  220. data/doc/JSON-API.md +0 -17
  221. data/doc/Pagination.md +0 -51
  222. data/doc/Providing-your-own-view-templates.md +0 -109
  223. data/doc/Quickstart.md +0 -115
  224. data/doc/README_SOLR.md +0 -245
  225. data/doc/Release-Notes-And-Upgrade-Guides.md +0 -20
  226. data/doc/Roadmap.md +0 -43
  227. data/doc/Sunspot-for-indexing.md +0 -46
  228. data/doc/Theming.md +0 -64
  229. data/doc/User-Authentication.md +0 -60
  230. data/doc/testing.md +0 -57
  231. data/lib/SolrMarc.jar +0 -0
  232. data/lib/blacklight/mash.rb +0 -19
  233. data/lib/blacklight/solr/document/marc.rb +0 -71
  234. data/lib/blacklight/solr/document/marc_export.rb +0 -590
  235. data/lib/generators/blacklight/marc_generator.rb +0 -66
  236. data/lib/generators/blacklight/templates/blacklight.scss +0 -4
  237. data/lib/generators/blacklight/templates/config/SolrMarc/config-test.properties +0 -37
  238. data/lib/generators/blacklight/templates/config/SolrMarc/config.properties +0 -37
  239. data/lib/generators/blacklight/templates/config/SolrMarc/index.properties +0 -97
  240. data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/dewey.bsh +0 -47
  241. data/lib/generators/blacklight/templates/config/SolrMarc/index_scripts/format.bsh +0 -126
  242. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/README_MAPS +0 -1
  243. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/callnumber_map.properties +0 -407
  244. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/composition_era_map.properties +0 -56
  245. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/country_map.properties +0 -379
  246. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/format_map.properties +0 -50
  247. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/instrument_map.properties +0 -101
  248. data/lib/generators/blacklight/templates/config/SolrMarc/translation_maps/language_map.properties +0 -490
  249. data/lib/railties/solr_marc.rake +0 -162
  250. data/spec/data/test_data.utf8.mrc +0 -1
  251. data/spec/features/librarian_view_spec.rb +0 -13
  252. data/spec/helpers/html_head_helper_spec.rb +0 -164
  253. data/spec/lib/blacklight_solr_document_marc_spec.rb +0 -89
  254. data/spec/lib/marc_export_spec.rb +0 -746
  255. data/spec/lib/tasks/solr_marc_task_spec.rb +0 -60
  256. data/spec/requests/alternate_controller_spec.rb +0 -16
  257. data/spec/routing/routes_spec.rb +0 -20
  258. data/spec/views/catalog/_constraints.html.erb_spec.rb +0 -33
  259. data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +0 -49
  260. data/test_support/data/test_data.utf8.mrc +0 -1
@@ -1,20 +0,0 @@
1
- This is for upgrade guides for each version.
2
- * [Blacklight 4.5 Release Notes and Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.5.0) (???)
3
- * [Blacklight 4.4 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.4.0) (September 17, 2013)
4
- * [Blacklight 4.3 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.3.0) (July 30, 2013)
5
- * [Blacklight 4.2.2 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.2.2) (2013)
6
- * [Blacklight 4.2.1 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.2.1) (2013)
7
- * [Blacklight 4.2.0 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.2.0) (Mar 29, 2013)
8
- * [Blacklight 4.1 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.1.0) (Mar 7, 2013)
9
- * [Blacklight 4.0 Release Notes And Upgrade Guide](https://github.com/projectblacklight/blacklight/releases/tag/v4.0.0) (Nov 29, 2012)
10
- * [[Blacklight 3.8 Release Notes And Upgrade Guide]] (Nov 2, 2012)
11
- * [[Blacklight 3.7 Release Notes And Upgrade Guide]] (Sep 25, 2012)
12
- * [[Blacklight 3.6 Release Notes And Upgrade Guide]] (Sep 10, 2012)
13
- * [[Blacklight 3.5 Release Notes And Upgrade Guide]] (Jun 25, 2012)
14
- * [[Blacklight 3.4 Release Notes And Upgrade Guide]] (Apr 24, 2012)
15
- * [[Blacklight 3.3 Release Notes And Upgrade Guide]] (Mar 19, 2012)
16
- * [[Blacklight 3.2 Release Notes And Upgrade Guide]] (Dec 15, 2011)
17
- * [[Blacklight 3.1 Release Notes And Upgrade Guide]] (Sep 28, 2011)
18
- * [[Blacklight 3.0 Release Notes And Upgrade Guide]] (July 11, 2011)
19
-
20
- Unreleased
@@ -1,43 +0,0 @@
1
- <table>
2
- <thead><td>Feature</td><td>What can be reused?</td><td>Who wants this</td><td>Who can work on this</td></thead>
3
- <tbody>
4
- <tr>
5
- <td>Document Index view toggles</td>
6
- <td><a href="https://revs-lib.stanford.edu/catalog?f%5Bpub_year_isim%5D%5B%5D=1930&q=&utf8=%E2%9C%93">Stanford</a>, <a href="http://levysheetmusic.mse.jhu.edu/catalog?utf8=%E2%9C%93&q=&f%5Bmods_subject_facet%5D%5B%5D=African+Americans">JHU</a></td>
7
- <td></td>
8
- <td></td>
9
- </tr>
10
- <tr>
11
- <td>i18n files in blacklight</td>
12
- <td>Stanford has fr + it</td>
13
- <td></td>
14
- <td></td>
15
- </tr>
16
-
17
- <tr>
18
- <td><a href="https://groups.google.com/forum/?fromgroups=#!topic/blacklight-development/Brz3ePltc3w">Thumbnails in search results</a></td>
19
- <td>Many places</td>
20
- <td></td>
21
- <td>cbeer</td>
22
- </tr>
23
-
24
- <tr>
25
- <td><a href="https://groups.google.com/forum/?fromgroups#!topic/blacklight-development/LGk2DtsA8rA">Blacklight curriculum for RailsBridge</a></td>
26
- <td></td>
27
- <td></td>
28
- <td>bess</td>
29
- </tr>
30
- <tr>
31
- <td>Tags and Comments</td>
32
- <td></td>
33
- <td>afred,awead</td>
34
- <td></td>
35
- </tr>
36
- <tr>
37
- <td>Caching</td>
38
- <td></td>
39
- <td>jronallo</td>
40
- <td></td>
41
- </tr>
42
- </tbody>
43
- </table>
@@ -1,46 +0,0 @@
1
- If you have a Rails application as your data store, you may look to [Sunspot](http://outoftime.github.com/sunspot/) to help index your ActiveRecord models. Sunspot provides a nice DSL that makes it easy to index your models and associations. There is one gotcha, though, for using Sunspot with Blacklight. Both Sunspot and Blacklight expect the Solr uniqueKey to be in the "id" field. Sunspot will use the class of your model plus the primary key of that instance as the value for the id field. So a value for the id field may look like this: "Resource 123".
2
-
3
- When a Sunspot-indexed Solr is used with Blacklight your model names and primary keys are exposed in your URLs. You may want to use a different value as your id value for Blacklight to use for document recall and URLs. For instance you want to use a unique filename as your id value for Blacklight.
4
-
5
- You can use something like the following monkeypatch of Sunspot (1.2) by placing it in config/initializers/sunspot_monkeypatch_id.rb. It takes the value of the id field that Sunspot creates (Resource 123) and places it in the resource_id_ss field. It then overwrites the id value with the value from the filename field. The second part then takes a Solr hit and reverses it so that Sunspot can retrieve your models.
6
-
7
- ```ruby
8
- # for using a different value for the id field of your Solr documents
9
- Sunspot::Indexer.module_eval do
10
- alias :old_prepare :prepare
11
- def prepare(model)
12
- document = old_prepare(model)
13
- document.fields_by_name(:resource_id_ss).first.value = document.fields_by_name(:id).first.value
14
- if !document.fields_by_name(:filename).blank? and !document.fields_by_name(:filename).first.blank?
15
- document.fields_by_name(:id).first.value = document.fields_by_name(:filename).first.value
16
- end
17
- document
18
- end
19
-
20
- alias :old_remove :remove
21
- def remove(*models)
22
- @connection.delete_by_id(
23
- models.map do |model|
24
- prepare(model).fields_by_name(:id).first.value
25
- end
26
- )
27
- end
28
-
29
- end
30
-
31
- # to allow searching with Sunspot's DSL as well to retrieve your models
32
- class Sunspot::Search::Hit
33
- def initialize(raw_hit, highlights, search)
34
- raw_hit['id'] = raw_hit['resource_id_ss']
35
- @class_name, @primary_key = *raw_hit['id'].match(/([^ ]+) (.+)/)[1..2]
36
- @score = raw_hit['score']
37
- @search = search
38
- @stored_values = raw_hit
39
- @stored_cache = {}
40
- @highlights = highlights
41
- end
42
- end
43
- ```
44
-
45
-
46
-
@@ -1,64 +0,0 @@
1
- # Theming Blacklight
2
-
3
- ## Bootswatches
4
-
5
- The Blacklight 4.x styling is [[Twitter Bootstrap|http://twitter.github.com/bootstrap]] based. While there is some Blacklight-specific code for handling layouts and positions, most (if not all) the "styling" (colors, fonts, etc) are handled by Bootstrap.
6
-
7
- There are many sources for Bootstrap themes. We'll look at bootswatches because they are fairly painless to integrate into a Rails application.
8
-
9
- First, add the [[bootswatch-rails gem|https://github.com/maxim/bootswatch-rails]] to your Gemfile (and run ```bundle install```):
10
-
11
- ```ruby
12
- gem 'bootswatch-rails'
13
- ```
14
-
15
- This will give you the set of themes from [[http://bootswatch.com/]], converted to SASS and exposed to the Rails asset pipeline.
16
-
17
- Out of the box, your application's blacklight stylesheet (generated by default to ```app/assets/stylesheets/blacklight.css.scss```) looks something like:
18
-
19
- ```css
20
- @import 'bootstrap';
21
- @import 'bootstrap-responsive';
22
-
23
- @import 'blacklight/blacklight';
24
- ```
25
-
26
- To add the one of the bootswatch themes ('cerulean' in this example):
27
-
28
- ```css
29
- @import "bootswatch/cerulean/variables";
30
-
31
- @import "bootstrap";
32
- @import "bootstrap-responsive";
33
-
34
- @import "bootswatch/cerulean/bootswatch";
35
-
36
- @import 'blacklight/blacklight'
37
- ```
38
-
39
- ![Blacklight with the Cerulean theme applied](http://projectblacklight.org/images/blacklight-cerulean.png)
40
-
41
- The [[bootswatch-rails|https://github.com/maxim/bootswatch-rails]] documentation provides similar directions, a list of available out-of-the-box themes, and more.
42
-
43
- > As of this writing, not all bootswatch-rails themes seem to be bootstrap 2.1.x compatible, or do weird things to the Blacklight navbar, etc. Your milage may vary.
44
-
45
- ## Developing a Customized "Local" Theme
46
-
47
- In most cases, you will want to develop your own theme within your Blacklight app, outside of the Bootswatch gem. To do this, you can do the following in your ```app/assets/stylesheets``` directory:
48
-
49
- 1. create your own _variables.scss and _bootswatch.scss files in stylesheets/ (easiest way to do this is to copy those files from the [[bootstrap-sass project|https://github.com/thomas-mcdonald/bootstrap-sass/tree/master/vendor/assets/stylesheets/bootstrap]] or an existing theme and customize from there)
50
- 2. change application.css to application.css.scss
51
- 3. add the import statements given in the above "theming" example to application.css.scss
52
- 4. delete blacklight.css.scss
53
-
54
- So, your application.css.scss should look like this:
55
- ```css
56
- @import "variables";
57
-
58
- @import "bootstrap";
59
- @import "bootstrap-responsive";
60
-
61
- @import "bootswatch";
62
-
63
- @import 'blacklight/blacklight'
64
- ```
@@ -1,60 +0,0 @@
1
- Blacklight does not require user authentication, however, if included, Blacklight can provide additional features for users ([[Bookmarks]], [[Saved Searches]], etc). Because of the wide range of institutional needs and capabilities, Blacklight does not require a specific user authentication provider.
2
-
3
- ## Installing with Devise
4
-
5
- If you are rolling your own user authentication system, we highly recommend [[Devise|https://github.com/plataformatec/devise]], an extremely flexible authentication solution that is relatively straightforward. For directions to install the Blacklight gem using devise, see the [[Quickstart]].
6
-
7
- ## Install and Use (with a custom user authentication system)
8
-
9
- Create a new rails 3 application
10
- ```bash
11
- $ rails new my_app
12
- ```
13
-
14
- Add blacklight to your gem file
15
- ```bash
16
- edit ./my_app/Gemfile
17
- ```
18
- ```ruby.
19
- # Append this line to the end of the file:
20
- gem 'blacklight'
21
- ```
22
-
23
- ```bash
24
- $ bundle install
25
- ```
26
-
27
- If you have a `User` model already, the Blacklight generator will connect to it automatically during installation. However, you will need to make sure the following named routes are included in your /config/routes.rb file:
28
-
29
- ```ruby
30
- match 'your_login', :to => 'Your User Session Controller # Log in action', :as => 'new_user_session'
31
- match 'your_logout', :to => 'Your User Session Controller # Log Out action', :as => 'destroy_user_session'
32
- match 'your_account_page', :to => 'Your User Session Controller # Account edit action', :as => 'edit_user_registration'
33
- ```
34
-
35
- One blacklight view partial uses `#to_s` on your user model to get a user-displayable account name/identifier for the currently logged in account, so you probably want to have such a method.
36
-
37
- Finally, you will need to make sure the following methods are available both on controllers and as helpers:
38
-
39
- * `current_user` - Which should return an ActiveRecord-based user object that include Blacklight::User
40
- * `user_session` - Which are included in your /config/routes.rb file:
41
-
42
- Optionally,
43
- * `guest_user` - Which should return an ActiveRecord-based temporary guest user object available across the current user session.
44
- * `current_or_guest_user` - Which should return the `current_user`, if available, or `guest_user`. If you don't provide this method, a stub method (that just returns `current_user`) will be provided for you.
45
-
46
- If you are supporting guest users, if a guest user logs in, you should call `#transfer_guest_user_actions_to_current_user` to move any persisted data to the permanent user.
47
-
48
- > The `devise-guests` gem implements the `guest_user`, `current_or_guest_user` and callbacks for Blacklight applications using devise. It may be a useful reference for rolling your own functionality. See [DeviseGuests::Controllers::Helpers](https://github.com/cbeer/devise-guests/blob/master/lib/devise-guests/controllers/helpers.rb)
49
-
50
- Once these are in place, you can run the Blacklight Installation Generator:
51
-
52
- ```bash
53
- $ rails generate blacklight [MODEL NAME]
54
- ```
55
- Where model name is the name of your user model.
56
-
57
- Execute your migrations, and you should be good to go.
58
- ```bash
59
- $ rake db:migrate
60
- ```
@@ -1,57 +0,0 @@
1
- ## Using Blacklight source checkout as gem for development
2
-
3
- The ordinary install instructions install the BL gem (which is not
4
- full source code) in wherever your system installs gems.
5
-
6
- Sometimes, especially for development, it's useful to check out
7
- a complete copy of the blacklight source code, and link your app
8
- to that as a 'gem' instead.
9
-
10
- Checkout the code:
11
-
12
- $ git clone git@github.com:projectblacklight/blacklight.git
13
-
14
-
15
- ## Automatically generate a test application (and run the tests)
16
-
17
- To run the Blacklight test suite, Blacklight comes with a rake task that creates local dependencies like a Solr with indexed test data and a test Rails application, and then runs tests.
18
-
19
- Requirements:
20
-
21
- * Java (1.6 or above) (for Solr)
22
- * phantomjs (used by integration tests, you may be able to install with your local package manager, for instance on OSX with `brew install phantomjs`)
23
-
24
- Then from the root directory of your blacklight git checkout:
25
-
26
- ```
27
- rake ci
28
- ```
29
- This ensure a test Solr exists and is running, creates a test application, and loads the fixtures and then runs specs and cucumber tests.
30
-
31
- ### Step by step, with more control
32
-
33
- `rake ci` will, every time you run it, re-index test data in solr, and re-build the test application. Re-building the test application in particular is kind of time-consuming. You may prefer to set up the environment and run tests as separate steps, to make development easier.
34
-
35
- To create the dummy test app:
36
-
37
- $ rake engine_cart:generate
38
-
39
- (If you have an existing dummy app that is outdated, `rake engine_cart:clean` first, then `rake engine_cart:generate).
40
-
41
- Then start up the test jetty with:
42
-
43
- $ rake jetty:start
44
-
45
- If you haven't yet indexed the test data in the test jetty. (??? Not sure how to do this. Run `rake ci` once to make sure test data has been indexed). Run `rake jetty:stop` when you're done with it.
46
-
47
- Then run all the specs with:
48
-
49
- $ rake spec
50
-
51
- Or just run one spec
52
-
53
- $ rake spec SPEC=just/one_spec.rb
54
-
55
- And stop your test solr when you're done with it:
56
-
57
- $ rake jetty:stop
Binary file
@@ -1,19 +0,0 @@
1
- # This class has dubious semantics and we only have it so that people can write
2
- # params[:key] instead of params['key'].
3
- class Mash < HashWithIndifferentAccess
4
- def initialize *args, &block
5
- ActiveSupport::Deprecation.warn("Mash is deprecated, and should be replaced with HashWithIndifferentAccess")
6
-
7
- super
8
- end
9
- end
10
-
11
- unless Hash.respond_to?(:to_mash)
12
- class Hash
13
- def to_mash
14
- ActiveSupport::Deprecation.warn("Hash#to_mash is deprecated, and should be replaced with #with_indifferent_access")
15
-
16
- HashWithIndifferentAccess.new(self)
17
- end
18
- end
19
- end
@@ -1,71 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- # This is a document extension meant to be mixed into a
4
- # Blacklight::Solr::Document class, such as SolrDocument. It provides support
5
- # for restoration of MARC data (xml or binary) from a Solr stored field, and
6
- # then provides various transformations/exports of that Marc via the included
7
- # Blacklight::Solr::Document::MarcExport module.
8
- #
9
- # This extension would normally be registered using
10
- # Blacklight::Solr::Document#use_extension. eg:
11
- #
12
- # SolrDocument.use_extension( Blacklight::Solr::Document::Marc ) { |document| my_logic_for_document_has_marc?( document ) }
13
- #
14
- # This extension also expects a :marc_source_field and :marc_format_type to
15
- # be registered with the hosting classes extension_parameters. In an initializer
16
- # or other startup code:
17
- # SolrDocument.extension_paramters[:marc_source_field] = "name_of_solr_stored_field"
18
- # SolrDocument.extension_parameters[:marc_format_type] = :marc21 # or :marcxml
19
- module Blacklight::Solr::Document::Marc
20
- require 'marc'
21
-
22
- include Blacklight::Solr::Document::MarcExport # All our export_as stuff based on to_marc.
23
-
24
- class UnsupportedMarcFormatType < RuntimeError; end
25
-
26
- def self.extended(document)
27
- # Register our exportable formats, we inherit these from MarcExport
28
- Blacklight::Solr::Document::MarcExport.register_export_formats( document )
29
- end
30
-
31
- # ruby-marc object
32
- def to_marc
33
- @_ruby_marc_obj ||= load_marc
34
- end
35
-
36
-
37
- protected
38
- def marc_source
39
- @_marc_source ||= fetch(_marc_source_field)
40
- end
41
-
42
- def load_marc
43
- case _marc_format_type.to_s
44
- when 'marcxml'
45
- records = MARC::XMLReader.new(StringIO.new( fetch(_marc_source_field) )).to_a
46
- return records[0]
47
- when 'marc21'
48
- return MARC::Record.new_from_marc( fetch(_marc_source_field) )
49
- else
50
-
51
- raise UnsupportedMarcFormatType.new("Only marcxml and marc21 are supported, this documents format is #{_marc_format_type} and the current extension parameters are #{self.class.extension_parameters.inspect}")
52
- end
53
- end
54
-
55
-
56
-
57
- def _marc_helper
58
- @_marc_helper ||= (
59
- Blacklight::Marc::Document.new fetch(_marc_source_field), _marc_format_type )
60
- end
61
-
62
- def _marc_source_field
63
- self.class.extension_parameters[:marc_source_field]
64
- end
65
-
66
- def _marc_format_type
67
- #TODO: Raise if not present
68
- self.class.extension_parameters[:marc_format_type]
69
- end
70
-
71
- end
@@ -1,590 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- # -*- coding: utf-8 -*-
3
- # Written for use with Blacklight::Solr::Document::Marc, but you can use
4
- # it for your own custom Blacklight document Marc extension too -- just
5
- # include this module in any document extension (or any other class)
6
- # that provides a #to_marc returning a ruby-marc object. This module will add
7
- # in export_as translation methods for a variety of formats.
8
- module Blacklight::Solr::Document::MarcExport
9
- extend Deprecation
10
- self.deprecation_horizon = 'Blacklight 5.x'
11
-
12
-
13
- def self.register_export_formats(document)
14
- document.will_export_as(:xml)
15
- document.will_export_as(:marc, "application/marc")
16
- # marcxml content type:
17
- # http://tools.ietf.org/html/draft-denenberg-mods-etc-media-types-00
18
- document.will_export_as(:marcxml, "application/marcxml+xml")
19
- document.will_export_as(:openurl_ctx_kev, "application/x-openurl-ctx-kev")
20
- document.will_export_as(:refworks_marc_txt, "text/plain")
21
- document.will_export_as(:endnote, "application/x-endnote-refer")
22
- end
23
-
24
-
25
- def export_as_marc
26
- to_marc.to_marc
27
- end
28
-
29
- def export_as_marcxml
30
- to_marc.to_xml.to_s
31
- end
32
- alias_method :export_as_xml, :export_as_marcxml
33
-
34
-
35
- # TODO This exporting as formatted citation thing should be re-thought
36
- # redesigned at some point to be more general purpose, but this
37
- # is in-line with what we had before, but at least now attached
38
- # to the document extension where it belongs.
39
- def export_as_apa_citation_txt
40
- apa_citation( to_marc )
41
- end
42
-
43
- def export_as_mla_citation_txt
44
- mla_citation( to_marc )
45
- end
46
-
47
- def export_as_chicago_citation_txt
48
- chicago_citation( to_marc )
49
- end
50
-
51
- # Exports as an OpenURL KEV (key-encoded value) query string.
52
- # For use to create COinS, among other things. COinS are
53
- # for Zotero, among other things. TODO: This is wierd and fragile
54
- # code, it should use ruby OpenURL gem instead to work a lot
55
- # more sensibly. The "format" argument was in the old marc.marc.to_zotero
56
- # call, but didn't neccesarily do what it thought it did anyway. Left in
57
- # for now for backwards compatibilty, but should be replaced by
58
- # just ruby OpenURL.
59
- def export_as_openurl_ctx_kev(format = nil)
60
- title = to_marc.find{|field| field.tag == '245'}
61
- author = to_marc.find{|field| field.tag == '100'}
62
- corp_author = to_marc.find{|field| field.tag == '110'}
63
- publisher_info = to_marc.find{|field| field.tag == '260'}
64
- edition = to_marc.find{|field| field.tag == '250'}
65
- isbn = to_marc.find{|field| field.tag == '020'}
66
- issn = to_marc.find{|field| field.tag == '022'}
67
- unless format.nil?
68
- format.is_a?(Array) ? format = format[0].downcase.strip : format = format.downcase.strip
69
- end
70
- export_text = ""
71
- if format == 'book'
72
- export_text << "ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;rft.genre=book&amp;"
73
- export_text << "rft.btitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;"
74
- export_text << "rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;"
75
- export_text << "rft.au=#{(author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a'])}&amp;"
76
- export_text << "rft.aucorp=#{CGI::escape(corp_author['a']) if corp_author['a']}+#{CGI::escape(corp_author['b']) if corp_author['b']}&amp;" unless corp_author.blank?
77
- export_text << "rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&amp;"
78
- export_text << "rft.place=#{(publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a'])}&amp;"
79
- export_text << "rft.pub=#{(publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b'])}&amp;"
80
- export_text << "rft.edition=#{(edition.nil? or edition['a'].nil?) ? "" : CGI::escape(edition['a'])}&amp;"
81
- export_text << "rft.isbn=#{(isbn.nil? or isbn['a'].nil?) ? "" : isbn['a']}"
82
- elsif (format =~ /journal/i) # checking using include because institutions may use formats like Journal or Journal/Magazine
83
- export_text << "ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;rft.genre=article&amp;"
84
- export_text << "rft.title=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;"
85
- export_text << "rft.atitle=#{(title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a'])}+#{(title.nil? or title['b'].nil?) ? "" : CGI::escape(title['b'])}&amp;"
86
- export_text << "rft.aucorp=#{CGI::escape(corp_author['a']) if corp_author['a']}+#{CGI::escape(corp_author['b']) if corp_author['b']}&amp;" unless corp_author.blank?
87
- export_text << "rft.date=#{(publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c'])}&amp;"
88
- export_text << "rft.issn=#{(issn.nil? or issn['a'].nil?) ? "" : issn['a']}"
89
- else
90
- export_text << "ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator&amp;"
91
- export_text << "rft.title=" + ((title.nil? or title['a'].nil?) ? "" : CGI::escape(title['a']))
92
- export_text << ((title.nil? or title['b'].nil?) ? "" : CGI.escape(" ") + CGI::escape(title['b']))
93
- export_text << "&amp;rft.creator=" + ((author.nil? or author['a'].nil?) ? "" : CGI::escape(author['a']))
94
- export_text << "&amp;rft.aucorp=#{CGI::escape(corp_author['a']) if corp_author['a']}+#{CGI::escape(corp_author['b']) if corp_author['b']}" unless corp_author.blank?
95
- export_text << "&amp;rft.date=" + ((publisher_info.nil? or publisher_info['c'].nil?) ? "" : CGI::escape(publisher_info['c']))
96
- export_text << "&amp;rft.place=" + ((publisher_info.nil? or publisher_info['a'].nil?) ? "" : CGI::escape(publisher_info['a']))
97
- export_text << "&amp;rft.pub=" + ((publisher_info.nil? or publisher_info['b'].nil?) ? "" : CGI::escape(publisher_info['b']))
98
- export_text << "&amp;rft.format=" + (format.nil? ? "" : CGI::escape(format))
99
- end
100
- export_text.html_safe unless export_text.blank?
101
- end
102
-
103
-
104
- # This format used to be called 'refworks', which wasn't really
105
- # accurate, sounds more like 'refworks tagged format'. Which this
106
- # is not, it's instead some weird under-documented Refworks
107
- # proprietary marc-ish in text/plain format. See
108
- # http://robotlibrarian.billdueber.com/sending-marcish-data-to-refworks/
109
- def export_as_refworks_marc_txt
110
- fields = to_marc.find_all { |f| ('000'..'999') === f.tag }
111
- text = "LEADER #{to_marc.leader}"
112
- fields.each do |field|
113
- unless ["940","999"].include?(field.tag)
114
- if field.is_a?(MARC::ControlField)
115
- text << "#{field.tag} #{field.value}\n"
116
- else
117
- text << "#{field.tag} "
118
- text << (field.indicator1 ? field.indicator1 : " ")
119
- text << (field.indicator2 ? field.indicator2 : " ")
120
- text << " "
121
- field.each {|s| s.code == 'a' ? text << "#{s.value}" : text << " |#{s.code}#{s.value}"}
122
- text << "\n"
123
- end
124
- end
125
- end
126
-
127
- # As of 11 May 2010, Refworks has a problem with UTF-8 if it's decomposed,
128
- # it seems to want C form normalization, although RefWorks support
129
- # couldn't tell me that. -jrochkind
130
- text = ActiveSupport::Multibyte::Unicode.normalize(text, :c)
131
-
132
- return text
133
- end
134
-
135
- # Endnote Import Format. See the EndNote User Guide at:
136
- # http://www.endnote.com/support/enx3man-terms-win.asp
137
- # Chapter 7: Importing Reference Data into EndNote / Creating a Tagged “EndNote Import” File
138
- #
139
- # Note: This code is copied from what used to be in the previous version
140
- # in ApplicationHelper#render_to_endnote. It does NOT produce very good
141
- # endnote import format; the %0 is likely to be entirely illegal, the
142
- # rest of the data is barely correct but messy. TODO, a new version of this,
143
- # or better yet just an export_as_ris instead, which will be more general
144
- # purpose.
145
- def export_as_endnote()
146
- end_note_format = {
147
- "%A" => "100.a",
148
- "%C" => "260.a",
149
- "%D" => "260.c",
150
- "%E" => "700.a",
151
- "%I" => "260.b",
152
- "%J" => "440.a",
153
- "%@" => "020.a",
154
- "%_@" => "022.a",
155
- "%T" => "245.a,245.b",
156
- "%U" => "856.u",
157
- "%7" => "250.a"
158
- }
159
- marc_obj = to_marc
160
-
161
- # TODO. This should be rewritten to guess
162
- # from actual Marc instead, probably.
163
- format_str = 'Generic'
164
-
165
- text = ''
166
- text << "%0 #{ format_str }\n"
167
- # If there is some reliable way of getting the language of a record we can add it here
168
- #text << "%G #{record['language'].first}\n"
169
- end_note_format.each do |key,value|
170
- values = value.split(",")
171
- first_value = values[0].split('.')
172
- if values.length > 1
173
- second_value = values[1].split('.')
174
- else
175
- second_value = []
176
- end
177
-
178
- if marc_obj[first_value[0].to_s]
179
- marc_obj.find_all{|f| (first_value[0].to_s) === f.tag}.each do |field|
180
- if field[first_value[1]].to_s or field[second_value[1]].to_s
181
- text << "#{key.gsub('_','')}"
182
- if field[first_value[1]].to_s
183
- text << " #{field[first_value[1]].to_s}"
184
- end
185
- if field[second_value[1]].to_s
186
- text << " #{field[second_value[1]].to_s}"
187
- end
188
- text << "\n"
189
- end
190
- end
191
- end
192
- end
193
- text
194
- end
195
-
196
- ## DEPRECATED stuff left in for backwards compatibility, but should
197
- # be gotten rid of eventually.
198
-
199
- def to_zotero(format)
200
- Deprecation.warn(self, "Simply call document.export_as_openurl_kev to get an openURL kev context object suitable for including in a COinS; then have view code make the span for the COinS. ")
201
- "<span class=\"Z3988\" title=\"#{export_as_openurl_kev(format)}\"></span>"
202
- end
203
-
204
- def to_apa
205
- Deprecation.warn(self, "Call document.export_as_apa_citation instead.")
206
- export_as_apa_citation
207
- end
208
-
209
- def to_mla
210
- Deprecation.warn(self, "Call document.export_as_mla_citation instead.")
211
- end
212
-
213
-
214
-
215
- protected
216
-
217
- # Main method for defining chicago style citation. If we don't end up converting to using a citation formatting service
218
- # we should make this receive a semantic document and not MARC so we can use this with other formats.
219
- def chicago_citation(marc)
220
- authors = get_all_authors(marc)
221
- author_text = ""
222
- unless authors[:primary_authors].blank?
223
- if authors[:primary_authors].length > 10
224
- authors[:primary_authors].each_with_index do |author,index|
225
- if index < 7
226
- if index == 0
227
- author_text << "#{author}"
228
- if author.ends_with?(",")
229
- author_text << " "
230
- else
231
- author_text << ", "
232
- end
233
- else
234
- author_text << "#{name_reverse(author)}, "
235
- end
236
- end
237
- end
238
- author_text << " et al."
239
- elsif authors[:primary_authors].length > 1
240
- authors[:primary_authors].each_with_index do |author,index|
241
- if index == 0
242
- author_text << "#{author}"
243
- if author.ends_with?(",")
244
- author_text << " "
245
- else
246
- author_text << ", "
247
- end
248
- elsif index + 1 == authors[:primary_authors].length
249
- author_text << "and #{name_reverse(author)}."
250
- else
251
- author_text << "#{name_reverse(author)}, "
252
- end
253
- end
254
- else
255
- author_text << authors[:primary_authors].first
256
- end
257
- else
258
- temp_authors = []
259
- authors[:translators].each do |translator|
260
- temp_authors << [translator, "trans."]
261
- end
262
- authors[:editors].each do |editor|
263
- temp_authors << [editor, "ed."]
264
- end
265
- authors[:compilers].each do |compiler|
266
- temp_authors << [compiler, "comp."]
267
- end
268
-
269
- unless temp_authors.blank?
270
- if temp_authors.length > 10
271
- temp_authors.each_with_index do |author,index|
272
- if index < 7
273
- author_text << "#{author.first} #{author.last} "
274
- end
275
- end
276
- author_text << " et al."
277
- elsif temp_authors.length > 1
278
- temp_authors.each_with_index do |author,index|
279
- if index == 0
280
- author_text << "#{author.first} #{author.last}, "
281
- elsif index + 1 == temp_authors.length
282
- author_text << "and #{name_reverse(author.first)} #{author.last}"
283
- else
284
- author_text << "#{name_reverse(author.first)} #{author.last}, "
285
- end
286
- end
287
- else
288
- author_text << "#{temp_authors.first.first} #{temp_authors.first.last}"
289
- end
290
- end
291
- end
292
- title = ""
293
- additional_title = ""
294
- section_title = ""
295
- if marc["245"] and (marc["245"]["a"] or marc["245"]["b"])
296
- title << citation_title(clean_end_punctuation(marc["245"]["a"]).strip) if marc["245"]["a"]
297
- title << ": #{citation_title(clean_end_punctuation(marc["245"]["b"]).strip)}" if marc["245"]["b"]
298
- end
299
- if marc["245"] and (marc["245"]["n"] or marc["245"]["p"])
300
- section_title << citation_title(clean_end_punctuation(marc["245"]["n"])) if marc["245"]["n"]
301
- if marc["245"]["p"]
302
- section_title << ", <i>#{citation_title(clean_end_punctuation(marc["245"]["p"]))}.</i>"
303
- elsif marc["245"]["n"]
304
- section_title << "."
305
- end
306
- end
307
-
308
- if !authors[:primary_authors].blank? and (!authors[:translators].blank? or !authors[:editors].blank? or !authors[:compilers].blank?)
309
- additional_title << "Translated by #{authors[:translators].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:translators].blank?
310
- additional_title << "Edited by #{authors[:editors].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:editors].blank?
311
- additional_title << "Compiled by #{authors[:compilers].collect{|name| name_reverse(name)}.join(" and ")}. " unless authors[:compilers].blank?
312
- end
313
-
314
- edition = ""
315
- edition << setup_edition(marc) unless setup_edition(marc).nil?
316
-
317
- pub_info = ""
318
- if marc["260"] and (marc["260"]["a"] or marc["260"]["b"])
319
- pub_info << clean_end_punctuation(marc["260"]["a"]).strip if marc["260"]["a"]
320
- pub_info << ": #{clean_end_punctuation(marc["260"]["b"]).strip}" if marc["260"]["b"]
321
- pub_info << ", #{setup_pub_date(marc)}" if marc["260"]["c"]
322
- elsif marc["502"] and marc["502"]["a"] # MARC 502 is the Dissertation Note. This holds the correct pub info for these types of records.
323
- pub_info << marc["502"]["a"]
324
- elsif marc["502"] and (marc["502"]["b"] or marc["502"]["c"] or marc["502"]["d"]) #sometimes the dissertation note is encoded in pieces in the $b $c and $d sub fields instead of lumped into the $a
325
- pub_info << "#{marc["502"]["b"]}, #{marc["502"]["c"]}, #{clean_end_punctuation(marc["502"]["d"])}"
326
- end
327
-
328
- citation = ""
329
- citation << "#{author_text} " unless author_text.blank?
330
- citation << "<i>#{title}.</i> " unless title.blank?
331
- citation << "#{section_title} " unless section_title.blank?
332
- citation << "#{additional_title} " unless additional_title.blank?
333
- citation << "#{edition} " unless edition.blank?
334
- citation << "#{pub_info}." unless pub_info.blank?
335
- citation
336
- end
337
-
338
-
339
-
340
- def mla_citation(record)
341
- text = ''
342
- authors_final = []
343
-
344
- #setup formatted author list
345
- authors = get_author_list(record)
346
-
347
- if authors.length < 4
348
- authors.each do |l|
349
- if l == authors.first #first
350
- authors_final.push(l)
351
- elsif l == authors.last #last
352
- authors_final.push(", and " + name_reverse(l) + ".")
353
- else #all others
354
- authors_final.push(", " + name_reverse(l))
355
- end
356
- end
357
- text += authors_final.join
358
- unless text.blank?
359
- if text[-1,1] != "."
360
- text += ". "
361
- else
362
- text += " "
363
- end
364
- end
365
- else
366
- text += authors.first + ", et al. "
367
- end
368
- # setup title
369
- title = setup_title_info(record)
370
- if !title.nil?
371
- text += "<i>" + mla_citation_title(title) + "</i> "
372
- end
373
-
374
- # Edition
375
- edition_data = setup_edition(record)
376
- text += edition_data + " " unless edition_data.nil?
377
-
378
- # Publication
379
- text += setup_pub_info(record) + ", " unless setup_pub_info(record).nil?
380
-
381
- # Get Pub Date
382
- text += setup_pub_date(record) unless setup_pub_date(record).nil?
383
- if text[-1,1] != "."
384
- text += "." unless text.nil? or text.blank?
385
- end
386
- text
387
- end
388
-
389
- def apa_citation(record)
390
- text = ''
391
- authors_list = []
392
- authors_list_final = []
393
-
394
- #setup formatted author list
395
- authors = get_author_list(record)
396
- authors.each do |l|
397
- authors_list.push(abbreviate_name(l)) unless l.blank?
398
- end
399
- authors_list.each do |l|
400
- if l == authors_list.first #first
401
- authors_list_final.push(l.strip)
402
- elsif l == authors_list.last #last
403
- authors_list_final.push(", &amp; " + l.strip)
404
- else #all others
405
- authors_list_final.push(", " + l.strip)
406
- end
407
- end
408
- text += authors_list_final.join
409
- unless text.blank?
410
- if text[-1,1] != "."
411
- text += ". "
412
- else
413
- text += " "
414
- end
415
- end
416
- # Get Pub Date
417
- text += "(" + setup_pub_date(record) + "). " unless setup_pub_date(record).nil?
418
-
419
- # setup title info
420
- title = setup_title_info(record)
421
- text += "<i>" + title + "</i> " unless title.nil?
422
-
423
- # Edition
424
- edition_data = setup_edition(record)
425
- text += edition_data + " " unless edition_data.nil?
426
-
427
- # Publisher info
428
- text += setup_pub_info(record) unless setup_pub_info(record).nil?
429
- unless text.blank?
430
- if text[-1,1] != "."
431
- text += "."
432
- end
433
- end
434
- text
435
- end
436
- def setup_pub_date(record)
437
- if !record.find{|f| f.tag == '260'}.nil?
438
- pub_date = record.find{|f| f.tag == '260'}
439
- if pub_date.find{|s| s.code == 'c'}
440
- date_value = pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9|n\.d\.]/, "")[0,4] unless pub_date.find{|s| s.code == 'c'}.value.gsub(/[^0-9|n\.d\.]/, "")[0,4].blank?
441
- end
442
- return nil if date_value.nil?
443
- end
444
- clean_end_punctuation(date_value) if date_value
445
- end
446
- def setup_pub_info(record)
447
- text = ''
448
- pub_info_field = record.find{|f| f.tag == '260'}
449
- if !pub_info_field.nil?
450
- a_pub_info = pub_info_field.find{|s| s.code == 'a'}
451
- b_pub_info = pub_info_field.find{|s| s.code == 'b'}
452
- a_pub_info = clean_end_punctuation(a_pub_info.value.strip) unless a_pub_info.nil?
453
- b_pub_info = b_pub_info.value.strip unless b_pub_info.nil?
454
- text += a_pub_info.strip unless a_pub_info.nil?
455
- if !a_pub_info.nil? and !b_pub_info.nil?
456
- text += ": "
457
- end
458
- text += b_pub_info.strip unless b_pub_info.nil?
459
- end
460
- return nil if text.strip.blank?
461
- clean_end_punctuation(text.strip)
462
- end
463
-
464
- def mla_citation_title(text)
465
- no_upcase = ["a","an","and","but","by","for","it","of","the","to","with"]
466
- new_text = []
467
- word_parts = text.split(" ")
468
- word_parts.each do |w|
469
- if !no_upcase.include? w
470
- new_text.push(w.capitalize)
471
- else
472
- new_text.push(w)
473
- end
474
- end
475
- new_text.join(" ")
476
- end
477
-
478
- # This will replace the mla_citation_title method with a better understanding of how MLA and Chicago citation titles are formatted.
479
- # This method will take in a string and capitalize all of the non-prepositions.
480
- def citation_title(title_text)
481
- prepositions = ["a","about","across","an","and","before","but","by","for","it","of","the","to","with","without"]
482
- new_text = []
483
- title_text.split(" ").each_with_index do |word,index|
484
- if (index == 0 and word != word.upcase) or (word.length > 1 and word != word.upcase and !prepositions.include?(word))
485
- # the split("-") will handle the capitalization of hyphenated words
486
- new_text << word.split("-").map!{|w| w.capitalize }.join("-")
487
- else
488
- new_text << word
489
- end
490
- end
491
- new_text.join(" ")
492
- end
493
-
494
- def setup_title_info(record)
495
- text = ''
496
- title_info_field = record.find{|f| f.tag == '245'}
497
- if !title_info_field.nil?
498
- a_title_info = title_info_field.find{|s| s.code == 'a'}
499
- b_title_info = title_info_field.find{|s| s.code == 'b'}
500
- a_title_info = clean_end_punctuation(a_title_info.value.strip) unless a_title_info.nil?
501
- b_title_info = clean_end_punctuation(b_title_info.value.strip) unless b_title_info.nil?
502
- text += a_title_info unless a_title_info.nil?
503
- if !a_title_info.nil? and !b_title_info.nil?
504
- text += ": "
505
- end
506
- text += b_title_info unless b_title_info.nil?
507
- end
508
-
509
- return nil if text.strip.blank?
510
- clean_end_punctuation(text.strip) + "."
511
-
512
- end
513
-
514
- def clean_end_punctuation(text)
515
- if [".",",",":",";","/"].include? text[-1,1]
516
- return text[0,text.length-1]
517
- end
518
- text
519
- end
520
-
521
- def setup_edition(record)
522
- edition_field = record.find{|f| f.tag == '250'}
523
- edition_code = edition_field.find{|s| s.code == 'a'} unless edition_field.nil?
524
- edition_data = edition_code.value unless edition_code.nil?
525
- if edition_data.nil? or edition_data == '1st ed.'
526
- return nil
527
- else
528
- return edition_data
529
- end
530
- end
531
-
532
- def get_author_list(record)
533
- author_list = []
534
- authors_primary = record.find{|f| f.tag == '100'}
535
- author_primary = authors_primary.find{|s| s.code == 'a'}.value unless authors_primary.nil? rescue ''
536
- author_list.push(clean_end_punctuation(author_primary)) unless author_primary.nil?
537
- authors_secondary = record.find_all{|f| ('700') === f.tag}
538
- if !authors_secondary.nil?
539
- authors_secondary.each do |l|
540
- author_list.push(clean_end_punctuation(l.find{|s| s.code == 'a'}.value)) unless l.find{|s| s.code == 'a'}.value.nil?
541
- end
542
- end
543
-
544
- author_list.uniq!
545
- author_list
546
- end
547
-
548
- # This is a replacement method for the get_author_list method. This new method will break authors out into primary authors, translators, editors, and compilers
549
- def get_all_authors(record)
550
- translator_code = "trl"; editor_code = "edt"; compiler_code = "com"
551
- primary_authors = []; translators = []; editors = []; compilers = []
552
- record.find_all{|f| f.tag === "100" }.each do |field|
553
- primary_authors << field["a"] if field["a"]
554
- end
555
- record.find_all{|f| f.tag === "700" }.each do |field|
556
- if field["a"]
557
- relators = []
558
- relators << clean_end_punctuation(field["e"]) if field["e"]
559
- relators << clean_end_punctuation(field["4"]) if field["4"]
560
- if relators.include?(translator_code)
561
- translators << field["a"]
562
- elsif relators.include?(editor_code)
563
- editors << field["a"]
564
- elsif relators.include?(compiler_code)
565
- compilers << field["a"]
566
- else
567
- primary_authors << field["a"]
568
- end
569
- end
570
- end
571
- {:primary_authors => primary_authors, :translators => translators, :editors => editors, :compilers => compilers}
572
- end
573
-
574
- def abbreviate_name(name)
575
- name_parts = name.split(", ")
576
- first_name_parts = name_parts.last.split(" ")
577
- temp_name = name_parts.first + ", " + first_name_parts.first[0,1] + "."
578
- first_name_parts.shift
579
- temp_name += " " + first_name_parts.join(" ") unless first_name_parts.empty?
580
- temp_name
581
- end
582
-
583
- def name_reverse(name)
584
- name = clean_end_punctuation(name)
585
- return name unless name =~ /,/
586
- temp_name = name.split(", ")
587
- return temp_name.last + " " + temp_name.first
588
- end
589
-
590
- end