Class: Webgen::Tag::Coderay

Inherits:
Object
  • Object
show all
Includes:
Base, WebsiteAccess
Defined in:
lib/webgen/tag/coderay.rb

Overview

Provides syntax highlighting via the coderay library.

Instance Method Summary collapse

Methods included from WebsiteAccess

included, website

Methods included from Base

#create_tag_params, #param, #set_params

Methods included from Loggable

#log, #puts

Instance Method Details

#call(tag, body, context) ⇒ Object

Highlight the body of the block.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webgen/tag/coderay.rb', line 12

def call(tag, body, context)
  require 'coderay'
  options = {
    :css => :style,
    :wrap => param('tag.coderay.wrap').to_sym,
    :line_numbers => (param('tag.coderay.line_numbers') ? :inline : nil),
    :line_number_start => param('tag.coderay.line_number_start'),
    :tab_width => param('tag.coderay.tab_width'),
    :bold_every => param('tag.coderay.bold_every')
  }

  if param('tag.coderay.process_body')
    body = website.blackboard.invoke(:content_processor, 'tags').call(context.clone(:content => body)).content
  end
  CodeRay.scan(body, param('tag.coderay.lang').to_sym).html(options)
end