Class: DontRepeatYourself::SnippetExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/dont_repeat_yourself/snippet_extractor.rb

Overview

:nodoc:

Defined Under Namespace

Classes: NullConverter

Instance Method Summary collapse

Instance Method Details

#plain_source_code(starts, ends, file_path) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/dont_repeat_yourself/snippet_extractor.rb', line 13

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

#snippet(starts, ends, file_path) ⇒ Object



22
23
24
25
26
27
# File 'lib/dont_repeat_yourself/snippet_extractor.rb', line 22

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