Sha256: 43bd0b171f105638f6b10baa57a7d5a556893ecae9b998d741cfc54e2fd28d6c

Contents?: true

Size: 1.06 KB

Versions: 25

Compression:

Stored size: 1.06 KB

Contents

module Jekyll
  class LayoutReader
    attr_reader :site
    def initialize(site)
      @site = site
      @layouts = {}
    end

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

      @layouts
    end

    def layout_directory
      @layout_directory ||= (layout_directory_in_cwd || layout_directory_inside_source)
    end

    private

    def layout_entries
      entries = []
      within(layout_directory) 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

    def layout_directory_inside_source
      site.in_source_dir(site.config['layouts_dir'])
    end

    def layout_directory_in_cwd
      dir = Jekyll.sanitized_path(Dir.pwd, site.config['layouts_dir'])
      if File.directory?(dir) && !site.safe
        dir
      else
        nil
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
jekyll-3.0.1 lib/jekyll/readers/layout_reader.rb
jekyll-3.0.0 lib/jekyll/readers/layout_reader.rb
jekyll-3.0.0.pre.rc1 lib/jekyll/readers/layout_reader.rb
jekyll-3.0.0.pre.beta10 lib/jekyll/readers/layout_reader.rb
jekyll-3.0.0.pre.beta9 lib/jekyll/readers/layout_reader.rb