Module: GollumRails::Meta

Extended by:
ActiveSupport::Concern
Included in:
Page
Defined in:
lib/gollum_rails/meta.rb

Instance Method Summary collapse

Instance Method Details

#has_yaml?Boolean

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

Returns:

  • (Boolean)

18
19
20
# File 'lib/gollum_rails/meta.rb', line 18

def has_yaml?
  !!raw_meta
end

#html_without_yamlObject

Gets the parsed html without the YAML part

Returns a string


52
53
54
# 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

#metaObject

Gets the parsed meta data

Returns parsed YAML


34
35
36
37
38
# File 'lib/gollum_rails/meta.rb', line 34

def meta
  @meta ||= YAML.load(raw_meta)
rescue Psych::SyntaxError => e
  {error: e}
end

#meta_titleObject

Example for meta data usage:

Gets the title from the meta data

Returns the title or nil


45
46
47
# File 'lib/gollum_rails/meta.rb', line 45

def meta_title
  meta['title']
end

#raw_metaObject

Gets the pages raw Yaml header.

Returns either the raw yaml or an empty string


26
27
28
# File 'lib/gollum_rails/meta.rb', line 26

def raw_meta
  raw_data.match(/^(?<headers>---\s*\n.*?\n?)^(---\s*$\n?)/m).to_s
end