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
+ # 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
+ 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
- CodeRay.scan(inner_text, lang.to_sym).html(
attributes)
0
+ CodeRay.scan(inner_text, lang.to_sym).html(
options)
0
- CodeRay.scan(inner_text, lang.to_sym).html(
:line_numbers => :table)
0
+ CodeRay.scan(inner_text, lang.to_sym).html(
DEFAULT_OPTIONS)
0
RAILS_DEFAULT_LOGGER.warn "CodeRay Error: #{$!.message}"
Comments
No one has commented yet.