Sha256: cd03f17b2c9765c6241c338a1c6eaac379a6bbe59a26a6d139d7266a833dac5b
Contents?: true
Size: 1012 Bytes
Versions: 4
Compression:
Stored size: 1012 Bytes
Contents
module DontRepeatYourself class SnippetExtractor #:nodoc: class NullConverter; def convert(code, pre); code; end; end #:nodoc: begin require 'rubygems' require 'syntax/convertors/html' @@converter = Syntax::Convertors::HTML.for_syntax "ruby" rescue LoadError @@converter = NullConverter.new end def plain_source_code(starts, ends, file_path) if File.file?(file_path) lines = File.open(file_path).read.split("\n") lines[starts-1..ends-1].join("\n") else "# Couldn't get snippet for #{file_path}" end end def snippet(starts, ends, file_path) raw_code = plain_source_code(starts, ends, file_path) highlighted = @@converter.convert(raw_code, false) highlighted << "\n<span class=\"comment\"># gem install syntax to get syntax highlighting</span>" if @@converter.is_a?(NullConverter) highlighted end end end
Version data entries
4 entries across 4 versions & 3 rubygems