class Impression::Pages::Page
Constants
- PAGE_REGEXP
- TITLE_REGEXP
Public Class Methods
new(path, full_path, opts = {})
click to toggle source
# File lib/impression/pages.rb, line 55 def initialize(path, full_path, opts = {}) @path = path @full_path = full_path @opts = opts read_page end
Public Instance Methods
kramdown_options()
click to toggle source
# File lib/impression/pages.rb, line 102 def kramdown_options { entity_output: :numeric, syntax_highlighter: :rouge, input: 'GFM' } end
path_without_extension()
click to toggle source
# File lib/impression/pages.rb, line 80 def path_without_extension "/#{File.basename(@path, File.extname(@path))}" end
read_page()
click to toggle source
# File lib/impression/pages.rb, line 64 def read_page data = IO.read(@full_path) || '' if data =~ PAGE_REGEXP front_matter = Regexp.last_match(1) @attributes = YAML.load(front_matter) @content = Regexp.last_match.post_match else @attributes = {} @content = data end end
relative_permalink()
click to toggle source
# File lib/impression/pages.rb, line 76 def relative_permalink @relative_permalink = @attributes[:permalink] || path_without_extension end
render_html()
click to toggle source
# File lib/impression/pages.rb, line 110 def render_html inner = Kramdown::Document.new(@content, **kramdown_options).to_html "<!doctype html><html><body>#{inner}</body></html>" end
status()
click to toggle source
# File lib/impression/pages.rb, line 94 def status @attributes['status'] || Qeweney::Status::OK end
title()
click to toggle source
# File lib/impression/pages.rb, line 84 def title @attributes['title'] || title_from_content end
title_from_content()
click to toggle source
# File lib/impression/pages.rb, line 90 def title_from_content (@content =~ TITLE_REGEXP) && Regexp.last_match(1) end
to_html()
click to toggle source
# File lib/impression/pages.rb, line 98 def to_html @html ||= render_html end