public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
expose more coderay options, add default options hash for customization

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2565 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Thu Dec 21 20:02:48 -0800 2006
commit  757d19e5ee8b0c7de51376e0e751d46a0ec89dbe
tree    6f6326536cc0383d6545340f2a69d56f57a10c64
parent  ea5c6dd6f870051ea0da24f55206038a29e646b1
...
1
2
 
3
4
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
 
12
13
 
14
15
16
...
1
2
3
4
 
 
 
 
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
26
27
 
28
29
30
31
0
@@ -1,16 +1,31 @@
0
 require 'coderay'
0
 class CodeMacro < FilteredColumn::Macros::Base
0
+ DEFAULT_OPTIONS = {:css => :class, :wrap => :div, :line_numbers => :table, :tab_width => 2, :bold_every => 5, :hint => false, :line_number_start => 1}
0
   def self.filter(attributes, inner_text = '', text = '')
0
- lang = attributes.delete(:lang)
0
- attributes[:line_numbers] = :table unless attributes.has_key?(:line_numbers)
0
- attributes.each do |key, value|
0
- attributes[key] = value == 'nil' ? nil : value.to_sym rescue nil
0
- end
0
+ # It's a whole lot easier to just set your attributes statically
0
+ # I think for most of us the only option we're gonna change is 'lang'
0
+ # refer to http://rd.cycnus.de/coderay/doc/classes/CodeRay/Encoders/HTML.html for more info
0
+ # use code_highlighter.css to change highlighting
0
+ # don't change, formats code so code_highlighter.css can be used
0
+
0
+ lang = attributes[:lang].blank? ? nil : attributes[:lang].to_sym
0
+ options = DEFAULT_OPTIONS.dup
0
+ # type of line number to print options: :inline, :table, :list, nil [default = :table]
0
+ # you can change the line_numbers default value but you will probably have to change the css too
0
+ options[:line_numbers] = attributes[:line_numbers].to_sym unless attributes[:line_numbers].blank?
0
+ # changes tab spacing [default = 2]
0
+ options[:tab_width] = attributes[:tab_width].to_i unless attributes[:tab_width].blank?
0
+ # bolds every 'X' line number
0
+ options[:bold_every] = attributes[:bold_every].to_i unless attributes[:bold_every].blank?
0
+ # use it if you want to can be :info, :info_long, :debug just debugging info in the tags
0
+ options[:hint] = attributes[:hint].to_sym unless attributes[:hint].blank?
0
+ # start with line number
0
+ options[:line_number_start] = attributes[:line_number_start].to_i unless attributes[:line_number_start].blank?
0
 
0
     begin
0
- CodeRay.scan(inner_text, lang.to_sym).html(attributes)
0
+ CodeRay.scan(inner_text, lang.to_sym).html(options)
0
     rescue ArgumentError
0
- CodeRay.scan(inner_text, lang.to_sym).html(:line_numbers => :table)
0
+ CodeRay.scan(inner_text, lang.to_sym).html(DEFAULT_OPTIONS)
0
     rescue
0
       unless lang.blank?
0
         RAILS_DEFAULT_LOGGER.warn "CodeRay Error: #{$!.message}"

Comments

    No one has commented yet.