Skip to content

Commit

Permalink
Use pipeline configuration to simplify the pipeline
Browse files Browse the repository at this point in the history
Rather than mutating the options passed to the pipeline.
  • Loading branch information
jcoyne committed Oct 30, 2018
1 parent 9200f7e commit ceb8d6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions app/presenters/blacklight/field_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
module Blacklight
# Renders a field and handles link_to_facet or helper_method if supplied
class FieldPresenter
# @param controller [Object] the context in which to execute helper methods
# @param document [SolrDocument] the document
# @param field_config [Blacklight::Configuration::Field] the field's configuration
# @param options [Hash]
# @option options [Object] :value when this is provided, we don't want the pipeline to deal with helper methods.
# this happens when drawing the label for the document
def initialize(controller, document, field_config, options)
@controller = controller
@document = document
Expand All @@ -13,15 +19,11 @@ def initialize(controller, document, field_config, options)
attr_reader :controller, :document, :field_config, :options

def render
if options[:value]
# This prevents helper methods from drawing.
config = Configuration::NullField.new(field_config.to_h.except(:helper_method))
values = Array.wrap(options[:value])
else
config = field_config
values = retrieve_values
end
Rendering::Pipeline.render(values, config, document, controller, options)
return Rendering::Pipeline.render(retrieve_values, field_config, document, controller, options) unless options[:value]
values = Array.wrap(options[:value])
# Prevents helper methods from drawing.
steps = Rendering::Pipeline.operations - [Rendering::HelperMethod]
Rendering::Pipeline.new(values, field_config, document, controller, steps, options).render
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/blacklight/index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def initialize(document, view_context, configuration = view_context.blacklight_c
end

##
# Render the document index heading
# Render the document index heading. This is used when making a link to a
# document, where we don't want any HTML markup added from the pipeline.
#
# @param [Symbol, Proc, String] field_or_string_or_proc Render the given field or evaluate the proc or render the given string
# @param [Hash] opts
Expand Down

0 comments on commit ceb8d6d

Please sign in to comment.