Sha256: c5eed659f9114e29a33284120957f205c6498e0d34a6593f5123e06214a1951f

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Bridgetown
  class LayoutReader
    attr_reader :site

    def initialize(site)
      @site = site
      @layouts = HashWithDotAccess::Hash.new
    end

    def read
      layout_entries.each do |layout_file|
        @layouts[layout_name(layout_file)] = \
          Layout.new(site, layout_directory, layout_file)
      end

      Bridgetown::PluginManager.source_manifests.map(&:layouts).compact.each do |plugin_layouts|
        layout_entries(plugin_layouts).each do |layout_file|
          @layouts[layout_name(layout_file)] ||= \
            Layout.new(site, plugin_layouts, layout_file, from_plugin: true)
        end
      end

      @layouts
    end

    def layout_directory
      @layout_directory ||= site.in_source_dir(site.config["layouts_dir"])
    end

    private

    def layout_entries(dir = layout_directory)
      entries_in dir
    end

    def entries_in(dir)
      entries = []
      within(dir) do
        entries = EntryFilter.new(site).filter(Dir["**/*.*"])
      end
      entries
    end

    def layout_name(file)
      file.split(".")[0..-2].join(".")
    end

    def within(directory)
      return unless File.exist?(directory)

      Dir.chdir(directory) { yield }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bridgetown-core-0.21.0.beta3 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.21.0.beta2 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.21.0.beta1 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.20.0 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.19.3 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.19.2 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.19.1 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.19.0 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.18.6 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.18.5 lib/bridgetown-core/readers/layout_reader.rb
bridgetown-core-0.18.4 lib/bridgetown-core/readers/layout_reader.rb