class Artifact::MarkdownFile

Public Instance Methods

author() click to toggle source
# File lib/artifact.rb, line 360
def author
  data['author']
end
category() click to toggle source
# File lib/artifact.rb, line 364
def category
  data['category']
end
content() click to toggle source
# File lib/artifact.rb, line 385
def content
  parts[1..-1].join("---\n\n")
end
data() click to toggle source
# File lib/artifact.rb, line 389
def data
  @data ||= YAML.load(parts[0])
rescue Psych::SyntaxError => e
  raise "Invalid YAML at #{path}: #{parts[0]}"
end
date() click to toggle source
# File lib/artifact.rb, line 356
def date
  data['date']
end
last_updated_by() click to toggle source
# File lib/artifact.rb, line 368
def last_updated_by
  data['last_updated_by']
end
parts() click to toggle source
# File lib/artifact.rb, line 395
def parts
  read.split("---\n\n")
end
sanitized_meta(hash) click to toggle source

include existing date and author in yaml hash in case they're not set

# File lib/artifact.rb, line 400
def sanitized_meta(hash)
  hash.stringify_keys!
  if exists?
    %w(date author).each do |key|
      hash[key] = self.send(key) if !hash[key] and self.send(key)
    end
  end
  hash.to_yaml
end
title() click to toggle source
# File lib/artifact.rb, line 352
def title
  data['title']
end
update(content, meta = {}) click to toggle source
Calls superclass method Artifact::WritableFile#update
# File lib/artifact.rb, line 372
def update(content, meta = {})
  yaml_data = sanitized_meta(meta) # insert date and author if missing
  body = "#{yaml_data}---\n\n#{content}"
  super(body)
  @data = nil # force reload
end
update_meta(key, val) click to toggle source
# File lib/artifact.rb, line 379
def update_meta(key, val)
  hash = {}
  hash[key.to_s] = val
  update(content, data.merge(hash))
end