Module: WhatTheGem::Template::Filters
- Defined in:
- lib/whatthegem/template.rb
Instance Method Summary collapse
-
#md_header_shift(text, minlevel) ⇒ Object
Consistently shift all markdown headers - ### - so they would be at least minlevel deep.
- #nfirst(array, num) ⇒ Object
- #paragraphs(text, num) ⇒ Object
- #reflow(text) ⇒ Object
- #rouge(text) ⇒ Object
Instance Method Details
#md_header_shift(text, minlevel) ⇒ Object
Consistently shift all markdown headers - ### - so they would be at least minlevel deep
21 22 23 24 25 26 |
# File 'lib/whatthegem/template.rb', line 21 def md_header_shift(text, minlevel) current_min = text.scan(/^(\#+) /).flatten.map(&:length).min return text if !current_min || current_min > minlevel shift = minlevel - current_min text.gsub(/^(\#+) /, '#' * shift + '\\1 ') end |
#nfirst(array, num) ⇒ Object
16 17 18 |
# File 'lib/whatthegem/template.rb', line 16 def nfirst(array, num) array.first(num) end |
#paragraphs(text, num) ⇒ Object
7 8 9 10 |
# File 'lib/whatthegem/template.rb', line 7 def paragraphs(text, num) # split on markdown-alike paragraph break (\n\n), or "paragraph, then list" (\n* ) text.split(/\n(?:\n|(?= *\*))/).first(num).join("\n\n").gsub(/\n +/, "\n").strip end |
#reflow(text) ⇒ Object
12 13 14 |
# File 'lib/whatthegem/template.rb', line 12 def reflow(text) text.tr("\n", ' ') end |
#rouge(text) ⇒ Object
28 29 30 31 |
# File 'lib/whatthegem/template.rb', line 28 def rouge(text) lexer = Rouge::Lexers::Ruby.new Rouge::Formatters::Terminal256.new(Rouge::Themes::Base16::Monokai.new).format(lexer.lex(text)) end |