hydra-head 3.2.0.pre2 → 3.2.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hydra-head (3.2.0.pre1)
4
+ hydra-head (3.2.0.pre2)
5
5
  RedCloth (= 4.2.3)
6
6
  active-fedora (>= 3.2.0.pre6)
7
- blacklight (= 3.0.0)
7
+ blacklight (= 3.1.2)
8
8
  block_helpers
9
9
  builder (= 2.1.2)
10
10
  columnize
@@ -28,7 +28,6 @@ PATH
28
28
  rack-test
29
29
  rails (~> 3.0.10)
30
30
  rake
31
- rsolr (= 1.0.2)
32
31
  sanitize
33
32
  solr-ruby
34
33
  solrizer (>= 1.1.0)
@@ -56,7 +55,7 @@ GEM
56
55
  rack-mount (~> 0.6.14)
57
56
  rack-test (~> 0.5.7)
58
57
  tzinfo (~> 0.3.23)
59
- active-fedora (3.2.0.pre6)
58
+ active-fedora (3.2.0.pre7)
60
59
  activeresource (>= 3.0.0)
61
60
  activesupport (>= 3.0.0)
62
61
  equivalent-xml
@@ -89,13 +88,13 @@ GEM
89
88
  akami (1.0.0)
90
89
  gyoku (>= 0.4.0)
91
90
  arel (2.0.10)
92
- blacklight (3.0.0)
91
+ blacklight (3.1.2)
93
92
  kaminari
94
93
  marc (~> 0.4.3)
95
94
  nokogiri (~> 1.5)
96
95
  rails (~> 3.0)
97
- rsolr (~> 1.0)
98
- rsolr-ext (~> 1.0)
96
+ rsolr (= 1.0.2)
97
+ rsolr-ext (= 1.0.3)
99
98
  unicode
100
99
  block_helpers (0.3.3)
101
100
  activesupport (>= 2.0)
data/HISTORY.textile CHANGED
@@ -1,4 +1,5 @@
1
1
  h3. 3.2.0
2
+ * Update to Blacklight 3.1.2
2
3
  * Update to ActiveFedora 3.2.0
3
4
  * Update to solrizer-fedora 1.2.2
4
5
  * Remove calls to has_relationship
data/hydra-head.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Hydra-Head is a Rails Engine containing the core code for a Hydra application. The full hydra stack includes: Blacklight, Fedora, Solr, active-fedora, solrizer, and om}
14
14
 
15
15
  s.add_dependency "rails", '~> 3.0.10'
16
- s.add_dependency "rsolr", '1.0.2' ## version 1.0.6 breaks when using blacklight 3.0.0
17
- s.add_dependency "blacklight", '3.0.0'
16
+ # s.add_dependency "rsolr", '1.0.2' ## version 1.0.6 breaks when using blacklight 3.1.0
17
+ s.add_dependency "blacklight", '~>3.1.2'
18
18
  s.add_dependency "active-fedora", '>=3.2.0.pre6'
19
19
  s.add_dependency 'builder', '2.1.2'
20
20
  s.add_dependency 'columnize'
@@ -5,608 +5,608 @@
5
5
  #
6
6
  # Methods added to this helper will be available to all templates in the hosting application
7
7
  #
8
- module Blacklight::BlacklightHelperBehavior
9
- include HashAsHiddenFields
10
- include RenderConstraintsHelper
11
-
12
-
13
- def application_name
14
- 'Blacklight'
15
- end
16
-
17
- ##
18
- # This method should be included in any Blacklight layout, including
19
- # custom ones. It will output results of #render_js_includes,
20
- # #render_stylesheet_includes, and all the content of
21
- # current_controller#extra_head_content.
22
- #
23
- # Uses controller methods #extra_head_content, #javascript_includes,
24
- # and #stylesheet_links to find content. Tolerates it if those
25
- # methods don't exist, silently skipping.
26
- #
27
- # By a layout outputting this in html HEAD, it provides an easy way for
28
- # local config or extra plugins to add HEAD content.
29
- #
30
- # Add your own css or remove the defaults by simply editing
31
- # controller.stylesheet_links, controller.javascript_includes,
32
- # or controller.extra_head_content.
33
- #
34
- #
35
- #
36
- # in an initializer or other startup file (plugin init.rb?):
37
- #
38
- # == Apply to all actions in all controllers:
39
- #
40
- # ApplicationController.before_filter do |controller|
41
- # # remove default jquery-ui theme.
42
- # controller.stylesheet_links.each do |args|
43
- # args.delete_if {|a| a =~ /^|\/jquery-ui-[\d.]+\.custom\.css$/ }
44
- # end
45
- #
46
- # # add in a different jquery-ui theme, or any other css or what have you
47
- # controller.stylesheet_links << 'my_css.css'
48
- #
49
- # controller.javascript_includes << "my_local_behaviors.js"
50
- #
51
- # controller.extra_head_content << '<link rel="something" href="something">'
52
- # end
53
- #
54
- # == Apply to a particular action in a particular controller:
55
- #
56
- # CatalogController.before_filter :only => :show |controller|
57
- # controller.extra_head_content << '<link rel="something" href="something">'
58
- # end
59
- #
60
- # == Or in a view file that wants to add certain header content? no problem:
61
- #
62
- # <% stylesheet_links << "mystylesheet.css" %>
63
- # <% javascript_includes << "my_js.js" %>
64
- # <% extra_head_content << capture do %>
65
- # <%= tag :link, { :href => some_method_for_something, :rel => "alternate" } %>
66
- # <% end %>
67
- #
68
- # == Full power of javascript_include_tag and stylesheet_link_tag
69
- # Note that the elements added to stylesheet_links and javascript_links
70
- # are arguments to Rails javascript_include_tag and stylesheet_link_tag
71
- # respectively, you can pass complex arguments. eg:
72
- #
73
- # stylesheet_links << ["stylesheet1.css", "stylesheet2.css", {:cache => "mykey"}]
74
- # javascript_includes << ["myjavascript.js", {:plugin => :myplugin} ]
75
- def render_head_content
76
- render_stylesheet_includes +
77
- render_js_includes +
78
- render_extra_head_content
79
- end
80
-
81
- ##
82
- # Assumes controller has a #stylesheet_link_tag method, array with
83
- # each element being a set of arguments for stylesheet_link_tag
84
- # See #render_head_content for instructions on local code or plugins
85
- # adding stylesheets.
86
- def render_stylesheet_includes
87
- return "".html_safe unless respond_to?(:stylesheet_links)
88
-
89
- stylesheet_links.uniq.collect do |args|
90
- stylesheet_link_tag(*args)
91
- end.join("\n").html_safe
92
- end
93
-
94
-
95
- ##
96
- # Assumes controller has a #js_includes method, array with each
97
- # element being a set of arguments for javsascript_include_tag.
98
- # See #render_head_content for instructions on local code or plugins
99
- # adding js files.
100
- def render_js_includes
101
- return "".html_safe unless respond_to?(:javascript_includes)
102
-
103
- javascript_includes.uniq.collect do |args|
104
- javascript_include_tag(*args)
105
- end.join("\n").html_safe
106
- end
107
-
108
- ##
109
- # Assumes controller has a #extra_head_content method
110
- #
111
- def render_extra_head_content
112
- return "".html_safe unless respond_to?(:extra_head_content)
113
-
114
- extra_head_content.join("\n").html_safe
115
- end
116
-
117
- # Create <link rel="alternate"> links from a documents dynamically
118
- # provided export formats. Currently not used by standard BL layouts,
119
- # but available for your custom layouts to provide link rel alternates.
120
- #
121
- # Returns empty string if no links available.
122
- #
123
- # :unique => true, will ensure only one link is output for every
124
- # content type, as required eg in atom. Which one 'wins' is arbitrary.
125
- # :exclude => array of format shortnames, formats to not include at all.
126
- def render_link_rel_alternates(document=@document, options = {})
127
- options = {:unique => false, :exclude => []}.merge(options)
128
-
129
- return nil if document.nil?
130
-
131
- seen = Set.new
132
-
133
- html = ""
134
- document.export_formats.each_pair do |format, spec|
135
- unless( options[:exclude].include?(format) ||
136
- (options[:unique] && seen.include?(spec[:content_type]))
137
- )
138
- html << tag(:link, {:rel=>"alternate", :title=>format, :type => spec[:content_type], :href=> catalog_url(document.id, format)}) << "\n"
139
-
140
- seen.add(spec[:content_type]) if options[:unique]
141
- end
142
- end
143
- return html.html_safe
144
- end
145
-
146
- def render_opensearch_response_metadata
147
- render :partial => 'catalog/opensearch_response_metadata'
148
- end
149
-
150
- def render_body_class
151
- extra_body_classes.join " "
152
- end
153
-
154
- # collection of items to be rendered in the @sidebar
155
- def sidebar_items
156
- @sidebar_items ||= []
157
- end
158
-
159
- def extra_body_classes
160
- @extra_body_classes ||= ['blacklight-' + controller.controller_name, 'blacklight-' + [controller.controller_name, controller.action_name].join('-')]
161
- end
162
-
163
- #
164
- # Blacklight.config based helpers ->
165
- #
166
-
167
- # used in the catalog/_facets partial
168
- def facet_field_labels
169
- Blacklight.config[:facet][:labels]
170
- end
171
-
172
- # used in the catalog/_facets partial
173
- def facet_field_names
174
- Blacklight.config[:facet][:field_names]
175
- end
176
-
177
- # used in the catalog/_facets partial and elsewhere
178
- # Renders a single section for facet limit with a specified
179
- # solr field used for faceting. Can be over-ridden for custom
180
- # display on a per-facet basis.
181
- def render_facet_limit(solr_field)
182
- render( :partial => "catalog/facet_limit", :locals => {:solr_field =>solr_field })
183
- end
184
-
185
- def render_document_list_partial options={}
186
- render :partial=>'catalog/document_list'
187
- end
188
-
189
- # Save function area for search results 'index' view, normally
190
- # renders next to title. Includes just 'Folder' by default.
191
- def render_index_doc_actions(document, options={})
192
- content_tag("div", :class=>"documentFunctions") do
193
- raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
194
- #{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
195
- end
196
- end
197
-
198
- # Save function area for item detail 'show' view, normally
199
- # renders next to title. By default includes 'Folder' and 'Bookmarks'
200
- def render_show_doc_actions(document=@document, options={})
201
- content_tag("div", :class=>"documentFunctions") do
202
- raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
203
- #{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
204
- end
205
- end
206
-
207
- # used in the catalog/_index_partials/_default view
208
- def index_field_names
209
- Blacklight.config[:index_fields][:field_names]
210
- end
211
-
212
- # used in the _index_partials/_default view
213
- def index_field_labels
214
- Blacklight.config[:index_fields][:labels]
215
- end
216
-
217
- def spell_check_max
218
- Blacklight.config[:spell_max] || 0
219
- end
220
-
221
- def render_index_field_label args
222
- field = args[:field]
223
- html_escape index_field_labels[field]
224
- end
225
-
226
- def render_index_field_value args
227
- value = args[:value]
228
- value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
229
- render_field_value value
230
- end
231
-
232
- # Used in the show view for displaying the main solr document heading
233
- def document_heading
234
- @document[Blacklight.config[:show][:heading]] || @document.id
235
- end
236
- def render_document_heading
237
- content_tag(:h1, document_heading)
238
- end
239
-
240
- # Used in the show view for setting the main html document title
241
- def document_show_html_title
242
- @document[Blacklight.config[:show][:html_title]]
243
- end
244
-
245
- # Used in citation view for displaying the title
246
- def citation_title(document)
247
- document[Blacklight.config[:show][:html_title]]
248
- end
249
-
250
- # Used in the document_list partial (search view) for building a select element
251
- def sort_fields
252
- Blacklight.config[:sort_fields]
253
- end
254
-
255
- # Used in the document list partial (search view) for creating a link to the document show action
256
- def document_show_link_field
257
- Blacklight.config[:index][:show_link].to_sym
258
- end
259
-
260
- # Used in the search form partial for building a select tag
261
- def search_fields
262
- Blacklight.search_field_options_for_select
263
- end
264
-
265
- # used in the catalog/_show/_default partial
266
- def document_show_fields
267
- Blacklight.config[:show_fields][:field_names]
268
- end
269
-
270
- # used in the catalog/_show/_default partial
271
- def document_show_field_labels
272
- Blacklight.config[:show_fields][:labels]
273
- end
274
-
275
- def render_document_show_field_label args
276
- field = args[:field]
277
- html_escape document_show_field_labels[field]
278
- end
279
-
280
- def render_document_show_field_value args
281
- value = args[:value]
282
- value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
283
- render_field_value value
284
- end
285
-
286
- def render_field_value value=nil
287
- value = [value] unless value.is_a? Array
288
- value = value.collect { |x| x.respond_to?(:force_encoding) ? x.force_encoding("UTF-8") : x}
289
- return value.map { |v| html_escape v }.join(field_value_separator).html_safe
290
- end
291
-
292
- def field_value_separator
293
- ', '
294
- end
295
-
296
- # Return a normalized partial name that can be used to contruct view partial path
297
- def document_partial_name(document)
298
- # .to_s is necessary otherwise the default return value is not always a string
299
- # using "_" as sep. to more closely follow the views file naming conventions
300
- # parameterize uses "-" as the default sep. which throws errors
301
- display_type = document[Blacklight.config[:show][:display_type]]
302
-
303
- return 'default' unless display_type
304
- display_type = display_type.join(" ") if display_type.respond_to?(:join)
305
-
306
- "#{display_type.gsub("-"," ")}".parameterize("_").to_s
307
- end
308
-
309
- # given a doc and action_name, this method attempts to render a partial template
310
- # based on the value of doc[:format]
311
- # if this value is blank (nil/empty) the "default" is used
312
- # if the partial is not found, the "default" partial is rendered instead
313
- def render_document_partial(doc, action_name)
314
- format = document_partial_name(doc)
315
- begin
316
- render :partial=>"catalog/_#{action_name}_partials/#{format}", :locals=>{:document=>doc}
317
- rescue ActionView::MissingTemplate
318
- render :partial=>"catalog/_#{action_name}_partials/default", :locals=>{:document=>doc}
319
- end
320
- end
321
-
322
- # Search History and Saved Searches display
323
- def link_to_previous_search(params)
324
- link_to(raw(render_search_to_s(params)), catalog_index_path(params)).html_safe
325
- end
326
-
327
- #
328
- # facet param helpers ->
329
- #
330
-
331
- # Standard display of a facet value in a list. Used in both _facets sidebar
332
- # partial and catalog/facet expanded list. Will output facet value name as
333
- # a link to add that to your restrictions, with count in parens.
334
- # first arg item is a facet value item from rsolr-ext.
335
- # options consist of:
336
- # :suppress_link => true # do not make it a link, used for an already selected value for instance
337
- def render_facet_value(facet_solr_field, item, options ={})
338
- (link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
339
- end
340
-
341
- # Standard display of a SELECTED facet value, no link, special span
342
- # with class, and 'remove' button.
343
- def render_selected_facet_value(facet_solr_field, item)
344
- content_tag(:span, render_facet_value(facet_solr_field, item, :suppress_link => true), :class => "selected label") +
345
- link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
346
- end
347
-
348
- # Renders a count value for facet limits. Can be over-ridden locally
349
- # to change style, for instance not use parens. And can be called
350
- # by plugins to get consistent display.
351
- def render_facet_count(num)
352
- content_tag("span", "(" + format_num(num) + ")", :class => "count")
353
- end
354
-
355
- # adds the value and/or field to params[:f]
356
- # Does NOT remove request keys and otherwise ensure that the hash
357
- # is suitable for a redirect. See
358
- # add_facet_params_and_redirect
359
- def add_facet_params(field, value)
360
- p = params.dup
361
- p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
362
- p[:f][field] = (p[:f][field] || []).dup
363
- p[:f][field].push(value)
364
- p
365
- end
366
-
367
- # Used in catalog/facet action, facets.rb view, for a click
368
- # on a facet value. Add on the facet params to existing
369
- # search constraints. Remove any paginator-specific request
370
- # params, or other request params that should be removed
371
- # for a 'fresh' display.
372
- # Change the action to 'index' to send them back to
373
- # catalog/index with their new facet choice.
374
- def add_facet_params_and_redirect(field, value)
375
- new_params = add_facet_params(field, value)
376
-
377
- # Delete page, if needed.
378
- new_params.delete(:page)
379
-
380
- # Delete any request params from facet-specific action, needed
381
- # to redir to index action properly.
382
- Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
383
- new_params.delete(paginator_key)
384
- end
385
- new_params.delete(:id)
386
-
387
- # Force action to be index.
388
- new_params[:action] = "index"
389
- new_params
390
- end
391
- # copies the current params (or whatever is passed in as the 3rd arg)
392
- # removes the field value from params[:f]
393
- # removes the field if there are no more values in params[:f][field]
394
- # removes additional params (page, id, etc..)
395
- def remove_facet_params(field, value, source_params=params)
396
- p = source_params.dup
397
- # need to dup the facet values too,
398
- # if the values aren't dup'd, then the values
399
- # from the session will get remove in the show view...
400
- p[:f] = p[:f].dup
401
- p[:f][field] = p[:f][field].nil? ? [] : p[:f][field].dup
402
- p.delete :page
403
- p.delete :id
404
- p.delete :counter
405
- p.delete :commit
406
- #return p unless p[field]
407
- p[:f][field] = p[:f][field] - [value]
408
- p[:f].delete(field) if p[:f][field].size == 0
409
- p
410
- end
411
-
412
- # true or false, depending on whether the field and value is in params[:f]
413
- def facet_in_params?(field, value)
414
- params[:f] and params[:f][field] and params[:f][field].include?(value)
415
- end
416
-
417
- #
418
- # shortcut for built-in Rails helper, "number_with_delimiter"
419
- #
420
- def format_num(num); number_with_delimiter(num) end
421
-
422
- #
423
- # link based helpers ->
424
- #
425
-
426
- # create link to query (e.g. spelling suggestion)
427
- def link_to_query(query)
428
- p = params.dup
429
- p.delete :page
430
- p.delete :action
431
- p[:q]=query
432
- link_url = catalog_index_path(p)
433
- link_to(query, link_url)
434
- end
435
-
436
- def render_document_index_label doc, opts
437
- label = nil
438
- label ||= doc.get(opts[:label]) if opts[:label].instance_of? Symbol
439
- label ||= opts[:label].call(doc, opts) if opts[:label].instance_of? Proc
440
- label ||= opts[:label] if opts[:label].is_a? String
441
- label ||= doc.id
442
- end
443
-
444
- # link_to_document(doc, :label=>'VIEW', :counter => 3)
445
- # Use the catalog_path RESTful route to create a link to the show page for a specific item.
446
- # catalog_path accepts a HashWithIndifferentAccess object. The solr query params are stored in the session,
447
- # so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results.
448
- def link_to_document(doc, opts={:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil, :results_view => true})
449
- label = render_document_index_label doc, opts
450
- link_to_with_data(label, catalog_path(doc.id), {:method => :put, :class => label.parameterize, :data => opts}).html_safe
451
- end
452
-
453
- # link_back_to_catalog(:label=>'Back to Search')
454
- # Create a link back to the index screen, keeping the user's facet, query and paging choices intact by using session.
455
- def link_back_to_catalog(opts={:label=>'Back to Search'})
456
- query_params = session[:search] ? session[:search].dup : {}
457
- query_params.delete :counter
458
- query_params.delete :total
459
- link_url = catalog_index_path + "?" + query_params.to_query
460
- link_to opts[:label], link_url
461
- end
462
-
463
- # Create form input type=hidden fields representing the entire search context,
464
- # for inclusion in a form meant to change some aspect of it, like
465
- # re-sort or change records per page. Can pass in params hash
466
- # as :params => hash, otherwise defaults to #params. Can pass
467
- # in certain top-level params keys to _omit_, defaults to :page
468
- def search_as_hidden_fields(options={})
469
-
470
- options = {:params => params, :omit_keys => [:page]}.merge(options)
471
- my_params = options[:params].dup
472
- options[:omit_keys].each {|omit_key| my_params.delete(omit_key)}
473
- # removing action and controller from duplicate params so that we don't get hidden fields for them.
474
- my_params.delete(:action)
475
- my_params.delete(:controller)
476
- # commit is just an artifact of submit button, we don't need it, and
477
- # don't want it to pile up with another every time we press submit again!
478
- my_params.delete(:commit)
479
- # hash_as_hidden_fields in hash_as_hidden_fields.rb
480
- return hash_as_hidden_fields(my_params)
481
- end
482
-
483
-
484
-
485
- def link_to_previous_document(previous_document)
486
- return if previous_document == nil
487
- link_to_document previous_document, :label=>'« Previous', :counter => session[:search][:counter].to_i - 1
488
- end
489
-
490
- def link_to_next_document(next_document)
491
- return if next_document == nil
492
- link_to_document next_document, :label=>'Next »', :counter => session[:search][:counter].to_i + 1
493
- end
494
-
495
- # Use case, you want to render an html partial from an XML (say, atom)
496
- # template. Rails API kind of lets us down, we need to hack Rails internals
497
- # a bit. code taken from:
498
- # http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
499
- def with_format(format, &block)
500
- old_format = @template_format
501
- @template_format = format
502
- result = block.call
503
- @template_format = old_format
504
- return result
505
- end
506
-
507
-
508
- # This is an updated +link_to+ that allows you to pass a +data+ hash along with the +html_options+
509
- # which are then written to the generated form for non-GET requests. The key is the form element name
510
- # and the value is the value:
511
- #
512
- # link_to_with_data('Name', some_path(some_id), :method => :post, :html)
513
- def link_to_with_data(*args, &block)
514
- if block_given?
515
- options = args.first || {}
516
- html_options = args.second
517
- concat(link_to(capture(&block), options, html_options))
518
- else
519
- name = args.first
520
- options = args.second || {}
521
- html_options = args.third
522
-
523
- url = url_for(options)
524
-
525
- if html_options
526
- html_options = html_options.stringify_keys
527
- href = html_options['href']
528
- convert_options_to_javascript_with_data!(html_options, url)
529
- tag_options = tag_options(html_options)
530
- else
531
- tag_options = nil
532
- end
533
-
534
- href_attr = "href=\"#{url}\"" unless href
535
- "<a #{href_attr}#{tag_options}>#{h(name) || h(url)}</a>".html_safe
536
- end
537
- end
538
-
539
- # This is derived from +convert_options_to_javascript+ from module +UrlHelper+ in +url_helper.rb+
540
- def convert_options_to_javascript_with_data!(html_options, url = '')
541
- confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
542
-
543
- method, href = html_options.delete("method"), html_options['href']
544
- data = html_options.delete("data")
545
- data = data.stringify_keys if data
546
-
547
- html_options["onclick"] = case
548
- when method
549
- "#{method_javascript_function_with_data(method, url, href, data)}return false;"
550
- else
551
- html_options["onclick"]
552
- end
553
- end
554
-
555
- # This is derived from +method_javascript_function+ from module +UrlHelper+ in +url_helper.rb+
556
- def method_javascript_function_with_data(method, url = '', href = nil, data=nil)
557
- action = (href && url.size > 0) ? "'#{url}'" : 'this.href'
558
- submit_function =
559
- "var f = document.createElement('form'); f.style.display = 'none'; " +
560
- "this.parentNode.appendChild(f); f.method = 'POST'; f.action = #{action};"+
561
- "if(event.metaKey || event.ctrlKey){f.target = '_blank';};" # if the command or control key is being held down while the link is clicked set the form's target to _blank
562
- if data
563
- data.each_pair do |key, value|
564
- submit_function << "var d = document.createElement('input'); d.setAttribute('type', 'hidden'); "
565
- submit_function << "d.setAttribute('name', '#{key}'); d.setAttribute('value', '#{escape_javascript(value.to_s)}'); f.appendChild(d);"
566
- end
567
- end
568
- unless method == :post
569
- submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "
570
- submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);"
571
- end
572
-
573
- if protect_against_forgery?
574
- submit_function << "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); "
575
- submit_function << "s.setAttribute('name', '#{request_forgery_protection_token}'); s.setAttribute('value', '#{escape_javascript form_authenticity_token}'); f.appendChild(s);"
576
- end
577
- submit_function << "f.submit();"
578
- end
579
-
580
- # determines if the given document id is in the folder
581
- def item_in_folder?(doc_id)
582
- session[:folder_document_ids] && session[:folder_document_ids].include?(doc_id) ? true : false
583
- end
584
-
585
- # puts together a collection of documents into one refworks export string
586
- def render_refworks_texts(documents)
587
- val = ''
588
- documents.each do |doc|
589
- if doc.respond_to?(:to_marc)
590
- val += doc.export_as_refworks_marc_txt + "\n"
591
- end
592
- end
593
- val
594
- end
595
-
596
- # puts together a collection of documents into one endnote export string
597
- def render_endnote_texts(documents)
598
- val = ''
599
- documents.each do |doc|
600
- if doc.respond_to?(:to_marc)
601
- val += doc.export_as_endnote + "\n"
602
- end
603
- end
604
- val
605
- end
606
-
607
-
608
- def render_document_unapi_microformat(document, options={})
609
- render(:partial=>'catalog/unapi_microformat', :locals => {:document=> document}.merge(options))
610
- end
611
-
612
- end
8
+ # module Blacklight::BlacklightHelperBehavior
9
+ # include HashAsHiddenFields
10
+ # include RenderConstraintsHelper
11
+ #
12
+ #
13
+ # def application_name
14
+ # 'Blacklight'
15
+ # end
16
+ #
17
+ # ##
18
+ # # This method should be included in any Blacklight layout, including
19
+ # # custom ones. It will output results of #render_js_includes,
20
+ # # #render_stylesheet_includes, and all the content of
21
+ # # current_controller#extra_head_content.
22
+ # #
23
+ # # Uses controller methods #extra_head_content, #javascript_includes,
24
+ # # and #stylesheet_links to find content. Tolerates it if those
25
+ # # methods don't exist, silently skipping.
26
+ # #
27
+ # # By a layout outputting this in html HEAD, it provides an easy way for
28
+ # # local config or extra plugins to add HEAD content.
29
+ # #
30
+ # # Add your own css or remove the defaults by simply editing
31
+ # # controller.stylesheet_links, controller.javascript_includes,
32
+ # # or controller.extra_head_content.
33
+ # #
34
+ # #
35
+ # #
36
+ # # in an initializer or other startup file (plugin init.rb?):
37
+ # #
38
+ # # == Apply to all actions in all controllers:
39
+ # #
40
+ # # ApplicationController.before_filter do |controller|
41
+ # # # remove default jquery-ui theme.
42
+ # # controller.stylesheet_links.each do |args|
43
+ # # args.delete_if {|a| a =~ /^|\/jquery-ui-[\d.]+\.custom\.css$/ }
44
+ # # end
45
+ # #
46
+ # # # add in a different jquery-ui theme, or any other css or what have you
47
+ # # controller.stylesheet_links << 'my_css.css'
48
+ # #
49
+ # # controller.javascript_includes << "my_local_behaviors.js"
50
+ # #
51
+ # # controller.extra_head_content << '<link rel="something" href="something">'
52
+ # # end
53
+ # #
54
+ # # == Apply to a particular action in a particular controller:
55
+ # #
56
+ # # CatalogController.before_filter :only => :show |controller|
57
+ # # controller.extra_head_content << '<link rel="something" href="something">'
58
+ # # end
59
+ # #
60
+ # # == Or in a view file that wants to add certain header content? no problem:
61
+ # #
62
+ # # <% stylesheet_links << "mystylesheet.css" %>
63
+ # # <% javascript_includes << "my_js.js" %>
64
+ # # <% extra_head_content << capture do %>
65
+ # # <%= tag :link, { :href => some_method_for_something, :rel => "alternate" } %>
66
+ # # <% end %>
67
+ # #
68
+ # # == Full power of javascript_include_tag and stylesheet_link_tag
69
+ # # Note that the elements added to stylesheet_links and javascript_links
70
+ # # are arguments to Rails javascript_include_tag and stylesheet_link_tag
71
+ # # respectively, you can pass complex arguments. eg:
72
+ # #
73
+ # # stylesheet_links << ["stylesheet1.css", "stylesheet2.css", {:cache => "mykey"}]
74
+ # # javascript_includes << ["myjavascript.js", {:plugin => :myplugin} ]
75
+ # def render_head_content
76
+ # render_stylesheet_includes +
77
+ # render_js_includes +
78
+ # render_extra_head_content
79
+ # end
80
+ #
81
+ # ##
82
+ # # Assumes controller has a #stylesheet_link_tag method, array with
83
+ # # each element being a set of arguments for stylesheet_link_tag
84
+ # # See #render_head_content for instructions on local code or plugins
85
+ # # adding stylesheets.
86
+ # def render_stylesheet_includes
87
+ # return "".html_safe unless respond_to?(:stylesheet_links)
88
+ #
89
+ # stylesheet_links.uniq.collect do |args|
90
+ # stylesheet_link_tag(*args)
91
+ # end.join("\n").html_safe
92
+ # end
93
+ #
94
+ #
95
+ # ##
96
+ # # Assumes controller has a #js_includes method, array with each
97
+ # # element being a set of arguments for javsascript_include_tag.
98
+ # # See #render_head_content for instructions on local code or plugins
99
+ # # adding js files.
100
+ # def render_js_includes
101
+ # return "".html_safe unless respond_to?(:javascript_includes)
102
+ #
103
+ # javascript_includes.uniq.collect do |args|
104
+ # javascript_include_tag(*args)
105
+ # end.join("\n").html_safe
106
+ # end
107
+ #
108
+ # ##
109
+ # # Assumes controller has a #extra_head_content method
110
+ # #
111
+ # def render_extra_head_content
112
+ # return "".html_safe unless respond_to?(:extra_head_content)
113
+ #
114
+ # extra_head_content.join("\n").html_safe
115
+ # end
116
+ #
117
+ # # Create <link rel="alternate"> links from a documents dynamically
118
+ # # provided export formats. Currently not used by standard BL layouts,
119
+ # # but available for your custom layouts to provide link rel alternates.
120
+ # #
121
+ # # Returns empty string if no links available.
122
+ # #
123
+ # # :unique => true, will ensure only one link is output for every
124
+ # # content type, as required eg in atom. Which one 'wins' is arbitrary.
125
+ # # :exclude => array of format shortnames, formats to not include at all.
126
+ # def render_link_rel_alternates(document=@document, options = {})
127
+ # options = {:unique => false, :exclude => []}.merge(options)
128
+ #
129
+ # return nil if document.nil?
130
+ #
131
+ # seen = Set.new
132
+ #
133
+ # html = ""
134
+ # document.export_formats.each_pair do |format, spec|
135
+ # unless( options[:exclude].include?(format) ||
136
+ # (options[:unique] && seen.include?(spec[:content_type]))
137
+ # )
138
+ # html << tag(:link, {:rel=>"alternate", :title=>format, :type => spec[:content_type], :href=> catalog_url(document.id, format)}) << "\n"
139
+ #
140
+ # seen.add(spec[:content_type]) if options[:unique]
141
+ # end
142
+ # end
143
+ # return html.html_safe
144
+ # end
145
+ #
146
+ # def render_opensearch_response_metadata
147
+ # render :partial => 'catalog/opensearch_response_metadata'
148
+ # end
149
+ #
150
+ # def render_body_class
151
+ # extra_body_classes.join " "
152
+ # end
153
+ #
154
+ # # collection of items to be rendered in the @sidebar
155
+ # def sidebar_items
156
+ # @sidebar_items ||= []
157
+ # end
158
+ #
159
+ # def extra_body_classes
160
+ # @extra_body_classes ||= ['blacklight-' + controller.controller_name, 'blacklight-' + [controller.controller_name, controller.action_name].join('-')]
161
+ # end
162
+ #
163
+ # #
164
+ # # Blacklight.config based helpers ->
165
+ # #
166
+ #
167
+ # # used in the catalog/_facets partial
168
+ # def facet_field_labels
169
+ # Blacklight.config[:facet][:labels]
170
+ # end
171
+ #
172
+ # # used in the catalog/_facets partial
173
+ # def facet_field_names
174
+ # Blacklight.config[:facet][:field_names]
175
+ # end
176
+ #
177
+ # # used in the catalog/_facets partial and elsewhere
178
+ # # Renders a single section for facet limit with a specified
179
+ # # solr field used for faceting. Can be over-ridden for custom
180
+ # # display on a per-facet basis.
181
+ # def render_facet_limit(solr_field)
182
+ # render( :partial => "catalog/facet_limit", :locals => {:solr_field =>solr_field })
183
+ # end
184
+ #
185
+ # def render_document_list_partial options={}
186
+ # render :partial=>'catalog/document_list'
187
+ # end
188
+ #
189
+ # # Save function area for search results 'index' view, normally
190
+ # # renders next to title. Includes just 'Folder' by default.
191
+ # def render_index_doc_actions(document, options={})
192
+ # content_tag("div", :class=>"documentFunctions") do
193
+ # raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
194
+ # #{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
195
+ # end
196
+ # end
197
+ #
198
+ # # Save function area for item detail 'show' view, normally
199
+ # # renders next to title. By default includes 'Folder' and 'Bookmarks'
200
+ # def render_show_doc_actions(document=@document, options={})
201
+ # content_tag("div", :class=>"documentFunctions") do
202
+ # raw("#{render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options))}
203
+ # #{render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))}")
204
+ # end
205
+ # end
206
+ #
207
+ # # used in the catalog/_index_partials/_default view
208
+ # def index_field_names
209
+ # Blacklight.config[:index_fields][:field_names]
210
+ # end
211
+ #
212
+ # # used in the _index_partials/_default view
213
+ # def index_field_labels
214
+ # Blacklight.config[:index_fields][:labels]
215
+ # end
216
+ #
217
+ # def spell_check_max
218
+ # Blacklight.config[:spell_max] || 0
219
+ # end
220
+ #
221
+ # def render_index_field_label args
222
+ # field = args[:field]
223
+ # html_escape index_field_labels[field]
224
+ # end
225
+ #
226
+ # def render_index_field_value args
227
+ # value = args[:value]
228
+ # value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
229
+ # render_field_value value
230
+ # end
231
+ #
232
+ # # Used in the show view for displaying the main solr document heading
233
+ # def document_heading
234
+ # @document[Blacklight.config[:show][:heading]] || @document.id
235
+ # end
236
+ # def render_document_heading
237
+ # content_tag(:h1, document_heading)
238
+ # end
239
+ #
240
+ # # Used in the show view for setting the main html document title
241
+ # def document_show_html_title
242
+ # @document[Blacklight.config[:show][:html_title]]
243
+ # end
244
+ #
245
+ # # Used in citation view for displaying the title
246
+ # def citation_title(document)
247
+ # document[Blacklight.config[:show][:html_title]]
248
+ # end
249
+ #
250
+ # # Used in the document_list partial (search view) for building a select element
251
+ # def sort_fields
252
+ # Blacklight.config[:sort_fields]
253
+ # end
254
+ #
255
+ # # Used in the document list partial (search view) for creating a link to the document show action
256
+ # def document_show_link_field
257
+ # Blacklight.config[:index][:show_link].to_sym
258
+ # end
259
+ #
260
+ # # Used in the search form partial for building a select tag
261
+ # def search_fields
262
+ # Blacklight.search_field_options_for_select
263
+ # end
264
+ #
265
+ # # used in the catalog/_show/_default partial
266
+ # def document_show_fields
267
+ # Blacklight.config[:show_fields][:field_names]
268
+ # end
269
+ #
270
+ # # used in the catalog/_show/_default partial
271
+ # def document_show_field_labels
272
+ # Blacklight.config[:show_fields][:labels]
273
+ # end
274
+ #
275
+ # def render_document_show_field_label args
276
+ # field = args[:field]
277
+ # html_escape document_show_field_labels[field]
278
+ # end
279
+ #
280
+ # def render_document_show_field_value args
281
+ # value = args[:value]
282
+ # value ||= args[:document].get(args[:field], :sep => nil) if args[:document] and args[:field]
283
+ # render_field_value value
284
+ # end
285
+ #
286
+ # def render_field_value value=nil
287
+ # value = [value] unless value.is_a? Array
288
+ # value = value.collect { |x| x.respond_to?(:force_encoding) ? x.force_encoding("UTF-8") : x}
289
+ # return value.map { |v| html_escape v }.join(field_value_separator).html_safe
290
+ # end
291
+ #
292
+ # def field_value_separator
293
+ # ', '
294
+ # end
295
+ #
296
+ # # Return a normalized partial name that can be used to contruct view partial path
297
+ # def document_partial_name(document)
298
+ # # .to_s is necessary otherwise the default return value is not always a string
299
+ # # using "_" as sep. to more closely follow the views file naming conventions
300
+ # # parameterize uses "-" as the default sep. which throws errors
301
+ # display_type = document[Blacklight.config[:show][:display_type]]
302
+ #
303
+ # return 'default' unless display_type
304
+ # display_type = display_type.join(" ") if display_type.respond_to?(:join)
305
+ #
306
+ # "#{display_type.gsub("-"," ")}".parameterize("_").to_s
307
+ # end
308
+ #
309
+ # # given a doc and action_name, this method attempts to render a partial template
310
+ # # based on the value of doc[:format]
311
+ # # if this value is blank (nil/empty) the "default" is used
312
+ # # if the partial is not found, the "default" partial is rendered instead
313
+ # def render_document_partial(doc, action_name)
314
+ # format = document_partial_name(doc)
315
+ # begin
316
+ # render :partial=>"catalog/_#{action_name}_partials/#{format}", :locals=>{:document=>doc}
317
+ # rescue ActionView::MissingTemplate
318
+ # render :partial=>"catalog/_#{action_name}_partials/default", :locals=>{:document=>doc}
319
+ # end
320
+ # end
321
+ #
322
+ # # Search History and Saved Searches display
323
+ # def link_to_previous_search(params)
324
+ # link_to(raw(render_search_to_s(params)), catalog_index_path(params)).html_safe
325
+ # end
326
+ #
327
+ # #
328
+ # # facet param helpers ->
329
+ # #
330
+ #
331
+ # # Standard display of a facet value in a list. Used in both _facets sidebar
332
+ # # partial and catalog/facet expanded list. Will output facet value name as
333
+ # # a link to add that to your restrictions, with count in parens.
334
+ # # first arg item is a facet value item from rsolr-ext.
335
+ # # options consist of:
336
+ # # :suppress_link => true # do not make it a link, used for an already selected value for instance
337
+ # def render_facet_value(facet_solr_field, item, options ={})
338
+ # (link_to_unless(options[:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits)).html_safe
339
+ # end
340
+ #
341
+ # # Standard display of a SELECTED facet value, no link, special span
342
+ # # with class, and 'remove' button.
343
+ # def render_selected_facet_value(facet_solr_field, item)
344
+ # content_tag(:span, render_facet_value(facet_solr_field, item, :suppress_link => true), :class => "selected label") +
345
+ # link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove")
346
+ # end
347
+ #
348
+ # # Renders a count value for facet limits. Can be over-ridden locally
349
+ # # to change style, for instance not use parens. And can be called
350
+ # # by plugins to get consistent display.
351
+ # def render_facet_count(num)
352
+ # content_tag("span", "(" + format_num(num) + ")", :class => "count")
353
+ # end
354
+ #
355
+ # # adds the value and/or field to params[:f]
356
+ # # Does NOT remove request keys and otherwise ensure that the hash
357
+ # # is suitable for a redirect. See
358
+ # # add_facet_params_and_redirect
359
+ # def add_facet_params(field, value)
360
+ # p = params.dup
361
+ # p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
362
+ # p[:f][field] = (p[:f][field] || []).dup
363
+ # p[:f][field].push(value)
364
+ # p
365
+ # end
366
+ #
367
+ # # Used in catalog/facet action, facets.rb view, for a click
368
+ # # on a facet value. Add on the facet params to existing
369
+ # # search constraints. Remove any paginator-specific request
370
+ # # params, or other request params that should be removed
371
+ # # for a 'fresh' display.
372
+ # # Change the action to 'index' to send them back to
373
+ # # catalog/index with their new facet choice.
374
+ # def add_facet_params_and_redirect(field, value)
375
+ # new_params = add_facet_params(field, value)
376
+ #
377
+ # # Delete page, if needed.
378
+ # new_params.delete(:page)
379
+ #
380
+ # # Delete any request params from facet-specific action, needed
381
+ # # to redir to index action properly.
382
+ # Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key|
383
+ # new_params.delete(paginator_key)
384
+ # end
385
+ # new_params.delete(:id)
386
+ #
387
+ # # Force action to be index.
388
+ # new_params[:action] = "index"
389
+ # new_params
390
+ # end
391
+ # # copies the current params (or whatever is passed in as the 3rd arg)
392
+ # # removes the field value from params[:f]
393
+ # # removes the field if there are no more values in params[:f][field]
394
+ # # removes additional params (page, id, etc..)
395
+ # def remove_facet_params(field, value, source_params=params)
396
+ # p = source_params.dup
397
+ # # need to dup the facet values too,
398
+ # # if the values aren't dup'd, then the values
399
+ # # from the session will get remove in the show view...
400
+ # p[:f] = p[:f].dup
401
+ # p[:f][field] = p[:f][field].nil? ? [] : p[:f][field].dup
402
+ # p.delete :page
403
+ # p.delete :id
404
+ # p.delete :counter
405
+ # p.delete :commit
406
+ # #return p unless p[field]
407
+ # p[:f][field] = p[:f][field] - [value]
408
+ # p[:f].delete(field) if p[:f][field].size == 0
409
+ # p
410
+ # end
411
+ #
412
+ # # true or false, depending on whether the field and value is in params[:f]
413
+ # def facet_in_params?(field, value)
414
+ # params[:f] and params[:f][field] and params[:f][field].include?(value)
415
+ # end
416
+ #
417
+ # #
418
+ # # shortcut for built-in Rails helper, "number_with_delimiter"
419
+ # #
420
+ # def format_num(num); number_with_delimiter(num) end
421
+ #
422
+ # #
423
+ # # link based helpers ->
424
+ # #
425
+ #
426
+ # # create link to query (e.g. spelling suggestion)
427
+ # def link_to_query(query)
428
+ # p = params.dup
429
+ # p.delete :page
430
+ # p.delete :action
431
+ # p[:q]=query
432
+ # link_url = catalog_index_path(p)
433
+ # link_to(query, link_url)
434
+ # end
435
+ #
436
+ # def render_document_index_label doc, opts
437
+ # label = nil
438
+ # label ||= doc.get(opts[:label]) if opts[:label].instance_of? Symbol
439
+ # label ||= opts[:label].call(doc, opts) if opts[:label].instance_of? Proc
440
+ # label ||= opts[:label] if opts[:label].is_a? String
441
+ # label ||= doc.id
442
+ # end
443
+ #
444
+ # # link_to_document(doc, :label=>'VIEW', :counter => 3)
445
+ # # Use the catalog_path RESTful route to create a link to the show page for a specific item.
446
+ # # catalog_path accepts a HashWithIndifferentAccess object. The solr query params are stored in the session,
447
+ # # so we only need the +counter+ param here. We also need to know if we are viewing to document as part of search results.
448
+ # def link_to_document(doc, opts={:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil, :results_view => true})
449
+ # label = render_document_index_label doc, opts
450
+ # link_to_with_data(label, catalog_path(doc.id), {:method => :put, :class => label.parameterize, :data => opts}).html_safe
451
+ # end
452
+ #
453
+ # # link_back_to_catalog(:label=>'Back to Search')
454
+ # # Create a link back to the index screen, keeping the user's facet, query and paging choices intact by using session.
455
+ # def link_back_to_catalog(opts={:label=>'Back to Search'})
456
+ # query_params = session[:search] ? session[:search].dup : {}
457
+ # query_params.delete :counter
458
+ # query_params.delete :total
459
+ # link_url = catalog_index_path + "?" + query_params.to_query
460
+ # link_to opts[:label], link_url
461
+ # end
462
+ #
463
+ # # Create form input type=hidden fields representing the entire search context,
464
+ # # for inclusion in a form meant to change some aspect of it, like
465
+ # # re-sort or change records per page. Can pass in params hash
466
+ # # as :params => hash, otherwise defaults to #params. Can pass
467
+ # # in certain top-level params keys to _omit_, defaults to :page
468
+ # def search_as_hidden_fields(options={})
469
+ #
470
+ # options = {:params => params, :omit_keys => [:page]}.merge(options)
471
+ # my_params = options[:params].dup
472
+ # options[:omit_keys].each {|omit_key| my_params.delete(omit_key)}
473
+ # # removing action and controller from duplicate params so that we don't get hidden fields for them.
474
+ # my_params.delete(:action)
475
+ # my_params.delete(:controller)
476
+ # # commit is just an artifact of submit button, we don't need it, and
477
+ # # don't want it to pile up with another every time we press submit again!
478
+ # my_params.delete(:commit)
479
+ # # hash_as_hidden_fields in hash_as_hidden_fields.rb
480
+ # return hash_as_hidden_fields(my_params)
481
+ # end
482
+ #
483
+ #
484
+ #
485
+ # def link_to_previous_document(previous_document)
486
+ # return if previous_document == nil
487
+ # link_to_document previous_document, :label=>'« Previous', :counter => session[:search][:counter].to_i - 1
488
+ # end
489
+ #
490
+ # def link_to_next_document(next_document)
491
+ # return if next_document == nil
492
+ # link_to_document next_document, :label=>'Next »', :counter => session[:search][:counter].to_i + 1
493
+ # end
494
+ #
495
+ # # Use case, you want to render an html partial from an XML (say, atom)
496
+ # # template. Rails API kind of lets us down, we need to hack Rails internals
497
+ # # a bit. code taken from:
498
+ # # http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
499
+ # def with_format(format, &block)
500
+ # old_format = @template_format
501
+ # @template_format = format
502
+ # result = block.call
503
+ # @template_format = old_format
504
+ # return result
505
+ # end
506
+ #
507
+ #
508
+ # # This is an updated +link_to+ that allows you to pass a +data+ hash along with the +html_options+
509
+ # # which are then written to the generated form for non-GET requests. The key is the form element name
510
+ # # and the value is the value:
511
+ # #
512
+ # # link_to_with_data('Name', some_path(some_id), :method => :post, :html)
513
+ # def link_to_with_data(*args, &block)
514
+ # if block_given?
515
+ # options = args.first || {}
516
+ # html_options = args.second
517
+ # concat(link_to(capture(&block), options, html_options))
518
+ # else
519
+ # name = args.first
520
+ # options = args.second || {}
521
+ # html_options = args.third
522
+ #
523
+ # url = url_for(options)
524
+ #
525
+ # if html_options
526
+ # html_options = html_options.stringify_keys
527
+ # href = html_options['href']
528
+ # convert_options_to_javascript_with_data!(html_options, url)
529
+ # tag_options = tag_options(html_options)
530
+ # else
531
+ # tag_options = nil
532
+ # end
533
+ #
534
+ # href_attr = "href=\"#{url}\"" unless href
535
+ # "<a #{href_attr}#{tag_options}>#{h(name) || h(url)}</a>".html_safe
536
+ # end
537
+ # end
538
+ #
539
+ # # This is derived from +convert_options_to_javascript+ from module +UrlHelper+ in +url_helper.rb+
540
+ # def convert_options_to_javascript_with_data!(html_options, url = '')
541
+ # confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
542
+ #
543
+ # method, href = html_options.delete("method"), html_options['href']
544
+ # data = html_options.delete("data")
545
+ # data = data.stringify_keys if data
546
+ #
547
+ # html_options["onclick"] = case
548
+ # when method
549
+ # "#{method_javascript_function_with_data(method, url, href, data)}return false;"
550
+ # else
551
+ # html_options["onclick"]
552
+ # end
553
+ # end
554
+ #
555
+ # # This is derived from +method_javascript_function+ from module +UrlHelper+ in +url_helper.rb+
556
+ # def method_javascript_function_with_data(method, url = '', href = nil, data=nil)
557
+ # action = (href && url.size > 0) ? "'#{url}'" : 'this.href'
558
+ # submit_function =
559
+ # "var f = document.createElement('form'); f.style.display = 'none'; " +
560
+ # "this.parentNode.appendChild(f); f.method = 'POST'; f.action = #{action};"+
561
+ # "if(event.metaKey || event.ctrlKey){f.target = '_blank';};" # if the command or control key is being held down while the link is clicked set the form's target to _blank
562
+ # if data
563
+ # data.each_pair do |key, value|
564
+ # submit_function << "var d = document.createElement('input'); d.setAttribute('type', 'hidden'); "
565
+ # submit_function << "d.setAttribute('name', '#{key}'); d.setAttribute('value', '#{escape_javascript(value.to_s)}'); f.appendChild(d);"
566
+ # end
567
+ # end
568
+ # unless method == :post
569
+ # submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); "
570
+ # submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);"
571
+ # end
572
+ #
573
+ # if protect_against_forgery?
574
+ # submit_function << "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); "
575
+ # submit_function << "s.setAttribute('name', '#{request_forgery_protection_token}'); s.setAttribute('value', '#{escape_javascript form_authenticity_token}'); f.appendChild(s);"
576
+ # end
577
+ # submit_function << "f.submit();"
578
+ # end
579
+ #
580
+ # # determines if the given document id is in the folder
581
+ # def item_in_folder?(doc_id)
582
+ # session[:folder_document_ids] && session[:folder_document_ids].include?(doc_id) ? true : false
583
+ # end
584
+ #
585
+ # # puts together a collection of documents into one refworks export string
586
+ # def render_refworks_texts(documents)
587
+ # val = ''
588
+ # documents.each do |doc|
589
+ # if doc.respond_to?(:to_marc)
590
+ # val += doc.export_as_refworks_marc_txt + "\n"
591
+ # end
592
+ # end
593
+ # val
594
+ # end
595
+ #
596
+ # # puts together a collection of documents into one endnote export string
597
+ # def render_endnote_texts(documents)
598
+ # val = ''
599
+ # documents.each do |doc|
600
+ # if doc.respond_to?(:to_marc)
601
+ # val += doc.export_as_endnote + "\n"
602
+ # end
603
+ # end
604
+ # val
605
+ # end
606
+ #
607
+ #
608
+ # def render_document_unapi_microformat(document, options={})
609
+ # render(:partial=>'catalog/unapi_microformat', :locals => {:document=> document}.merge(options))
610
+ # end
611
+ #
612
+ # end