From 1b1fe27d75c1f4933138b7738a006749d7bba65c Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Fri, 31 Mar 2017 11:00:08 +0530 Subject: [PATCH] Re-surface missing public methods in `Jekyll::Document` (#5975) Merge pull request 5975 --- lib/jekyll/document.rb | 70 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 386683d6..a37ca1e4 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -3,10 +3,13 @@ module Jekyll class Document include Comparable + extend Forwardable attr_reader :path, :site, :extname, :collection attr_accessor :content, :output + def_delegator :self, :read_post_data, :post_read + YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m DATELESS_FILENAME_MATCHER = %r!^(?:.+/)*(.*)(\.[^.]+)$! DATE_FILENAME_MATCHER = %r!^(?:.+/)*(\d{2,4}-\d{1,2}-\d{1,2})-(.*)(\.[^.]+)$! @@ -375,6 +378,38 @@ module Jekyll data.key?(method.to_s) || super end + # Add superdirectories of the special_dir to categories. + # In the case of es/_posts, 'es' is added as a category. + # In the case of _posts/es, 'es' is NOT added as a category. + # + # Returns nothing. + def categories_from_path(special_dir) + superdirs = relative_path.sub(%r!#{special_dir}(.*)!, "") + .split(File::SEPARATOR) + .reject do |c| + c.empty? || c == special_dir || c == basename + end + merge_data!({ "categories" => superdirs }, :source => "file path") + end + + def populate_categories + merge_data!({ + "categories" => ( + Array(data["categories"]) + Utils.pluralized_array_from_hash( + data, + "category", + "categories" + ) + ).map(&:to_s).flatten.uniq, + }) + end + + def populate_tags + merge_data!({ + "tags" => Utils.pluralized_array_from_hash(data, "tag", "tags").flatten, + }) + end + private def merge_categories!(other) if other.key?("categories") && !other["categories"].nil? @@ -445,41 +480,6 @@ module Jekyll end end - # Add superdirectories of the special_dir to categories. - # In the case of es/_posts, 'es' is added as a category. - # In the case of _posts/es, 'es' is NOT added as a category. - # - # Returns nothing. - private - def categories_from_path(special_dir) - superdirs = relative_path.sub(%r!#{special_dir}(.*)!, "") - .split(File::SEPARATOR) - .reject do |c| - c.empty? || c == special_dir || c == basename - end - merge_data!({ "categories" => superdirs }, :source => "file path") - end - - private - def populate_categories - merge_data!({ - "categories" => ( - Array(data["categories"]) + Utils.pluralized_array_from_hash( - data, - "category", - "categories" - ) - ).map(&:to_s).flatten.uniq, - }) - end - - private - def populate_tags - merge_data!({ - "tags" => Utils.pluralized_array_from_hash(data, "tag", "tags").flatten, - }) - end - private def generate_excerpt if generate_excerpt?