From 9ce262bfd7c5f31c8ee7e3bca12a1c7a63adba5e Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 6 Jul 2016 16:48:01 -0700 Subject: [PATCH] Rename presenter controller argument to view_context; fixes #1328 --- app/presenters/blacklight/index_presenter.rb | 18 ++++++++------- app/presenters/blacklight/show_presenter.rb | 24 +++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/presenters/blacklight/index_presenter.rb b/app/presenters/blacklight/index_presenter.rb index 357235dc02..f68114520c 100644 --- a/app/presenters/blacklight/index_presenter.rb +++ b/app/presenters/blacklight/index_presenter.rb @@ -1,13 +1,15 @@ # frozen_string_literal: true module Blacklight class IndexPresenter + attr_reader :document, :configuration, :view_context + # @param [SolrDocument] document - # @param [ActionController::Base] controller scope for linking and generating urls + # @param [ActionView::Base] view context scope for linking and generating urls # @param [Blacklight::Configuration] configuration - def initialize(document, controller, configuration = controller.blacklight_config) + def initialize(document, view_context, configuration = view_context.blacklight_config) @document = document + @view_context = view_context @configuration = configuration - @controller = controller end ## @@ -21,14 +23,14 @@ def label(field_or_string_or_proc, opts = {}) value = case field_or_string_or_proc when Symbol config = field_config(field_or_string_or_proc) - @document[field_or_string_or_proc] + document[field_or_string_or_proc] when Proc - field_or_string_or_proc.call(@document, opts) + field_or_string_or_proc.call(document, opts) when String field_or_string_or_proc end - value ||= @document.id + value ||= document.id field_values(config, value: value) end @@ -59,11 +61,11 @@ def field_value field, options = {} # @param [Blacklight::Configuration::Field] solr field configuration # @param [Hash] options additional options to pass to the rendering helpers def field_values(field_config, options={}) - FieldPresenter.new(@controller, @document, field_config, options).render + FieldPresenter.new(view_context, document, field_config, options).render end def field_config(field) - @configuration.index_fields.fetch(field) { Configuration::NullField.new(field) } + configuration.index_fields.fetch(field) { Configuration::NullField.new(field) } end end end diff --git a/app/presenters/blacklight/show_presenter.rb b/app/presenters/blacklight/show_presenter.rb index 7a32dfb696..70e827429f 100644 --- a/app/presenters/blacklight/show_presenter.rb +++ b/app/presenters/blacklight/show_presenter.rb @@ -4,13 +4,15 @@ class ShowPresenter extend Deprecation self.deprecation_horizon = 'Blacklight version 7.0.0' + attr_reader :document, :configuration, :view_context + # @param [SolrDocument] document - # @param [ActionController::Base] controller scope for linking and generating urls + # @param [ActionView::Base] view context scope for linking and generating urls # @param [Blacklight::Configuration] configuration - def initialize(document, controller, configuration = controller.blacklight_config) + def initialize(document, view_context, configuration = view_context.blacklight_config) @document = document + @view_context = view_context @configuration = configuration - @controller = controller end ## @@ -23,7 +25,7 @@ def initialize(document, controller, configuration = controller.blacklight_confi # @option options [Array] :exclude array of format shortnames to not include in the output # @deprecated moved to ShowPresenter#link_rel_alternates def link_rel_alternates(options = {}) - LinkAlternatePresenter.new(@controller, @document, options).render + LinkAlternatePresenter.new(view_context, document, options).render end ## @@ -35,7 +37,7 @@ def link_rel_alternates(options = {}) def html_title if view_config.html_title_field fields = Array.wrap(view_config.html_title_field) - f = fields.detect { |field| @document.has? field } + f = fields.detect { |field| document.has? field } f ||= 'id' field_values(field_config(f)) else @@ -51,9 +53,9 @@ def html_title # @return [String] def heading fields = Array.wrap(view_config.title_field) - f = fields.detect { |field| @document.has? field } - f ||= @configuration.document_model.unique_key - field_values(field_config(f), value: @document[f]) + f = fields.detect { |field| document.has? field } + f ||= configuration.document_model.unique_key + field_values(field_config(f), value: document[f]) end # @deprecated @@ -88,15 +90,15 @@ def field_value field, options={} # @param [Blacklight::Configuration::Field] solr field configuration # @param [Hash] options additional options to pass to the rendering helpers def field_values(field_config, options={}) - FieldPresenter.new(@controller, @document, field_config, options).render + FieldPresenter.new(view_context, document, field_config, options).render end def view_config - @configuration.view_config(:show) + configuration.view_config(:show) end def field_config(field) - @configuration.show_fields.fetch(field) { Configuration::NullField.new(field) } + configuration.show_fields.fetch(field) { Configuration::NullField.new(field) } end end end