aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-05-30 12:42:48 +0100
committerGareth Rees <gareth@mysociety.org>2014-06-25 10:40:37 +0100
commite5a73815f580d296572e11b71b5f3ed320bbe912 (patch)
treea6afe88e876933f15a65e9f948e195dc5b79cf5e /app/helpers/application_helper.rb
parentb429a1a2fc2a3b73322e6361fb27ed0a5c3ace7f (diff)
Add helper to highlight and excerpt by regex
Backport of https://github.com/rails/rails/pull/11793/ Contains integration tests to check that it works as expected with ActsAsXapian.
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb22
1 files changed, 3 insertions, 19 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 45b042354..49ce94951 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -22,6 +22,9 @@ module ApplicationHelper
# Useful for sending emails
include MailerHelper
+ # Extra highlight helpers
+ include HighlightHelper
+
# Copied from error_messages_for in active_record_helper.rb
def foi_error_messages_for(*params)
options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
@@ -54,25 +57,6 @@ module ApplicationHelper
end
end
- # Highlight words, also escapes HTML (other than spans that we add)
- def highlight_words(t, words, html = true)
- if html
- highlight(h(t), words, :highlighter => '<span class="highlight">\1</span>').html_safe
- else
- highlight(t, words, :highlighter => '*\1*')
- end
- end
-
- def highlight_and_excerpt(t, words, excount, html = true)
- newt = excerpt(t, words[0], :radius => excount)
- if not newt
- newt = excerpt(t, '', :radius => excount)
- end
- t = newt
- t = highlight_words(t, words, html)
- return t
- end
-
def locale_name(locale)
return LanguageNames::get_language_name(locale)
end