module WhatTheGem::Template::Filters
Public Instance Methods
md_header_shift(text, minlevel)
click to toggle source
Consistently shift all markdown headers - ### - so they would be at least minlevel deep
# 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)
click to toggle source
# File lib/whatthegem/template.rb, line 16 def nfirst(array, num) array.first(num) end
paragraphs(text, num)
click to toggle source
# 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)
click to toggle source
# File lib/whatthegem/template.rb, line 12 def reflow(text) text.tr("\n", ' ') end
rouge(text)
click to toggle source
# 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