Skip to content

Commit

Permalink
Make odr legal link clickable in impressum, closes #1508
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaltmann committed Jul 2, 2017
1 parent ab56531 commit da952a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def truncate_and_sanitize_without_linebreaks(text = '', length = 70, omission =
truncate(Sanitize.clean(text), length: length, separator: separator, omission: omission).gsub("\n", ' ')
end

def clickable_legal_links(html)
odr_url = /https?:\/\/ec.europa.eu\/odr\/?/
html.to_s.gsub(odr_url) do |url|
"<a href=\"#{url}\" target=\"_blank\">#{url}</a>"
end
end

# Login form anywhere - https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/show/_article_contents.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
= link_to resource.seller.cancellation_form.url(:original, false) do
= t('formtastic.labels.user.cancellation_form')
= accordion_item "about", {content_class: "Accordion-content-maxsize"} do
= resource.seller_about.html_safe
= raw clickable_legal_links(resource.seller_about)


- # Feedback Box
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/profile.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- if resource.about.present?
h3
= "#{t('formtastic.labels.user.about')}"
= raw resource.about
= raw clickable_legal_links(resource.about)

- if resource.terms.present?
hr
Expand Down
21 changes: 21 additions & 0 deletions test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2012-2017, Fairmondo eG. This file is
# licensed under the GNU Affero General Public License version 3 or later.
# See the COPYRIGHT file for details.

require_relative '../test_helper'

describe ApplicationHelper do
describe 'clickable_legal_links' do
it 'should put a link around an ODR URL' do
html = '<p>Please read http://ec.europa.eu/odr for legal stuff on online stores.</p>'
expected = '<p>Please read <a href="http://ec.europa.eu/odr" target="_blank">http://ec.europa.eu/odr</a> for legal stuff on online stores.</p>'
assert_equal(expected, helper.clickable_legal_links(html))
end

it 'should put no link around other URLs' do
html = '<p>Please also look at http://forbidden.website.com</p>'
expected = '<p>Please also look at http://forbidden.website.com</p>'
assert_equal(expected, helper.clickable_legal_links(html))
end
end
end

0 comments on commit da952a5

Please sign in to comment.