Class: ContentDirectory::Entry
- Inherits:
-
Object
- Object
- ContentDirectory::Entry
- Defined in:
- lib/content_directory/entry.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #html ⇒ Object
-
#initialize(path) ⇒ Entry
constructor
A new instance of Entry.
Constructor Details
#initialize(path) ⇒ Entry
Returns a new instance of Entry.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/content_directory/entry.rb', line 8 def initialize(path) @path = path @text = File.read "#{ContentDirectory.root}/#{@path}" @metadata, @text = @text.split("\n\n", 2) begin @metadata = YAML.load @metadata rescue Exception => e @metadata = nil end end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/content_directory/entry.rb', line 6 def @metadata end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/content_directory/entry.rb', line 6 def path @path end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/content_directory/entry.rb', line 6 def text @text end |
Instance Method Details
#html ⇒ Object
20 21 22 23 24 25 |
# File 'lib/content_directory/entry.rb', line 20 def html return nil unless @text markdown = Redcarpet::Markdown.new Redcarpet::Render::HTML html = markdown.render @text Redcarpet::Render::SmartyPants.render html end |