module Webgen::Tag::Coderay

Provides syntax highlighting via the coderay library.

Public Class Methods

call(tag, body, context) click to toggle source

Highlight the body of the block.

   # File lib/webgen/tag/coderay.rb
11 def self.call(tag, body, context)
12   config = context[:config]
13 
14   options = {}
15   if config['tag.coderay.css'].to_s == 'other'
16     options[:css] = :class
17   elsif config['tag.coderay.css'].to_s == 'class'
18     options[:css] = :class
19     context.html_head.link_file(:css, '/stylesheets/coderay-default.css')
20   else
21     options[:css] = :style
22   end
23   options.merge!(:wrap => config['tag.coderay.wrap'].to_sym,
24                  :line_numbers => (config['tag.coderay.line_numbers'] ? :inline : nil),
25                  :line_number_start => config['tag.coderay.line_number_start'],
26                  :tab_width => config['tag.coderay.tab_width'],
27                  :bold_every => config['tag.coderay.bold_every'])
28 
29   if config['tag.coderay.process_body']
30     body = context.website.ext.content_processor.call('tags', context.clone(:content => body)).content
31   end
32   CodeRay.scan(body, config['tag.coderay.lang'].to_sym).html(options)
33 end