comparison .svn/pristine/18/1840b49390462af0c4e344f45e7614d2e14bd243.svn-base @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 module Redmine
19 module SyntaxHighlighting
20
21 class << self
22 attr_reader :highlighter
23
24 def highlighter=(name)
25 if name.is_a?(Module)
26 @highlighter = name
27 else
28 @highlighter = const_get(name)
29 end
30 end
31
32 def highlight_by_filename(text, filename)
33 highlighter.highlight_by_filename(text, filename)
34 rescue
35 ERB::Util.h(text)
36 end
37
38 def highlight_by_language(text, language)
39 highlighter.highlight_by_language(text, language)
40 rescue
41 ERB::Util.h(text)
42 end
43 end
44
45 module CodeRay
46 require 'coderay'
47
48 class << self
49 # Highlights +text+ as the content of +filename+
50 # Should not return line numbers nor outer pre tag
51 def highlight_by_filename(text, filename)
52 language = ::CodeRay::FileType[filename]
53 language ? ::CodeRay.scan(text, language).html(:break_lines => true) : ERB::Util.h(text)
54 end
55
56 # Highlights +text+ using +language+ syntax
57 # Should not return outer pre tag
58 def highlight_by_language(text, language)
59 ::CodeRay.scan(text, language).html(:wrap => :span)
60 end
61 end
62 end
63 end
64
65 SyntaxHighlighting.highlighter = 'CodeRay'
66 end