class Forematter::FileWrapper
Attributes
filename[R]
Public Class Methods
new(filename)
click to toggle source
# File lib/forematter/file_wrapper.rb, line 7 def initialize(filename) fail Forematter::UnexpectedValue, "File not found: #{filename}" unless File.file?(filename) @filename = filename end
Public Instance Methods
content()
click to toggle source
# File lib/forematter/file_wrapper.rb, line 24 def content parse_file @content end
to_s()
click to toggle source
# File lib/forematter/file_wrapper.rb, line 16 def to_s "#{meta.to_yaml}---\n#{content}" end
write()
click to toggle source
# File lib/forematter/file_wrapper.rb, line 20 def write File.open(filename, 'w+') { |f| f << to_s } end
Protected Instance Methods
meta()
click to toggle source
# File lib/forematter/file_wrapper.rb, line 31 def meta parse_file @meta end
parse_file()
click to toggle source
# File lib/forematter/file_wrapper.rb, line 36 def parse_file return if @is_parsed data = '--- {}' content = IO.read(@filename) if content =~ /\A(---\s*\n.*?\n?)^(?:(?:---|\.\.\.)\s*$\n?)/m data = Regexp.last_match[1] content = $POSTMATCH end @meta = Forematter::Frontmatter.new(data) @content = content @is_parsed = true end