Skip to content

Commit

Permalink
Enable the rendering pipeline to be configured per-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 30, 2018
1 parent 2a23401 commit 9200f7e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
25 changes: 20 additions & 5 deletions app/presenters/blacklight/rendering/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,42 @@

module Blacklight
module Rendering
# The field rendering pipeline
# The field rendering pipeline.
# This takes a field and it's values and transforms them through a list of
# operations.
class Pipeline
class_attribute :operations
class_attribute :operations, instance_accessor: false

# The ordered list of pipeline operations
self.operations = [HelperMethod, LinkToFacet, Microdata, Join]

def initialize(values, config, document, context, options)
# @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 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)
@values = values
@config = config
@document = document
@context = context
@operations = operations
@options = options
end

attr_reader :values, :config, :document, :context, :options
attr_reader :values, :config, :document, :context, :operations, :options

# @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 options [Hash] options to pass to the processors. Typically only `:value` is used
def self.render(values, config, document, context, options)
new(values, config, document, context, options).render
new(values, config, document, context, operations, options).render
end

# Perform the processing by the pipeline
def render
first, *rest = *stack
first.new(values, config, document, context, options, rest).render
Expand Down
29 changes: 24 additions & 5 deletions spec/presenters/pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
include Capybara::RSpecMatchers
let(:document) { instance_double(SolrDocument) }
let(:context) { double }
let(:options) { double }
let(:presenter) { described_class.new(values, field_config, document, context, options) }
let(:options) { double('options') }

describe "render" do
subject { presenter.render }
describe '.render' do
subject { described_class.render(values, field_config, document, context, options) }

let(:values) { %w[a b] }
let(:field_config) { Blacklight::Configuration::NullField.new }
Expand All @@ -28,9 +27,16 @@

it { is_expected.to have_selector("span[@itemprop='some-prop']", text: "a") }
end

it 'sets the operations on the instance as equal to the class variable' do
expect(described_class).to receive(:new)
.with(values, field_config, document, context, described_class.operations, options)
.and_return(instance_double(described_class, render: true))
subject
end
end

describe "#operations" do
describe '.operations' do
subject { described_class.operations }

it {
Expand All @@ -40,4 +46,17 @@
Blacklight::Rendering::Join]
}
end

describe '#operations' do
subject(:operations) { presenter.operations }

let(:presenter) { described_class.new(values, field_config, document, context, steps, options) }
let(:steps) { [Blacklight::Rendering::HelperMethod] }
let(:values) { ['a'] }
let(:field_config) { Blacklight::Configuration::NullField.new }

it 'sets the operations to the value passed to the initializer' do
expect(operations).to eq steps
end
end
end

0 comments on commit 9200f7e

Please sign in to comment.