Class: Marsdawn::Source::Document
- Inherits:
-
Kramdown::Document
- Object
- Kramdown::Document
- Marsdawn::Source::Document
- Defined in:
- lib/marsdawn/source/document.rb
Instance Attribute Summary collapse
-
#front_matter ⇒ Object
Returns the value of attribute front_matter.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, options = {}) ⇒ Document
constructor
A new instance of Document.
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, ={} doc = FrontMatter.new(text) @front_matter = {} [:input] = 'Marsdawn' super doc.content, @front_matter.merge! Kramdown::Parser::Marsdawn.front_matter @front_matter.merge! doc.attr end |
Instance Attribute Details
#front_matter ⇒ Object
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, ={} text = open(path).read new(text, ).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 |