Class: Marsdawn::Source::Document

Inherits:
Kramdown::Document
  • Object
show all
Defined in:
lib/marsdawn/source/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, options = {}) ⇒ Document

Returns a new instance of Document.



22
23
24
25
26
27
28
29
# File 'lib/marsdawn/source/document.rb', line 22

def initialize text, options={}
  doc = FrontMatter.new(text)
  @front_matter = {}
  options[:input] = 'Marsdawn'
  super doc.content, options
  @front_matter.merge! Kramdown::Parser::Marsdawn.front_matter
  @front_matter.merge! doc.attr
end

Instance Attribute Details

#front_matterObject

Returns the value of attribute front_matter.



10
11
12
# File 'lib/marsdawn/source/document.rb', line 10

def front_matter
  @front_matter
end

Class Method Details

.read(path, title = nil, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/marsdawn/source/document.rb', line 12

def self.read path, title=nil, options={}
  text = open(path).read
  new(text, options).tap do |doc|
    title = File.basename(path, '.*') if title.nil?
    title = title.gsub(/^\d+_/, '').gsub(/_|-/, ' ').capitalize
    doc.front_matter[:title] ||= title
    doc.front_matter[:link_key] ||= title
  end
end