class Jekyll::VersionedFiles::FrontMatter

Constants

FRONTMATTER_REGEXP

Attributes

content[RW]
data[RW]
frontmatter[RW]
new_data[RW]

Public Class Methods

new(new_data) click to toggle source

Initialize FileDocument.

Returns nothing.

# File lib/jekyll/versioned_files/frontmatter.rb, line 18
def initialize(new_data)
  @data     = {} 
  @fm_mods  = VersionedFiles.frontmatter
  @new_data = new_data || {}
end

Public Instance Methods

create() click to toggle source

Creates a new Front matter block

Returns content with updated Front Matter

# File lib/jekyll/versioned_files/frontmatter.rb, line 36
def create
  merge_data  
  to_frontmatter 
end
update() click to toggle source

Updates the content's Front Matter

Returns content with updated Front Matter

# 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

Private Instance Methods

merge_data() click to toggle source
# File lib/jekyll/versioned_files/frontmatter.rb, line 42
def merge_data
  @new_data.each do |k,v|
    next if !@fm_mods[k]
    @data[@fm_mods[k]] = v # @new_data[k]
  end
end
mod_key(key) click to toggle source
# File lib/jekyll/versioned_files/frontmatter.rb, line 60
def mod_key(key)
  if frontmatter
    @data = SafeYAML.load(frontmatter[1].sub!(/#{key}/, @fm_mods[key]))
  end
end
to_data(content) click to toggle source
# File lib/jekyll/versioned_files/frontmatter.rb, line 55
def to_data(content)
  @data = SafeYAML.load(content) unless content.nil?
end
to_frontmatter() click to toggle source
# File lib/jekyll/versioned_files/frontmatter.rb, line 50
def to_frontmatter
  @data.to_yaml + "---\n\n"
end