diff --git a/lib/jekyll/collection.rb b/lib/jekyll/collection.rb index 9faffaab..4363aee1 100644 --- a/lib/jekyll/collection.rb +++ b/lib/jekyll/collection.rb @@ -23,12 +23,21 @@ module Jekyll @docs ||= [] end - [:sort, :sort!, :each, :[], :reject, :first, :last, :size, :length].each do |method| - class_eval %Q" - def #{method}(*args, &blk) - docs.#{method}(*args, &blk) - end - " + # Override of normal respond_to? to match method_missing's logic for + # looking in @data. + def respond_to?(method, include_private = false) + docs.respond_to?(method.to_sym, include_private) || super + end + + # Override of method_missing to check in @data for the key. + def method_missing(method, *args, &blck) + if docs.respond_to?(method.to_sym) + Jekyll.logger.warn "Deprecation:", "Collection##{method} should be called on the #docs array directly." + Jekyll.logger.warn "", "Called by #{caller.first}." + docs.public_send(method.to_sym, *args, &blck) + else + super + end end # Fetch the static files in this collection. diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 9dbc4cee..46ff7e86 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -431,5 +431,22 @@ module Jekyll def related_posts Jekyll::RelatedPosts.new(self).build end + + # Override of normal respond_to? to match method_missing's logic for + # looking in @data. + def respond_to?(method, include_private = false) + data.key?(method.to_s) || super + end + + # Override of method_missing to check in @data for the key. + def method_missing(method, *args, &blck) + if data.key?(method.to_s) + Jekyll.logger.warn "Deprecation:", "Document##{method} is now a key in the #data hash." + Jekyll.logger.warn "", "Called by #{caller.first}." + data[method.to_s] + else + super + end + end end end diff --git a/lib/jekyll/reader.rb b/lib/jekyll/reader.rb index 149a7a7a..45a20422 100644 --- a/lib/jekyll/reader.rb +++ b/lib/jekyll/reader.rb @@ -22,7 +22,7 @@ module Jekyll # Sorts posts, pages, and static files. def sort_files! - site.collections.values.each(&:sort!) + site.collections.values.each{|c| c.docs.sort!} site.pages.sort_by!(&:name) site.static_files.sort_by!(&:relative_path) end diff --git a/lib/jekyll/related_posts.rb b/lib/jekyll/related_posts.rb index f7dc0962..fbc2837b 100644 --- a/lib/jekyll/related_posts.rb +++ b/lib/jekyll/related_posts.rb @@ -14,7 +14,7 @@ module Jekyll end def build - return [] unless site.posts.size > 1 + return [] unless site.posts.docs.size > 1 if site.lsi build_index @@ -30,7 +30,7 @@ module Jekyll lsi = ClassifierReborn::LSI.new(:auto_rebuild => false) display("Populating LSI...") - site.posts.each do |x| + site.posts.docs.each do |x| lsi.add_item(x) end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 66bfd163..2384ea17 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -222,7 +222,7 @@ module Jekyll # Build a hash map based on the specified post attribute ( post attr => # array of posts ) then sort each array in reverse order. hash = Hash.new { |h, key| h[key] = [] } - posts.each { |p| p.data[post_attr].each { |t| hash[t] << p } } + posts.docs.each { |p| p.data[post_attr].each { |t| hash[t] << p } } hash.values.each { |posts| posts.sort!.reverse! } hash end @@ -265,7 +265,7 @@ module Jekyll "site" => Utils.deep_merge_hashes(config, Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], { "time" => time, - "posts" => posts.sort { |a, b| b <=> a }, + "posts" => posts.docs.sort { |a, b| b <=> a }, "pages" => pages, "static_files" => static_files, "html_pages" => pages.select { |page| page.html? || page.url.end_with?("/") }, @@ -333,7 +333,7 @@ module Jekyll end def each_site_file - %w(posts pages static_files docs_to_write).each do |type| + %w(pages static_files docs_to_write).each do |type| send(type).each do |item| yield item end