Module: Blacklight::ComponentHelperBehavior

Included in:
ComponentHelper
Defined in:
app/helpers/blacklight/component_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#document_action_label(action, opts) ⇒ Object



4
5
6
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 4

def document_action_label action, opts
  t("blacklight.tools.#{action}", default: opts.label || action.to_s.humanize)
end

#document_action_path(action_opts, url_opts = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 8

def document_action_path action_opts, url_opts = nil
  if action_opts.path
    self.send(action_opts.path, url_opts)
  elsif url_opts[:id].class.respond_to?(:model_name)
    url_for([action_opts.key, url_opts[:id]])
  else
    self.send("#{action_opts.key}_#{controller_name}_path", url_opts)
  end
end

#render_filtered_partials(partials, options = {}, &block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 57

def render_filtered_partials(partials, options={}, &block)
  content = []
  filter_partials(partials, options).each do |key, config|
    config.key ||= key
    rendered = render(partial: config.partial || key.to_s, locals: { document_action_config: config }.merge(options))
    if block_given?
      yield config, rendered
    else
      content << rendered
    end
  end
  safe_join(content, "\n") unless block_given?
end

#render_index_doc_actions(document, options = {}) ⇒ String

Render “document actions” area for search results view (normally renders next to title in the list view)

Parameters:

Options Hash (options):

  • :wrapping_class (String)

Returns:

  • (String)


38
39
40
41
42
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 38

def render_index_doc_actions(document, options={})
  wrapping_class = options.delete(:wrapping_class) || "index-document-functions"
  rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).document_actions, { document: document }.merge(options))
  ("div", rendered, class: wrapping_class) unless rendered.blank?
end

#render_nav_actions(options = {}, &block) ⇒ String

Render “document actions” area for navigation header (normally renders “Saved Searches”, “History”, “Bookmarks”) These things are added by add_nav_action and the default config is provided by DefaultComponentConfiguration

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (String)


26
27
28
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 26

def render_nav_actions(options={}, &block)
  render_filtered_partials(blacklight_config.navbar.partials, options, &block)
end

#render_results_collection_tools(options = {}) ⇒ String

Render “collection actions” area for search results view (normally renders next to pagination at the top of the result set)

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :wrapping_class (String)

Returns:

  • (String)


51
52
53
54
55
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 51

def render_results_collection_tools(options = {})
  wrapping_class = options.delete(:wrapping_class) || "search-widgets"
  rendered = render_filtered_partials(blacklight_config.view_config(document_index_view_type).collection_actions, options)
  ("div", rendered, class: wrapping_class) unless rendered.blank?
end

#render_show_doc_actions(document = @document, options = {}, &block) ⇒ String

Render “document actions” for the item detail 'show' view. (this normally renders next to title)

By default includes 'Bookmarks'

Parameters:

  • document (SolrDocument) (defaults to: @document)
  • options (Hash) (defaults to: {})

Returns:

  • (String)


80
81
82
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 80

def render_show_doc_actions(document=@document, options={}, &block)
  render_filtered_partials(blacklight_config.show.document_actions, { document: document }.merge(options), &block)
end

#show_doc_actions?(document = @document, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/helpers/blacklight/component_helper_behavior.rb', line 84

def show_doc_actions?(document = @document, options = {})
  filter_partials(blacklight_config.show.document_actions, { document: document }.merge(options)).any?
end