-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make metadata field text URL aware and br tags within text shou…
…ld work by using html_safe (#105) * feat: make metadata field text URL aware and br tags within text should work by using html_safe * fix: linting issues
- Loading branch information
Showing
9 changed files
with
76 additions
and
27 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,29 @@ | ||
# frozen_string_literal: true | ||
require 'rails_autolink' | ||
|
||
module ApplicationHelper | ||
include ERB::Util # provides html_escape | ||
|
||
# Uses Rails auto_link to add links to fields | ||
# | ||
# @param field [String,Hash] string to format and escape, or a hash as per helper_method | ||
# @option field [SolrDocument] :document | ||
# @option field [String] :field name of the solr field | ||
# @option field [Blacklight::Configuration::IndexField, Blacklight::Configuration::ShowField] :config | ||
# @option field [Array] :value array of values for the field | ||
# @param show_link [Boolean] | ||
# @return [ActiveSupport::SafeBuffer] | ||
def iconify_auto_link(field, show_link = true) | ||
if field.is_a? Hash | ||
options = field[:config].separator_options || {} | ||
text = field[:value].to_sentence(options) | ||
else | ||
text = field | ||
end | ||
# this block is only executed when a link is inserted; | ||
# if we pass text containing no links, it just returns text. | ||
auto_link(html_escape(text)) do |value| | ||
"<span class='fa fa-external-link'></span>#{(' ' + value) if show_link}" | ||
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,20 @@ | ||
# frozen_string_literal: true | ||
# Joins values using configured value, linebreak, or delimiter | ||
class AutoLink < Blacklight::Rendering::AbstractStep | ||
include ActionView::Helpers::TextHelper | ||
|
||
def render | ||
if config.auto_link | ||
linked_values = values.map do |value| | ||
auto_link(html_escape(value), &:to_s) | ||
end | ||
next_step(linked_values) | ||
else | ||
next_step(values) | ||
end | ||
end | ||
|
||
def html_escape(*args) | ||
ERB::Util.html_escape(*args) | ||
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 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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# frozen_string_literal: true | ||
ActiveSupport::Reloader.to_prepare do | ||
Blacklight::Rendering::Pipeline.operations = [Blacklight::Rendering::HelperMethod, | ||
Blacklight::Rendering::LinkToFacet, | ||
Blacklight::Rendering::Microdata, | ||
CustomJoin] | ||
Blacklight::Rendering::Pipeline.operations = [ | ||
AutoLink, | ||
Blacklight::Rendering::HelperMethod, | ||
Blacklight::Rendering::LinkToFacet, | ||
Blacklight::Rendering::Microdata, | ||
CustomJoin | ||
] | ||
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