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 Nov 13, 2018
1 parent 2363bb3 commit 285b7a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
21 changes: 12 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,12 @@ 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
4 changes: 2 additions & 2 deletions app/presenters/blacklight/rendering/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
module Rendering
# The field rendering pipeline.
# This takes a field and it's values and transforms them through a list of
# This takes a field and its values and transforms them through a list of
# operations.
class Pipeline
class_attribute :operations, instance_accessor: false
Expand All @@ -14,7 +14,7 @@ class Pipeline
# @param values [Array] the values for the field
# @param config [Blacklight::Configuration::Field] the field's configuration
# @param document [SolrDocument] the document
# @param context [Object] an execution context, used to execute the helper method in.
# @param context [Object] an execution context, used to execute the helper method in.
# @param operations [Array<Class>] the list of operations in this Pipeline
# @param options [Hash] options to pass to the processors. Typically only `:value` is used
def initialize(values, config, document, context, operations, options)
Expand Down

0 comments on commit 285b7a6

Please sign in to comment.