public
Description: Syntax Highlighting extension for RadiantCMS
Homepage: http://github.com/marcoow/syntax_highlighting/wikis
Clone URL: git://github.com/marcoow/syntax_highlighting.git
Reformatted, removed deboug output
Marco Otte-Witte (author)
Sat Mar 01 01:48:34 -0800 2008
commit  472a9c237029d07c9127021a214e18dc797dc7da
tree    c1ed430c25605a271990f04163cc06c2437a32f0
parent  afc37f448dd9c6515f941ddaaf08180b450313d1
...
39
40
41
42
43
 
44
45
46
...
51
52
53
54
55
56
57
 
 
58
59
60
61
 
62
63
 
64
65
 
66
67
 
68
69
70
71
72
 
73
74
75
76
77
78
79
 
80
81
82
83
84
 
85
86
87
...
39
40
41
 
 
42
43
44
45
...
50
51
52
 
53
 
 
54
55
56
57
58
 
59
60
 
61
62
 
63
64
 
65
66
67
68
69
 
70
71
72
73
74
75
76
 
77
78
79
80
81
 
82
83
84
85
0
@@ -39,8 +39,7 @@ module PygmentsWrapper
0
     begin
0
       return CGI.escapeHTML(code) if !(language = get_language_sym(language))
0
       cache_key = build_cache_key(code, language)
0
- result = get_from_cache(cache_key)
0
- return result if result
0
+ return result if result = get_from_cache(cache_key)
0
       filename = "/tmp/syntax_highlight_#{Time.now.to_f}"
0
       File.open(filename, "w") { |f|
0
         f << code
0
@@ -51,37 +50,36 @@ module PygmentsWrapper
0
       pygments.close
0
       clean_result(result)
0
       add_to_cache(cache_key, result)
0
- logger.debug "RESULT: " + result.inspect
0
       result
0
- rescue
0
- logger.debug "EXCEPTION!"
0
+ rescue => ex
0
+ logger.debug "Syntax Highlighting exception: ex.to_s"
0
       code
0
     end
0
   end
0
-
0
+
0
   protected
0
-
0
+
0
     def build_cache_key(code, language)
0
- "#{language}:___#{code}".hash
0
+ "#{language}_#{code.hash}"
0
     end
0
-
0
+
0
     def get_language_sym(name)
0
       return false if !SUPPORTED_LANGUAGES.key?(name.to_s.downcase)
0
       SUPPORTED_LANGUAGES[name.to_s.downcase]
0
     end
0
-
0
+
0
     def clean_result(result)
0
       result.strip!
0
       result.sub!(/<div class=\"highlight\"><pre>/, '')
0
       result.sub!(/\n<\/pre><\/div>/, '')
0
       result
0
     end
0
-
0
+
0
     def get_from_cache(key)
0
       return CACHE[key] if CACHE.key?(key)
0
       false
0
     end
0
-
0
+
0
     def add_to_cache(key, content)
0
       if !CACHE.key?(key)
0
         CACHE[key] = content
...
30
31
32
33
34
35
36
...
30
31
32
 
33
34
35
0
@@ -30,7 +30,6 @@ module SyntaxHighlightingTags
0
   }
0
   tag 'code' do |tag|
0
     return "<code>#{CGI.escapeHTML(tag.expand.to_s.strip)}</code>" if (!tag.attributes.key?('language'))
0
- logger.debug "TAG CONTENT: " + tag.expand.to_s.strip.inspect
0
     "<code>#{format(tag.expand.to_s.strip, tag.attributes['language'])}</code>"
0
   end
0
 
...
1
 
2
 
3
4
5
6
7
8
 
9
10
11
...
28
29
30
31
 
 
32
 
33
 
34
...
1
2
3
4
5
6
7
8
9
 
10
11
12
13
...
30
31
32
 
33
34
35
36
37
38
39
0
@@ -1,11 +1,13 @@
0
 namespace :radiant do
0
+
0
   namespace :extensions do
0
+
0
     namespace :syntax_highlighting do
0
       
0
       desc 'Installs the Syntax Highlighting extension'
0
       task :install => :update do
0
         puts "Syntax Highlighting won't work for you since you don't have Pygments installed. Run \n\tsudo easy_install pygments\nfirst." if IO::popen("which pygmentize").read == ''
0
- puts 'Syntax Highlighting won\'t work for you since your your /tmp directory is not writable. Please grant write access for /tmp to the user you are running Radiant under.' if !File.writable?('/tmp/')
0
+ puts 'Syntax Highlighting won\'t work for you since your your /tmp directory is not writable. Grant write access for /tmp to the user you are running Radiant under.' if !File.writable?('/tmp/')
0
       end
0
       
0
       desc "Runs the migration of the Syntax Highlighting extension"
0
@@ -28,7 +30,10 @@ namespace :radiant do
0
           mkdir_p RAILS_ROOT + directory
0
           cp file, RAILS_ROOT + path
0
         end
0
- end
0
+ end
0
+
0
     end
0
+
0
   end
0
+
0
 end

Comments

    No one has commented yet.