Skip to content

Commit

Permalink
Display special encoding from solr.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed May 31, 2017
1 parent dfee1d6 commit 11b9e29
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ Rails/Date:
Rails/TimeZone:
Enabled: false

Rails/OutputSafety:
Exclude:
- 'app/presenters/rtl_index_presenter.rb'
- 'app/presenters/rtl_show_presenter.rb'

Rails/DynamicFindBy:
Exclude:
- 'app/controllers/exhibits_controller.rb'
Expand Down
4 changes: 4 additions & 0 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def find(id, params = {})
end
end

def fetch(key, *default)
Array.wrap(super).map(&:html_safe)
end

def to_param
first("access_identifier_ssim") || id
end
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/rtl_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def value_from_symbol(field)

def label_value(value, config)
if value.is_a?(Array) && value.count > 1
value.collect { |v| field_values(config, value: v) }
value.collect { |v| field_values(config, value: v.html_safe) }
else
field_values(config, value: value)
field_values(config, value: Array.wrap(value).map(&:html_safe))
end
end
end
4 changes: 2 additions & 2 deletions app/presenters/rtl_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def field_value_separator
# @options opts [String] :value
def field_value(field, options = {})
tags = super.split(field_value_separator).collect do |value|
content_tag(:li, value, dir: value.dir)
content_tag(:li, value.html_safe, dir: value.dir)
end

content_tag(:ul) do
Expand All @@ -29,7 +29,7 @@ def header
f = fields.detect { |field| @document.has? field }
f ||= @configuration.document_model.unique_key
@document[f].to_sentence(field_config(f).separator_options)
field_value(f, value: @document[f])
field_value(f, value: @document[f].map(&:html_safe))
end

def field_config(field)
Expand Down
8 changes: 8 additions & 0 deletions spec/presenters/rtl_index_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
end
end

context "when given a title with special characters" do
let(:title) { ["Traité sur l'art de la charpente : théorique et pratique"] }

it "renders appropriately" do
expect(presenter.label(:title)).to eq "Traité sur l'art de la charpente : théorique et pratique"
end
end

context 'when configured with a display title field' do
let(:index_config) { double(title_field: 'title', display_title_field: 'alternate_title') }

Expand Down
10 changes: 8 additions & 2 deletions spec/presenters/rtl_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
let(:document) do
SolrDocument.new(
field: ["بي"],
title: ["بي", "Test"]
special: ["Traité sur l'art de la charpente : théorique et pratique"],
title: ["بي", "Traité sur l'art de la charpente : théorique et pratique"]
)
end
let(:cc_config) { CatalogController.new.blacklight_config }
Expand All @@ -24,11 +25,16 @@
expect(presenter.field_value(:field)).to eq "<ul><li dir=\"rtl\">بي</li></ul>"
end
end
context "when given a string with special characters" do
it "renders it without escaping them" do
expect(presenter.field_value(:special)).to eq "<ul><li dir=\"ltr\">Traité sur l'art de la charpente : théorique et pratique</li></ul>"
end
end
end

describe "#heading" do
it "returns multiple titles appropriately" do
expect(presenter.header).to eq "<ul><li dir=\"rtl\">بي</li><li dir=\"ltr\">Test</li></ul>"
expect(presenter.header).to eq "<ul><li dir=\"rtl\">بي</li><li dir=\"ltr\">Traité sur l'art de la charpente : théorique et pratique</li></ul>"
end
end
end

0 comments on commit 11b9e29

Please sign in to comment.