module GollumRails::Meta

Public Instance Methods

has_yaml?() click to toggle source

Checks if this page has a Yaml part

Example YAML part:


title: “My Page”


YAML part is seperated from the rest by `—` before and after the content

Returns true or false

# File lib/gollum_rails/meta.rb, line 18
def has_yaml?
  !!raw_meta
end
html_without_yaml() click to toggle source

Gets the parsed html without the YAML part

Returns a string

# File lib/gollum_rails/meta.rb, line 52
def html_without_yaml
  gollum_page.markup_class.render(raw_data.tap{|s| s.slice!(raw_meta.to_s)})
end
meta() click to toggle source

Gets the parsed meta data

Returns parsed YAML

# File lib/gollum_rails/meta.rb, line 34
def meta
  @meta ||= YAML.load(raw_meta)
rescue Psych::SyntaxError => e
  {error: e}
end
meta_title() click to toggle source

Example for meta data usage:

Gets the title from the meta data

Returns the title or nil

# File lib/gollum_rails/meta.rb, line 45
def meta_title
  meta['title']
end
raw_meta() click to toggle source

Gets the pages raw Yaml header.

Returns either the raw yaml or an empty string

# File lib/gollum_rails/meta.rb, line 26
def raw_meta
  raw_data.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m).to_s
end