Sha256: 0e48bec389863a987ab9efd924b61d5262231484ed537aee1adffd93fcb33840

Contents?: true

Size: 1.89 KB

Versions: 15

Compression:

Stored size: 1.89 KB

Contents

module Jekyll
  class PostReader
    attr_reader :site, :unfiltered_content
    def initialize(site)
      @site = site
    end

    # Read all the files in <source>/<dir>/_drafts and create a new
    # Document object with each one.
    #
    # dir - The String relative path of the directory to read.
    #
    # Returns nothing.
    def read_drafts(dir)
      read_publishable(dir, '_drafts', Document::DATELESS_FILENAME_MATCHER)
    end

    # Read all the files in <source>/<dir>/_posts and create a new Document
    # object with each one.
    #
    # dir - The String relative path of the directory to read.
    #
    # Returns nothing.
    def read_posts(dir)
      read_publishable(dir, '_posts', Document::DATE_FILENAME_MATCHER)
    end

    # Read all the files in <source>/<dir>/<magic_dir> and create a new
    # Document object with each one insofar as it matches the regexp matcher.
    #
    # dir - The String relative path of the directory to read.
    #
    # Returns nothing.
    def read_publishable(dir, magic_dir, matcher)
      read_content(dir, magic_dir, matcher).tap do |docs|
        docs.each(&:read)
      end.select do |doc|
        site.publisher.publish?(doc)
      end
    end

    # Read all the content files from <source>/<dir>/magic_dir
    #   and return them with the type klass.
    #
    # dir - The String relative path of the directory to read.
    # magic_dir - The String relative directory to <dir>,
    #   looks for content here.
    # klass - The return type of the content.
    #
    # Returns klass type of content files
    def read_content(dir, magic_dir, matcher)
      @site.reader.get_entries(dir, magic_dir).map do |entry|
        next unless entry =~ matcher
        path = @site.in_source_dir(File.join(dir, magic_dir, entry))
        Document.new(path, {
          :site => @site,
          :collection => @site.posts
        })
      end.reject(&:nil?)
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
blackboard-3.1.9 lib/jekyll/readers/post_reader.rb
blackboard-3.1.8 lib/jekyll/readers/post_reader.rb
blackboard-3.1.7 lib/jekyll/readers/post_reader.rb
jekyll-3.1.6 lib/jekyll/readers/post_reader.rb
jekyll-3.1.5 lib/jekyll/readers/post_reader.rb
jekyll-3.1.4 lib/jekyll/readers/post_reader.rb
jekyll-3.1.3 lib/jekyll/readers/post_reader.rb
jekyll-3.1.2 lib/jekyll/readers/post_reader.rb
jekyllplusadmin-1.1.0 lib/jekyll/readers/post_reader.rb
jekyllplusadmin-1.0.0 lib/jekyll/readers/post_reader.rb
jekyll-3.1.1 lib/jekyll/readers/post_reader.rb
jekyll-3.1.0 lib/jekyll/readers/post_reader.rb
jekyll-3.1.0.pre.rc3 lib/jekyll/readers/post_reader.rb
jekyll-3.1.0.pre.rc2 lib/jekyll/readers/post_reader.rb
jekyll-3.1.0.pre.rc1 lib/jekyll/readers/post_reader.rb