class Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Snippet

Public Instance Methods

load(scope) click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 11
def load(scope)
  super
  load_list
end

Private Instance Methods

build(filepath, slug, locale) click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 34
def build(filepath, slug, locale)
  {
    name:           slug.humanize,
    slug:           slug,
    template_path:  { locale => filepath }
  }
end
each_file() { |filepath, permalink, to_sym| ... } click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 46
def each_file(&block)
  Dir.glob(File.join(path, "*.{#{template_extensions.join(',')}}")).each do |filepath|
    slug, locale = File.basename(filepath).split('.')[0..1]
    locale = default_locale if template_extensions.include?(locale)

    yield(filepath, slug.permalink, locale.to_sym)
  end
end
load_list() click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 18
def load_list
  {}.tap do |hash|
    each_file do |filepath, slug, locale|
      _locale = locale || default_locale

      if element = hash[slug]
        update(element, filepath, _locale)
      else
        element = build(filepath, slug, _locale)
      end

      hash[slug] = element
    end
  end.values
end
path() click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 55
def path
  @path ||= File.join(site_path, 'app', 'views', 'snippets')
end
update(element, filepath, locale) click to toggle source
# File lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb, line 42
def update(element, filepath, locale)
  element[:template_path][locale] = filepath
end