Class: Tilt::YamlFrontMattersHamlTemplate

Inherits:
HamlTemplate
  • Object
show all
Defined in:
lib/locomotive/mounter/extensions/tilt/haml.rb

Overview

YAML Front-matters for HAML templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Attributes from YAML Front-matters header



7
8
9
# File 'lib/locomotive/mounter/extensions/tilt/haml.rb', line 7

def attributes
  @attributes
end

Instance Method Details

#need_for_prerendering?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/locomotive/mounter/extensions/tilt/haml.rb', line 9

def need_for_prerendering?
  true
end

#prepareObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/locomotive/mounter/extensions/tilt/haml.rb', line 13

def prepare
  if data =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)(.*)/m
    @attributes = YAML.load($1)
    @data = $3
  end
  @data = @data.force_encoding('utf-8')
  begin
    super
  rescue Haml::SyntaxError => e
    # invalid haml so re-throw the exception but with keeping track of the attributes
    e.attributes = @attributes
    raise e
  end
end