-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ValueRenderer with a Rendering::Pipeline
- Loading branch information
Showing
17 changed files
with
229 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Blacklight | ||
module Rendering | ||
class AbstractStep | ||
def initialize(values, config, document, context, options, stack) | ||
@values = values | ||
@config = config | ||
@document = document | ||
@context = context | ||
@options = options | ||
@stack = stack | ||
end | ||
|
||
attr_reader :values, :config, :document, :context, :options, :stack | ||
|
||
protected | ||
|
||
def next_step(output_values) | ||
first, *rest = *stack | ||
first.new(output_values, config, document, context, options, rest).render | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Blacklight | ||
module Rendering | ||
class HelperMethod < AbstractStep | ||
def render | ||
return next_step(values) unless config.helper_method | ||
return render_helper # short circut the rest of the steps | ||
end | ||
|
||
private | ||
|
||
def render_helper | ||
context.send(config.helper_method, | ||
options.merge(document: document, | ||
field: config.field, | ||
config: config, | ||
value: values)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Blacklight | ||
module Rendering | ||
class Join < AbstractStep | ||
def render | ||
options = config.separator_options || {} | ||
next_step(values.map { |x| html_escape(x) }.to_sentence(options).html_safe) | ||
end | ||
|
||
private | ||
|
||
def html_escape(*args) | ||
ERB::Util.html_escape(*args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Blacklight | ||
module Rendering | ||
class LinkToFacet < AbstractStep | ||
def render | ||
# TODO: We should rename the config variable, because it creates a link to a facet. | ||
return next_step(values) unless config.link_to_search | ||
next_step(render_link) | ||
end | ||
|
||
private | ||
|
||
# This allows the link to wrap an itemprop | ||
def render_link | ||
values.map { |v| link(link_field, v) } | ||
end | ||
|
||
def link_field | ||
return config.key if config.link_to_search === true | ||
config.link_to_search | ||
end | ||
|
||
def link(field, v) | ||
context.link_to v, search_path(field, v) | ||
end | ||
|
||
def search_path(field, v) | ||
context.search_action_path(facet_params(field, v)) | ||
end | ||
|
||
def facet_params(field, v) | ||
context.search_state.reset.add_facet_params(field, v) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Blacklight | ||
module Rendering | ||
class Microdata < AbstractStep | ||
include ActionView::Helpers::TagHelper | ||
def render | ||
return next_step(values) unless config.itemprop | ||
next_step(values.map { |x| itemprop(x, config.itemprop) }) | ||
end | ||
|
||
private | ||
|
||
def itemprop(val, itemprop) | ||
content_tag :span, val, itemprop: itemprop | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Blacklight | ||
module Rendering | ||
# The field rendering pipeline | ||
class Pipeline | ||
def initialize(values, config, document, context, options) | ||
@values = values | ||
@config = config | ||
@document = document | ||
@context = context | ||
@options = options | ||
end | ||
|
||
attr_reader :values, :config, :document, :context, :options | ||
|
||
def self.render(values, config, document, context, options) | ||
new(values, config, document, context, options).render | ||
end | ||
|
||
def render | ||
first, *rest = *stack | ||
first.new(values, config, document, context, options, rest).render | ||
end | ||
|
||
protected | ||
|
||
# Ordered list of operations, Terminator must be at the end. | ||
def stack | ||
[HelperMethod, LinkToFacet, Microdata, Join, Terminator] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Blacklight | ||
module Rendering | ||
class Terminator < AbstractStep | ||
def render | ||
values | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
module Blacklight | ||
# Returned if no config is defined for the field in the Blacklight::Configuration | ||
class Configuration::NullField < Blacklight::Configuration::Field | ||
def initialize(field) | ||
super(field: field) | ||
def initialize(field_or_hash = nil) | ||
case field_or_hash | ||
when String, Symbol | ||
super(field: field_or_hash) | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.