Class: NanDoc::Filters::General::ProcessSnippet
- Inherits:
-
Object
- Object
- NanDoc::Filters::General::ProcessSnippet
- Includes:
- HackHelpers
- Defined in:
- lib/nandoc/filters.rb
Constant Summary collapse
- ReInspect =
/\A([ \t]*)(?:nandoc\.inspect[ \t]*)(.+)\Z/
- ReOut =
/\A[ \t]*nandoc\.out\([ \t]*<<-'?([A-Z]+)/
- ReUntilDo =
/\A[ \t]*\)[ \t]*do[ \t]*\Z/
- ReHere =
/\A(.*)(?:, ?<<-'?([A-Z]+))/
- ConsumeThese =
[:inspect, :out]
Instance Method Summary collapse
-
#initialize(filter, sexp, idx) ⇒ ProcessSnippet
constructor
A new instance of ProcessSnippet.
- #process ⇒ Object
Methods included from HackHelpers
#leading_indent, #re_for_here, #re_for_line_with_same_indent_as, #re_for_unindent_gsub, #string_diff_assert
Constructor Details
#initialize(filter, sexp, idx) ⇒ ProcessSnippet
Returns a new instance of ProcessSnippet.
506 507 508 509 510 |
# File 'lib/nandoc/filters.rb', line 506 def initialize filter, sexp, idx @prefix = '# => ' sexp[idx].first == :record_ruby or fail("must be record_ruby") @filter, @sexp, @idx = filter, sexp, idx end |
Instance Method Details
#process ⇒ Object
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
# File 'lib/nandoc/filters.rb', line 521 def process j = @idx snip = @sexp[j][1] @lines = snip.file_lines.dup # we will be changing values @inspects = [] while @sexp[j+1] && ConsumeThese.include?(@sexp[j+1].first) j += 1 @inspects.push @sexp[j] end inspects_interpolate if @inspects.any? unindented_lines = @lines[snip.line_start..snip.line_stop-2] fake_unindented_ruby = unindented_lines.compact.join('') indent = /\A([ \t]*)/ =~ fake_unindented_ruby && $1 fake_md = {:indent => indent, :content => fake_unindented_ruby} @filter.render_block_fence_ruby(fake_md) advance_by = j - @idx advance_by end |