Skip to content

Commit

Permalink
Use percent regexp so we don't need to excape slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 1, 2018
1 parent a0c6247 commit 6cca81d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 29 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -655,16 +655,6 @@ Style/RedundantFreeze:
Exclude:
- 'app/helpers/blacklight/render_partials_helper_behavior.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'app/views/catalog/_document.atom.builder'
- 'spec/helpers/blacklight/url_helper_behavior_spec.rb'
- 'spec/views/catalog/_thumbnail.html.erb_spec.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
Expand Down
31 changes: 15 additions & 16 deletions app/views/catalog/_document.atom.builder
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,52 @@

xml.entry do
xml.title index_presenter(document).label(document_show_link_field(document))

# updated is required, for now we'll just set it to now, sorry
xml.updated Time.current.iso8601

xml.link "rel" => "alternate", "type" => "text/html", "href" => polymorphic_url(url_for_document(document))
# add other doc-specific formats, atom only lets us have one per
# content type, so the first one in the list wins.
xml << show_presenter(document).link_rel_alternates(unique: true)
xml << show_presenter(document).link_rel_alternates(unique: true)

xml.id polymorphic_url(url_for_document(document))



if document.to_semantic_values.key? :author
xml.author { xml.name(document.to_semantic_values[:author].first) }
end

with_format("html") do
xml.summary "type" => "html" do
xml.text! render_document_partial(document,
:index,
document_counter: document_counter)
end
end
#If they asked for a format, give it to them.

#If they asked for a format, give it to them.
if (params["content_format"] &&
document.export_formats[params["content_format"].to_sym])

type = document.export_formats[params["content_format"].to_sym][:content_type]

xml.content type: type do |content_element|
data = document.export_as(params["content_format"])

# encode properly. See:
# http://tools.ietf.org/html/rfc4287#section-4.1.3.3
type = type.downcase
if (type.downcase =~ /\+|\/xml$/)
# xml, just put it right in
if (type.downcase =~ %r{\+|/xml$})
# xml, just put it right in
content_element << data
elsif (type.downcase =~ /text\//)
elsif (type.downcase =~ %r{text/})
# text, escape
content_element.text! data
else
#something else, base64 encode it
content_element << Base64.encode64(data)
end
end

end
end
4 changes: 2 additions & 2 deletions spec/helpers/blacklight/url_helper_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
allow(helper).to receive(:current_search_session).and_return double(query_params: bookmarks_query_params)
tag = helper.link_back_to_catalog
expect(tag).to match /Back to Bookmarks/
expect(tag).to match /\/bookmarks/
expect(tag).to match %r{/bookmarks}
end

context "with a search context" do
Expand Down Expand Up @@ -152,7 +152,7 @@
allow(helper).to receive_messages(params: parameter_class.new)
tag = helper.link_to_query(query)
expect(tag).to match /q=#{query}/
expect(tag).to match />#{query}<\/a>/
expect(tag).to match %r{>#{query}</a>}
end

it "builds a link tag to catalog using query string and other existing params" do
Expand Down
2 changes: 1 addition & 1 deletion spec/views/catalog/_thumbnail.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
it "renders the thumbnail if the document has one" do
render partial: "catalog/thumbnail", locals: { document: document_with_thumbnail_field, document_counter: 1 }
expect(rendered).to match /document-thumbnail/
expect(rendered).to match /src="http:\/\/localhost\/logo.png"/
expect(rendered).to match %r{src="http://localhost/logo.png"}
end

it "does not render a thumbnail if the document does not have one" do
Expand Down

0 comments on commit 6cca81d

Please sign in to comment.