Sha256: 9f6f949168a34610b8149d4b1469e889cf541701dfab22d92c7f3f007ad1d6d5

Contents?: true

Size: 1.33 KB

Versions: 31

Compression:

Stored size: 1.33 KB

Contents

module Locomotive::Steam
  module Adapters
    module Filesystem

      module YAMLLoader

        attr_reader :site_path

        def initialize(site_path)
          @site_path = site_path
        end

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

        def default_locale
          @scope.default_locale
        end

        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

        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

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

      end

    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.1.2 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.1.1 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.1.0 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.1.0.rc3 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
locomotivecms_steam-1.1.0.rc2 lib/locomotive/steam/adapters/filesystem/yaml_loader.rb