class Tilt::SyntaxHighlightingRedcarpetTemplate

Public Class Methods

engine_initialized?() click to toggle source
# File lib/ro/initializers/tilt.rb, line 7
def self.engine_initialized?
  defined?(::Redcarpet) && defined?(::Pygments) && defined?(::ERB)
end

Public Instance Methods

allows_script?() click to toggle source
# File lib/ro/initializers/tilt.rb, line 66
def allows_script?
  true
end
block_code(code, language) click to toggle source
# File lib/ro/initializers/tilt.rb, line 44
def block_code(code, language)
  language = 'ruby' if language.to_s.strip.empty?
  ::Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'})
end
erb(string, binding) click to toggle source
# File lib/ro/initializers/tilt.rb, line 62
def erb(string, binding)
  string
end
evaluate(scope, locals, &block) click to toggle source
# File lib/ro/initializers/tilt.rb, line 51
def evaluate(scope, locals, &block)
  binding =
    if scope.is_a?(::Binding)
      scope
    else
      scope.instance_eval{ ::Kernel.binding }
    end

  @engine.render(erb(data, binding))
end
initialize_engine() click to toggle source
# File lib/ro/initializers/tilt.rb, line 11
def initialize_engine
  require_template_library('redcarpet')
  require_template_library('pygments')
  require_template_library('erb')
end
prepare() click to toggle source
# File lib/ro/initializers/tilt.rb, line 17
def prepare
  @engine =
    Redcarpet::Markdown.new(
      syntax_highlighting_renderer,
  
      :no_intra_emphasis            => true,
      :tables                       => true,
      :fenced_code_blocks           => true,
      :autolink                     => true,
      :disable_indented_code_blocks => true,
      :strikethrough                => true,
      :lax_spacing                  => true,
      :space_after_headers          => false,
      :superscript                  => true,
      :underline                    => true,
      :highlight                    => true,
      :quote                        => true,

      :with_toc_data                => true,
      :hard_wrap                    => true,
    )

  @output = nil
end
syntax_highlighting_renderer() click to toggle source
# File lib/ro/initializers/tilt.rb, line 42
def syntax_highlighting_renderer
  Class.new(Redcarpet::Render::HTML) do
    def block_code(code, language)
      language = 'ruby' if language.to_s.strip.empty?
      ::Pygments.highlight(code, :lexer => language, :options => {:encoding => 'utf-8'})
    end
  end
end