Class: Jekyll::VersionedFiles::FrontMatter

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/versioned_files/frontmatter.rb

Constant Summary collapse

FRONTMATTER_REGEXP =
%r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_data) ⇒ FrontMatter

Initialize FileDocument.

Returns nothing.



18
19
20
21
22
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 18

def initialize(new_data)
  @data     = {} 
  @fm_mods  = VersionedFiles.frontmatter
  @new_data = new_data || {}
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 4

def content
  @content
end

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 4

def data
  @data
end

#frontmatterObject

Returns the value of attribute frontmatter.



4
5
6
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 4

def frontmatter
  @frontmatter
end

#new_dataObject

Returns the value of attribute new_data.



4
5
6
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 4

def new_data
  @new_data
end

Instance Method Details

#createObject

Creates a new Front matter block

Returns content with updated Front Matter



36
37
38
39
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 36

def create
  merge_data  
  to_frontmatter 
end

#updateObject

Updates the content’s Front Matter

Returns content with updated Front Matter



27
28
29
30
31
# File 'lib/jekyll/versioned_files/frontmatter.rb', line 27

def update
  mod_key("permalink") if data.has_key?("permalink") && @fm_mods["permalink"]
  merge_data
  @content.sub!(FRONTMATTER_REGEXP, to_frontmatter) || @content
end