Module: ApplicationHelper
- Includes:
- HashAsHiddenFields, HydraHelper, RenderConstraintsHelper, Stanford::SearchworksHelper
- Defined in:
- vendor/plugins/blacklight/app/helpers/application_helper.rb,
app/helpers/application_helper.rb,
vendor/plugins/hydra_repository/app/helpers/application_helper.rb
Overview
Methods added to this helper will be available to all templates in the application.
Instance Method Summary (collapse)
-
- (Object) add_facet_params(field, value)
adds the value and/or field to params[:f] Does NOT remove request keys and otherwise ensure that the hash is suitable for a redirect.
-
- (Object) add_facet_params_and_redirect(field, value)
Used in catalog/facet action, facets.rb view, for a click on a facet value.
- - (Object) application_name
-
- (Object) citation_title(document)
Used in citation view for displaying the title.
-
- (Object) convert_options_to_javascript_with_data!(html_options, url = '')
This is derived from convert_options_to_javascript from module UrlHelper in url_helper.rb.
-
- (Object) document_heading
Used in the show view for displaying the main solr document heading.
-
- (Object) document_partial_name(document)
currently only used by the render_document_partial helper method (below).
-
- (Object) document_show_field_labels
used in the catalog/_show/_default partial.
-
- (Object) document_show_fields
used in the catalog/_show/_default partial.
-
- (Object) document_show_html_title
Used in the show view for setting the main html document title.
-
- (Object) document_show_link_field
Used in the document list partial (search view) for creating a link to the document show action.
-
- (Object) facet_field_labels
used in the catalog/_facets partial.
-
- (Object) facet_field_names
used in the catalog/_facets partial.
-
- (Boolean) facet_in_params?(field, value)
true or false, depending on whether the field and value is in params[:f].
-
- (Object) format_num(num)
shortcut for built-in Rails helper, “number_with_delimiter”.
- - (Object) get_data_with_linked_label(doc, label, field_string, opts = {})
-
- (Object) index_field_labels
used in the _index_partials/_default view.
-
- (Object) index_field_names
used in the catalog/_index_partials/_default view.
-
- (Boolean) item_in_folder?(doc_id)
determines if the given document id is in the folder.
-
- (Object) link_back_to_catalog(opts = {:label=>'Back to Search'})
link_back_to_catalog(:label=>’Back to Search’) Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
-
- (Object) link_to_document(doc, opts = {:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil,:title => nil})
link_to_document(doc, :label=>’VIEW’, :counter => 3) Use the catalog_path RESTful route to create a link to the show page for a specific item.
- - (Object) link_to_next_document(next_document)
- - (Object) link_to_previous_document(previous_document)
-
- (Object) link_to_previous_search(params)
Search History and Saved Searches display.
-
- (Object) link_to_query(query)
create link to query (e.g. spelling suggestion).
-
- (Object) link_to_with_data(*args, &block)
This is an updated link_to that allows you to pass a data hash along with the html_options which are then written to the generated form for non-GET requests.
- - (Object) linked_label(field, field_string)
-
- (Object) method_javascript_function_with_data(method, url = '', href = nil, data = nil)
This is derived from method_javascript_function from module UrlHelper in url_helper.rb.
-
- (Object) remove_facet_params(field, value, source_params = params)
copies the current params (or whatever is passed in as the 3rd arg) removes the field value from params[:f] removes the field if there are no more values in params[:f][field] removes additional params (page, id, etc..).
- - (Object) render_body_class
- - (Object) render_document_functions_partial(document = @document, options = {})
- - (Object) render_document_heading
- - (Object) render_document_index_label(doc, opts)
- - (Object) render_document_list_partial(options = {})
-
- (Object) render_document_partial(doc, action_name, locals = {})
Overriding Blacklight’s render_document_partial given a doc and action_name, this method attempts to render a partial template based on the value of doc[:format] if this value is blank (nil/empty) the “default” is used if the partial is not found, the “default” partial is rendered instead.
- - (Object) render_document_show_field_label(args)
- - (Object) render_document_show_field_value(args)
-
- (Object) render_endnote_texts(documents)
puts together a collection of documents into one endnote export string.
-
- (Object) render_facet_count(num)
Renders a count value for facet limits.
-
- (Object) render_facet_limit(solr_field)
used in the catalog/_facets partial and elsewhere Renders a single section for facet limit with a specified solr field used for faceting.
-
- (Object) render_facet_value(facet_solr_field, item, options = {})
Standard display of a facet value in a list.
-
- (Object) render_head_content
This method should be included in any Blacklight layout, including custom ones.
- - (Object) render_index_field_label(args)
- - (Object) render_index_field_value(args)
-
- (Object) render_js_includes
Assumes controller has a #js_includes method, array with each element being a set of arguments for javsascript_include_tag.
-
- (Object) render_link_rel_alternates(document = @document, options = {})
Create links from a documents dynamically provided export formats.
-
- (Object) render_refworks_texts(documents)
puts together a collection of documents into one refworks export string.
-
- (Object) render_selected_facet_value(facet_solr_field, item)
Standard display of a SELECTED facet value, no link, special span with class, and ‘remove’ button.
-
- (Object) render_stylesheet_includes
Assumes controller has a #stylesheet_link_tag method, array with each element being a set of arguments for stylesheet_link_tag See #render_head_content for instructions on local code or plugins adding stylesheets.
-
- (Object) search_as_hidden_fields(options = {})
Create form input type=hidden fields representing the entire search context, for inclusion in a form meant to change some aspect of it, like re-sort or change records per page.
-
- (Object) search_fields
Used in the search form partial for building a select tag.
-
- (Object) sidebar_items
collection of items to be rendered in the @sidebar.
-
- (Object) sort_fields
Used in the document_list partial (search view) for building a select element.
-
- (Object) with_format(format, &block)
Use case, you want to render an html partial from an XML (say, atom) template.
Methods included from HydraHelper
#async_load_tag, #document_fedora_show_html_title, #edit_and_browse_links, #facet_value_hits, #get_html_data_with_label, #get_textile_data_with_label, #grouped_result_count, #grouping_facet, #javascript_includes, #link_to_multifacet, #stylesheet_links
Methods included from RenderConstraintsHelper
#render_constraint_element, #render_constraints, #render_constraints_filters, #render_constraints_query, #render_search_to_s, #render_search_to_s_element, #render_search_to_s_filters, #render_search_to_s_q
Methods included from HashAsHiddenFields
Instance Method Details
- (Object) add_facet_params(field, value)
adds the value and/or field to params[:f] Does NOT remove request keys and otherwise ensure that the hash is suitable for a redirect. See add_facet_params_and_redirect
308 309 310 311 312 313 314 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 308 def add_facet_params(field, value) p = params.dup p[:f]||={} p[:f][field] ||= [] p[:f][field].push(value) p end |
- (Object) add_facet_params_and_redirect(field, value)
Used in catalog/facet action, facets.rb view, for a click on a facet value. Add on the facet params to existing search constraints. Remove any paginator-specific request params, or other request params that should be removed for a ‘fresh’ display. Change the action to ‘index’ to send them back to catalog/index with their new facet choice.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 323 def add_facet_params_and_redirect(field, value) new_params = add_facet_params(field, value) # Delete page, if needed. new_params.delete(:page) # Delete any request params from facet-specific action, needed # to redir to index action properly. Blacklight::Solr::FacetPaginator.request_keys.values.each do |paginator_key| new_params.delete(paginator_key) end new_params.delete(:id) # Force action to be index. new_params[:action] = "index" new_params end |
- (Object) application_name
9 10 11 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 9 def application_name 'Hydrangea (Hydra Demo App)' end |
- (Object) citation_title(document)
Used in citation view for displaying the title
209 210 211 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 209 def citation_title(document) document[Blacklight.config[:show][:html_title]] end |
- (Object) convert_options_to_javascript_with_data!(html_options, url = '')
This is derived from convert_options_to_javascript from module UrlHelper in url_helper.rb
486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 486 def (, url = '') confirm, popup = .delete("confirm"), .delete("popup") method, href = .delete("method"), ['href'] data = .delete("data") data = data.stringify_keys if data ["onclick"] = case when method "#{method_javascript_function_with_data(method, url, href, data)}return false;" else ["onclick"] end end |
- (Object) document_heading
Used in the show view for displaying the main solr document heading
196 197 198 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 196 def document_heading @document[Blacklight.config[:show][:heading]] end |
- (Object) document_partial_name(document)
currently only used by the render_document_partial helper method (below)
251 252 253 254 255 256 257 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 251 def document_partial_name(document) if !document[Blacklight.config[:show][:display_type]].nil? return document[Blacklight.config[:show][:display_type]].first.gsub("info:fedora/afmodel:","").underscore.pluralize else return nil end end |
- (Object) document_show_field_labels
used in the catalog/_show/_default partial
234 235 236 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 234 def document_show_field_labels Blacklight.config[:show_fields][:labels] end |
- (Object) document_show_fields
used in the catalog/_show/_default partial
229 230 231 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 229 def document_show_fields Blacklight.config[:show_fields][:field_names] end |
- (Object) document_show_html_title
Used in the show view for setting the main html document title
204 205 206 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 204 def document_show_html_title @document[Blacklight.config[:show][:html_title]] end |
- (Object) document_show_link_field
Used in the document list partial (search view) for creating a link to the document show action
219 220 221 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 219 def document_show_link_field Blacklight.config[:index][:show_link].to_sym end |
- (Object) facet_field_labels
used in the catalog/_facets partial
149 150 151 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 149 def facet_field_labels Blacklight.config[:facet][:labels] end |
- (Object) facet_field_names
used in the catalog/_facets partial
154 155 156 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 154 def facet_field_names Blacklight.config[:facet][:field_names] end |
- (Boolean) facet_in_params?(field, value)
true or false, depending on whether the field and value is in params[:f]
362 363 364 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 362 def facet_in_params?(field, value) params[:f] and params[:f][field] and params[:f][field].include?(value) end |
- (Object) format_num(num)
shortcut for built-in Rails helper, “number_with_delimiter“
369 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 369 def format_num(num) number_with_delimiter(num) end |
- (Object) get_data_with_linked_label(doc, label, field_string, opts = {})
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'vendor/plugins/hydra_repository/app/helpers/application_helper.rb', line 10 def get_data_with_linked_label(doc, label, field_string, opts={}) (opts[:default] and !doc[field_string]) ? field = opts[:default] : field = doc[field_string] delim = opts[:delimiter] ? opts[:delimiter] : "<br/>" if doc[field_string] text = "<dt>#{label}</dt><dd>" if field.respond_to?(:each) text += field.map do |l| linked_label(l, field_string) end.join(delim) else text += linked_label(field, field_string) end text += "</dd>" text end end |
- (Object) index_field_labels
used in the _index_partials/_default view
180 181 182 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 180 def index_field_labels Blacklight.config[:index_fields][:labels] end |
- (Object) index_field_names
used in the catalog/_index_partials/_default view
175 176 177 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 175 def index_field_names Blacklight.config[:index_fields][:field_names] end |
- (Boolean) item_in_folder?(doc_id)
determines if the given document id is in the folder
527 528 529 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 527 def item_in_folder?(doc_id) session[:folder_document_ids] && session[:folder_document_ids].include?(doc_id) ? true : false end |
- (Object) link_back_to_catalog(opts = {:label=>'Back to Search'})
link_back_to_catalog(:label=>’Back to Search’) Create a link back to the index screen, keeping the user’s facet, query and paging choices intact by using session.
404 405 406 407 408 409 410 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 404 def link_back_to_catalog(opts={:label=>'Back to Search'}) query_params = session[:search] ? session[:search].dup : {} query_params.delete :counter query_params.delete :total link_url = catalog_index_path(query_params) link_to opts[:label], link_url end |
- (Object) link_to_document(doc, opts = {:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil,:title => nil})
link_to_document(doc, :label=>’VIEW’, :counter => 3) Use the catalog_path RESTful route to create a link to the show page for a specific item. catalog_path accepts a HashWithIndifferentAccess object. The solr query params are stored in the session, so we only need the counter param here. We also need to know if we are viewing to document as part of search results.
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 397 def link_to_document(doc, opts={:label=>Blacklight.config[:index][:show_link].to_sym, :counter => nil,:title => nil}) label = case opts[:label] when Symbol doc.get(opts[:label]) when String opts[:label] else raise 'Invalid label argument' end if label.blank? label = doc[:id] end link_to_with_data(label, catalog_path(doc[:id]), {:method => :put, :data => {:counter => opts[:counter]},:title=>opts[:title]}) end |
- (Object) link_to_next_document(next_document)
436 437 438 439 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 436 def link_to_next_document(next_document) return if next_document == nil link_to_document next_document, :label=>'Next »', :counter => session[:search][:counter].to_i + 1 end |
- (Object) link_to_previous_document(previous_document)
431 432 433 434 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 431 def link_to_previous_document(previous_document) return if previous_document == nil link_to_document previous_document, :label=>'« Previous', :counter => session[:search][:counter].to_i - 1 end |
- (Object) link_to_previous_search(params)
Search History and Saved Searches display
269 270 271 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 269 def link_to_previous_search(params) link_to(render_search_to_s(params), catalog_index_path(params)) end |
- (Object) link_to_query(query)
create link to query (e.g. spelling suggestion)
376 377 378 379 380 381 382 383 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 376 def link_to_query(query) p = params.dup p.delete :page p.delete :action p[:q]=query link_url = catalog_index_path(p) link_to(query, link_url) end |
- (Object) link_to_with_data(*args, &block)
This is an updated link_to that allows you to pass a data hash along with the html_options which are then written to the generated form for non-GET requests. The key is the form element name and the value is the value:
link_to_with_data('Name', some_path(some_id), :method => :post, :html)
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 459 def link_to_with_data(*args, &block) if block_given? = args.first || {} = args.second concat(link_to(capture(&block), , )) else name = args.first = args.second || {} = args.third url = url_for() if = .stringify_keys href = ['href'] (, url) = () else = nil end href_attr = "href=\"#{url}\"" unless href "<a #{href_attr}#{tag_options}>#{h(name) || h(url)}</a>" end end |
- (Object) linked_label(field, field_string)
28 29 30 |
# File 'vendor/plugins/hydra_repository/app/helpers/application_helper.rb', line 28 def linked_label(field, field_string) link_to(field, add_facet_params(field_string, field).merge!({"controller" => "catalog", :action=> "index"})) end |
- (Object) method_javascript_function_with_data(method, url = '', href = nil, data = nil)
This is derived from method_javascript_function from module UrlHelper in url_helper.rb
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 502 def method_javascript_function_with_data(method, url = '', href = nil, data=nil) action = (href && url.size > 0) ? "'#{url}'" : 'this.href' submit_function = "var f = document.createElement('form'); f.style.display = 'none'; " + "this.parentNode.appendChild(f); f.method = 'POST'; f.action = #{action};"+ "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 if data data.each_pair do |key, value| submit_function << "var d = document.createElement('input'); d.setAttribute('type', 'hidden'); " submit_function << "d.setAttribute('name', '#{key}'); d.setAttribute('value', '#{value}'); f.appendChild(d);" end end unless method == :post submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); " submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);" end if protect_against_forgery? submit_function << "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); " submit_function << "s.setAttribute('name', '#{request_forgery_protection_token}'); s.setAttribute('value', '#{escape_javascript form_authenticity_token}'); f.appendChild(s);" end submit_function << "f.submit();" end |
- (Object) remove_facet_params(field, value, source_params = params)
copies the current params (or whatever is passed in as the 3rd arg) removes the field value from params[:f] removes the field if there are no more values in params[:f][field] removes additional params (page, id, etc..)
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 345 def remove_facet_params(field, value, source_params=params) p = source_params.dup.symbolize_keys! # need to dup the facet values too, # if the values aren't dup'd, then the values # from the session will get remove in the show view... p[:f] = p[:f].dup.symbolize_keys! p.delete :page p.delete :id p.delete :counter p.delete :commit #return p unless p[field] p[:f][field] = p[:f][field] - [value] p[:f].delete(field) if p[:f][field].size == 0 p end |
- (Object) render_body_class
135 136 137 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 135 def render_body_class ['blacklight-' + @controller.controller_name, 'blacklight-' + [@controller.controller_name, @controller.action_name].join('-')].join " " end |
- (Object) render_document_functions_partial(document = @document, options = {})
170 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 170 def render_document_functions_partial document=@document, ={} |
- (Object) render_document_heading
199 200 201 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 199 def render_document_heading '<h1>' + document_heading + '</h1>' end |
- (Object) render_document_index_label(doc, opts)
385 386 387 388 389 390 391 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 385 def render_document_index_label doc, opts label = nil label ||= doc.get(opts[:label]) if opts[:label].instance_of? Symbol label ||= opts[:label] if opts[:label].instance_of? String label ||= opts[:label].call(doc, opts) if opts[:label].instance_of? Proc label ||= doc.id end |
- (Object) render_document_list_partial(options = {})
166 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 166 def render_document_list_partial ={} |
- (Object) render_document_partial(doc, action_name, locals = {})
Overriding Blacklight’s render_document_partial given a doc and action_name, this method attempts to render a partial template based on the value of doc[:format] if this value is blank (nil/empty) the “default” is used if the partial is not found, the “default” partial is rendered instead
259 260 261 262 263 264 265 266 267 268 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 259 def render_document_partial(doc, action_name, locals={}) format = document_partial_name(doc) begin Rails.logger.debug("attempting to render #{format}/_#{action_name}") render :partial=>"#{format}/#{action_name}", :locals=>{:document=>doc}.merge(locals) rescue ActionView::MissingTemplate Rails.logger.debug("rendering default partial catalog/_#{action_name}_partials/default") render :partial=>"catalog/_#{action_name}_partials/default", :locals=>{:document=>doc}.merge(locals) end end |
- (Object) render_document_show_field_label(args)
238 239 240 241 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 238 def render_document_show_field_label args field = args[:field] html_escape document_show_field_labels[field] end |
- (Object) render_document_show_field_value(args)
243 244 245 246 247 248 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 243 def render_document_show_field_value args value = args[:value] value ||= args[:document].get(args[:field]) if args[:document] and args[:field] return value.map { |v| html_escape v }.join "<br />" if value.is_a? Array html_escape value end |
- (Object) render_endnote_texts(documents)
puts together a collection of documents into one endnote export string
543 544 545 546 547 548 549 550 551 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 543 def render_endnote_texts(documents) val = '' documents.each do |doc| if doc.respond_to?(:to_marc) val += doc.export_as_endnote + "\n" end end val end |
- (Object) render_facet_count(num)
Renders a count value for facet limits. Can be over-ridden locally to change style, for instance not use parens. And can be called by plugins to get consistent display.
300 301 302 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 300 def render_facet_count(num) content_tag("span", "(" + format_num(num) + ")", :class => "count") end |
- (Object) render_facet_limit(solr_field)
used in the catalog/_facets partial and elsewhere Renders a single section for facet limit with a specified solr field used for faceting. Can be over-ridden for custom display on a per-facet basis.
162 163 164 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 162 def render_facet_limit(solr_field) render( :partial => "catalog/facet_limit", :locals => {:solr_field =>solr_field }) end |
- (Object) render_facet_value(facet_solr_field, item, options = {})
Standard display of a facet value in a list. Used in both _facets sidebar partial and catalog/facet expanded list. Will output facet value name as a link to add that to your restrictions, with count in parens. first arg item is a facet value item from rsolr-ext. options consist of: :suppress_link => true # do not make it a link, used for an already selected value for instance
284 285 286 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 284 def render_facet_value(facet_solr_field, item, ={}) link_to_unless([:suppress_link], item.value, add_facet_params_and_redirect(facet_solr_field, item.value), :class=>"facet_select label") + " " + render_facet_count(item.hits) end |
- (Object) render_head_content
This method should be included in any Blacklight layout, including custom ones. It will output results of #render_js_includes, #render_stylesheet_includes, and all the content of current_controller#extra_head_content.
Uses controller methods #extra_head_content, #javascript_includes, and #stylesheet_links to find content. Tolerates it if those methods don’t exist, silently skipping.
By a layout outputting this in html HEAD, it provides an easy way for local config or extra plugins to add HEAD content.
Add your own css or remove the defaults by simply editing controller.stylesheet_links, controller.javascript_includes, or controller.extra_head_content.
in an initializer or other startup file (plugin init.rb?):
Apply to all actions in all controllers:
ApplicationController.before_filter do |controller| # remove default jquery-ui theme. controller.stylesheet_links.each do |args| args.delete_if {|a| a =~ /^|\/jquery-ui-[\d.]+\.custom\.css$/ } end # add in a different jquery-ui theme, or any other css or what have you controller.stylesheet_links << 'my_css.css' controller.javascript_includes << "my_local_behaviors.js" controller.extra_head_content << '<link rel="something" href="something">' end
Apply to a particular action in a particular controller:
CatalogController.before_filter :only => :show |controller| controller.extra_head_content << '<link rel="something" href="something">' end
Or in a view file that wants to add certain header content? no problem:
<% stylesheet_links << "mystylesheet.css" %> <% javascript_includes << "my_js.js" %> <% extra_head_content << capture do %> <%= tag :link, { :href => some_method_for_something, :rel => "alternate" } %> <% end %>
Full power of javascript_include_tag and stylesheet_link_tag
Note that the elements added to stylesheet_links and javascript_links are arguments to Rails javascript_include_tag and stylesheet_link_tag respectively, you can pass complex arguments. eg:
stylesheet_links << [“stylesheet1.css”, “stylesheet2.css”, => “mykey”] javascript_includes << [“myjavascript.js”, {:plugin => :myplugin} ]
71 72 73 74 75 76 77 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 71 def render_head_content render_stylesheet_includes + render_js_includes + ( respond_to?(:extra_head_content) ? extra_head_content.join("\n") : "") end |
- (Object) render_index_field_label(args)
184 185 186 187 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 184 def render_index_field_label args field = args[:field] html_escape index_field_labels[field] end |
- (Object) render_index_field_value(args)
189 190 191 192 193 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 189 def render_index_field_value args value = args[:value] value ||= args[:document].get(args[:field]) if args[:document] and args[:field] html_escape value end |
- (Object) render_js_includes
Assumes controller has a #js_includes method, array with each element being a set of arguments for javsascript_include_tag. See #render_head_content for instructions on local code or plugins adding js files.
98 99 100 101 102 103 104 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 98 def render_js_includes return "" unless respond_to?(:javascript_includes) javascript_includes.collect do |args| javascript_include_tag(*args) end.join("\n") end |
- (Object) render_link_rel_alternates(document = @document, options = {})
Create links from a documents dynamically provided export formats. Currently not used by standard BL layouts, but available for your custom layouts to provide link rel alternates.
Returns empty string if no links available.
:unique => true, will ensure only one link is output for every content type, as required eg in atom. Which one ‘wins’ is arbitrary. :exclude => array of format shortnames, formats to not include at all.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 115 def render_link_rel_alternates(document=@document, = {}) = {:unique => false, :exclude => []}.merge() return nil if document.nil? seen = Set.new html = "" document.export_formats.each_pair do |format, spec| unless( [:exclude].include?(format) || ([:unique] && seen.include?(spec[:content_type])) ) html << tag(:link, {:rel=>"alternate", :title=>format, :type => spec[:content_type], :href=> catalog_url(document[:id], format)}) << "\n" seen.add(spec[:content_type]) if [:unique] end end return html end |
- (Object) render_refworks_texts(documents)
puts together a collection of documents into one refworks export string
532 533 534 535 536 537 538 539 540 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 532 def render_refworks_texts(documents) val = '' documents.each do |doc| if doc.respond_to?(:to_marc) val += doc.export_as_refworks_marc_txt + "\n" end end val end |
- (Object) render_selected_facet_value(facet_solr_field, item)
Standard display of a SELECTED facet value, no link, special span with class, and ‘remove’ button.
290 291 292 293 294 295 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 290 def render_selected_facet_value(facet_solr_field, item) '<span class="selected label">' + render_facet_value(facet_solr_field, item, :suppress_link => true) + '</span>' + link_to("[remove]", remove_facet_params(facet_solr_field, item.value, params), :class=>"remove") end |
- (Object) render_stylesheet_includes
Assumes controller has a #stylesheet_link_tag method, array with each element being a set of arguments for stylesheet_link_tag See #render_head_content for instructions on local code or plugins adding stylesheets.
84 85 86 87 88 89 90 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 84 def render_stylesheet_includes return "" unless respond_to?(:stylesheet_links) stylesheet_links.collect do |args| stylesheet_link_tag(*args) end.join("\n") end |
Create form input type=hidden fields representing the entire search context, for inclusion in a form meant to change some aspect of it, like re-sort or change records per page. Can pass in params hash as :params => hash, otherwise defaults to #params. Can pass in certain top-level params keys to omit, defaults to :page
417 418 419 420 421 422 423 424 425 426 427 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 417 def search_as_hidden_fields(={}) = {:params => params, :omit_keys => [:page]}.merge() my_params = [:params].dup [:omit_keys].each {|omit_key| my_params.delete(omit_key)} # removing action and controller from duplicate params so that we don't get hidden fields for them. my_params.delete(:action) my_params.delete(:controller) # hash_as_hidden_fields in hash_as_hidden_fields.rb return hash_as_hidden_fields(my_params) end |
- (Object) search_fields
Used in the search form partial for building a select tag
224 225 226 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 224 def search_fields Blacklight. end |
- (Object) sidebar_items
collection of items to be rendered in the @sidebar
140 141 142 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 140 def ||= [] end |
- (Object) sort_fields
Used in the document_list partial (search view) for building a select element
214 215 216 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 214 def sort_fields Blacklight.config[:sort_fields] end |
- (Object) with_format(format, &block)
Use case, you want to render an html partial from an XML (say, atom) template. Rails API kind of lets us down, we need to hack Rails internals a bit. code taken from: stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails
445 446 447 448 449 450 451 |
# File 'vendor/plugins/blacklight/app/helpers/application_helper.rb', line 445 def with_format(format, &block) old_format = @template_format @template_format = format result = block.call @template_format = old_format return result end |