Class: Artifact::MarkdownFile
Instance Attribute Summary
Attributes inherited from ReadableFile
#full_path, #path
Instance Method Summary
collapse
#delete, #save
#body, #dirname, #exists?, #filename, #initialize, #last_modified, #meta, #slug
Instance Method Details
#author ⇒ Object
360
361
362
|
# File 'lib/artifact.rb', line 360
def author
data['author']
end
|
#category ⇒ Object
364
365
366
|
# File 'lib/artifact.rb', line 364
def category
data['category']
end
|
#content ⇒ Object
385
386
387
|
# File 'lib/artifact.rb', line 385
def content
parts[1..-1].join("---\n\n")
end
|
#data ⇒ Object
389
390
391
392
393
|
# 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 ⇒ Object
356
357
358
|
# File 'lib/artifact.rb', line 356
def date
data['date']
end
|
#last_updated_by ⇒ Object
368
369
370
|
# File 'lib/artifact.rb', line 368
def last_updated_by
data['last_updated_by']
end
|
#parts ⇒ Object
395
396
397
|
# File 'lib/artifact.rb', line 395
def parts
read.split("---\n\n")
end
|
include existing date and author in yaml hash in case they’re not set
400
401
402
403
404
405
406
407
408
|
# 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 ⇒ Object
352
353
354
|
# File 'lib/artifact.rb', line 352
def title
data['title']
end
|
#update(content, meta = {}) ⇒ Object
372
373
374
375
376
377
|
# File 'lib/artifact.rb', line 372
def update(content, meta = {})
yaml_data = sanitized_meta(meta) body = "#{yaml_data}---\n\n#{content}"
super(body)
@data = nil end
|
379
380
381
382
383
|
# File 'lib/artifact.rb', line 379
def update_meta(key, val)
hash = {}
hash[key.to_s] = val
update(content, data.merge(hash))
end
|