Module: Locomotive::Steam::Adapters::Filesystem::YAMLLoader

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#site_pathObject (readonly)

Returns the value of attribute site_path.



7
8
9
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 7

def site_path
  @site_path
end

Instance Method Details

#_load(path, frontmatter = false, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 21

def _load(path, frontmatter = false, &block)
  if File.exists?(path)
    yaml      = File.open(path).read.force_encoding('utf-8')
    template  = nil

    if frontmatter && match = yaml.match(FRONTMATTER_REGEXP)
      yaml, template = match[:yaml], match[:template]
    end

    safe_yaml_load(yaml, template, path, &block)
  else
    Locomotive::Common::Logger.error "No #{path} file found"
    {}
  end
end

#default_localeObject



17
18
19
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 17

def default_locale
  @scope.default_locale
end

#initialize(site_path) ⇒ Object



9
10
11
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 9

def initialize(site_path)
  @site_path = site_path
end

#load(scope = nil) ⇒ Object



13
14
15
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 13

def load(scope = nil)
  @scope = scope
end

#safe_yaml_load(yaml, template, path, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 37

def safe_yaml_load(yaml, template, path, &block)
  return {} if yaml.blank?

  begin
    HashConverter.to_sym(YAML.load(yaml)).tap do |attributes|
      block.call(attributes, template) if block_given?
    end
  rescue Exception => e
    raise "Malformed YAML in this file #{path}, error: #{e.message}"
  end
end

#template_extensionsObject



49
50
51
# File 'lib/locomotive/steam/adapters/filesystem/yaml_loader.rb', line 49

def template_extensions
  @extensions ||= %w(liquid haml)
end