Class: ContentDirectory::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/content_directory/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/content_directory/entry.rb', line 6

def 
  @metadata
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/content_directory/entry.rb', line 6

def path
  @path
end

#textObject (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

#htmlObject



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