Sha256: 23ba833931ed4e411bc5ab48970828ee42531ed0799549874c622620369c28da

Contents?: true

Size: 979 Bytes

Versions: 8

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  class LiquidRenderer
    class FileSystem < Liquid::LocalFileSystem
      def read_template_file(template_path)
        load_paths = root
        found_paths = []

        load_paths.each do |load_path|
          # Use Liquid's gut checks to verify template pathname
          self.root = load_path
          full_template_path = full_path(template_path)

          # Look for .liquid as well as .html extensions
          path_variants = [
            Pathname.new(full_template_path),
            Pathname.new(full_template_path).sub_ext(".html"),
          ]

          found_paths << path_variants.find(&:exist?)
        end

        # Restore pristine state
        self.root = load_paths

        found_paths.compact!

        raise Liquid::FileSystemError, "No such template '#{template_path}'" if found_paths.empty?

        # Last path in the list wins
        ::File.read(found_paths.last)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bridgetown-core-0.12.1 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.12.0 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.11.2 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.11.1 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.11.0 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.10.2 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.10.1 lib/bridgetown-core/liquid_renderer/file_system.rb
bridgetown-core-0.10.0 lib/bridgetown-core/liquid_renderer/file_system.rb