Class: Locomotive::Mounter::Utils::YAMLFrontMattersTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/mounter/utils/yaml_front_matters_template.rb

Overview

YAML Front-matters for HAML/Liquid templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ YAMLFrontMattersTemplate

Returns a new instance of YAMLFrontMattersTemplate.



10
11
12
13
14
15
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 10

def initialize(filepath)
  self.filepath     = filepath
  self.line_offset  = 0

  self.fetch_attributes_and_raw_source(File.read(self.filepath))
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 8

def attributes
  @attributes
end

#filepathObject

Returns the value of attribute filepath.



8
9
10
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 8

def filepath
  @filepath
end

#line_offsetObject

Returns the value of attribute line_offset.



8
9
10
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 8

def line_offset
  @line_offset
end

#raw_sourceObject

Returns the value of attribute raw_source.



8
9
10
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 8

def raw_source
  @raw_source
end

Instance Method Details

#sourceObject



17
18
19
20
21
22
23
24
25
# File 'lib/locomotive/mounter/utils/yaml_front_matters_template.rb', line 17

def source
  return @source if @source

  @source = if self.filepath.ends_with?('.haml')
    Haml::Engine.new(self.raw_source).render
  else
    self.raw_source
  end
end