Module: Luo::Helpers
Defined Under Namespace
Classes: HTMLwithRouge
Instance Method Summary collapse
- #display_html(text) ⇒ Object
- #display_md(text) ⇒ Object
- #gem_exists?(gem_name) ⇒ Boolean
- #load_test(path, &block) ⇒ Object
- #print_md(text) ⇒ Object
Instance Method Details
#display_html(text) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/luo/helpers.rb', line 41 def display_html(text) unless gem_exists?('iruby') raise "Please install iruby gem first." end IRuby.display(IRuby.html(text)) end |
#display_md(text) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/luo/helpers.rb', line 22 def display_md(text) renderer = HTMLwithRouge.new markdown = Redcarpet::Markdown.new(renderer, autolink: true, tables: true, strikethrough: true, highlight: true, prettify: true, fenced_code_blocks: true) body = markdown.render(text) css = Rouge::Themes::Github.mode(:light).render(scope: '.highlight') html = " <style>\#{css}</style>\n \#{body}\n HTML\n # puts html\n IRuby.display(IRuby.html(html))\nend\n" |
#gem_exists?(gem_name) ⇒ Boolean
59 60 61 62 63 64 |
# File 'lib/luo/helpers.rb', line 59 def gem_exists?(gem_name) Gem::Specification.find_by_name(gem_name) true rescue Gem::LoadError false end |
#load_test(path, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/luo/helpers.rb', line 48 def load_test(path, &block) data = YAML.load_file(path) if data.is_a?(Array) data.each do |value| yield(value) end else yield(data) end end |
#print_md(text) ⇒ Object
18 19 20 |
# File 'lib/luo/helpers.rb', line 18 def print_md(text) puts TTY::Markdown.parse(text) end |