Class: NanDoc::SpecDoc::Playback::Ruby

Inherits:
Object
  • Object
show all
Includes:
PlaybackMethods, Ruby2RubyStandin, Singleton
Defined in:
lib/nandoc/spec-doc/playback/players/ruby.rb

Instance Method Summary collapse

Methods included from PlaybackMethods

#get_tag_filter, #run_sexp_with_handlers

Methods included from Ruby2RubyStandin

#leading_indent, #re_for_line_with_same_indent_as, #re_for_unindent_gsub, #reindent_content, #string_diff_assert

Constructor Details

#initializeRuby

Returns a new instance of Ruby.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nandoc/spec-doc/playback/players/ruby.rb', line 20

def initialize
  @here = NanDoc::Regexp.new( /\A(.*)(?:, ?<<-'?([A-Z]+))/,
                                 :keep,          :here)

  @inspect = NanDoc::Regexp.new(
    /\A([ \t]*)(?:nandoc\.inspect[ \t]*)(.+)\Z/,
    :indent,   :tail)

  @prefix = '# '

  @re_out = NanDoc::Regexp.new(/\A[ \t]*nandoc\.out\([ \t]*<<-'?([A-Z]+)/)

  @re_until_do = /\A[ \t]*\)[ \t]*do[ \t]*\Z/
end

Instance Method Details

#run_record_ruby(out, scn) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nandoc/spec-doc/playback/players/ruby.rb', line 35

def run_record_ruby out, scn
  node = scn.scan_assert(:record_ruby)
  code = node[1]
  @file_lines = code.file_lines.dup # we change the originals
  while ! scn.eos? && [:inspect, :out].include?(curr = scn.current.first)
    case curr
    when :inspect; process_inspect(scn)
    when :out;     process_out(scn)
    else fail("do me: #{curr.inspect}")
    end
  end
  these = @file_lines[code.start_at[:line]..code.stop_at[:line]-2]
  block = these.join('')
  unind = unindent(block)
  unind.chomp! # sure why not
  conv = ::Syntax::Convertors::HTML.for_syntax('ruby')
  html = conv.convert(unind, false)
  out.push_smart 'pre', 'ruby', html
  nil
end