class Ramble::BlogPost::MarkdownParser
Attributes
body[R]
contents_of_file[R]
preview[R]
title[R]
Public Class Methods
new(contents_of_file)
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 9 def initialize(contents_of_file) @contents_of_file = contents_of_file @title = parsed_title @body = parsed_body @preview = parsed_preview end
Private Instance Methods
document()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 20 def document @document ||= Nokogiri::HTML.parse(raw_html) end
extensions()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 51 def extensions { fenced_code_blocks: true } end
parsed_body()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 30 def parsed_body document.search("//body").children.to_html end
parsed_preview()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 34 def parsed_preview document.search("//p").first.text end
parsed_title()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 24 def parsed_title return @parsed_title if @parsed_title heading = document.search("//h1").first.remove @parsed_title = heading.to_html.match(/<h1>(.*)<\/h1>/)[1] end
raw_html()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 38 def raw_html Redcarpet::Markdown.new(renderer, extensions). render(contents_of_file) end
render_options()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 43 def render_options { hard_wrap: true } end
renderer()
click to toggle source
# File lib/ramble/blog_post/markdown_parser.rb, line 47 def renderer @renderer ||= Redcarpet::Render::HTML.new(render_options) end