Module: NanDoc::Filters::General::HackHelpers
- Included in:
- ProcessSnippet
- Defined in:
- lib/nandoc/filters.rb
Instance Method Summary collapse
-
#leading_indent(str) ⇒ Object
stand-in for ruby-2-ruby.
- #re_for_here(here) ⇒ Object
- #re_for_line_with_same_indent_as(str) ⇒ Object
- #re_for_unindent_gsub(indent) ⇒ Object
- #string_diff_assert(long, short) ⇒ Object
Instance Method Details
#leading_indent(str) ⇒ Object
stand-in for ruby-2-ruby
479 480 481 |
# File 'lib/nandoc/filters.rb', line 479 def leading_indent str /\A([ \t]*)/ =~ str && $1 end |
#re_for_here(here) ⇒ Object
487 488 489 |
# File 'lib/nandoc/filters.rb', line 487 def re_for_here here /\A[ \t]*#{Regexp.escape(here)}[ \t]*\n?\Z/ end |
#re_for_line_with_same_indent_as(str) ⇒ Object
482 483 484 485 486 |
# File 'lib/nandoc/filters.rb', line 482 def re_for_line_with_same_indent_as str ind = leading_indent(str) re = /\A#{Regexp.escape(ind)}(?=[^ \t])/ re end |
#re_for_unindent_gsub(indent) ⇒ Object
490 491 492 493 |
# File 'lib/nandoc/filters.rb', line 490 def re_for_unindent_gsub indent re = /\A#{Regexp.escape(indent)}/ re end |
#string_diff_assert(long, short) ⇒ Object
494 495 496 497 498 499 500 |
# File 'lib/nandoc/filters.rb', line 494 def string_diff_assert long, short idx = long.index(short) or fail("short not found in long -- "<< "#{short.inspect} in #{long.inspect}") head = long[0,idx] # usu. '' tail = long[idx + short.length..-1] head + tail end |