summaryrefslogtreecommitdiffstats
path: root/app/helpers/search_helper.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-04-30 08:52:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-04-30 08:52:39 +0000
commitebe10fa6452de7ea6c5759bfd9c7b439091b54cd (patch)
tree30eb8f2f6fb758c41530597814c2e9d048fc75c8 /app/helpers/search_helper.rb
parent833c5035a697858cfc390b08e5db204ba30831d9 (diff)
downloadredmine-ebe10fa6452de7ea6c5759bfd9c7b439091b54cd.tar.gz
redmine-ebe10fa6452de7ea6c5759bfd9c7b439091b54cd.zip
Added a quick search form in page header. Search functionality moved to a dedicated controller.
When used: * outside of a project: searches projects * inside a project: searches issues, changesets, news, documents and wiki pages of the current project If an issue number is given, user is redirected to the corresponding issue. git-svn-id: http://redmine.rubyforge.org/svn/trunk@489 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers/search_helper.rb')
-rw-r--r--app/helpers/search_helper.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
new file mode 100644
index 000000000..bc408a305
--- /dev/null
+++ b/app/helpers/search_helper.rb
@@ -0,0 +1,28 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module SearchHelper
+ def highlight_tokens(text, tokens)
+ return text unless tokens && !tokens.empty?
+ regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE
+ result = ''
+ text.split(regexp).each_with_index do |words, i|
+ result << (i.even? ? (words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', words, :class => 'highlight'))
+ end
+ result
+ end
+end