Module: AllCollectionsHooks
- Included in:
- JekyllAllCollections
- Defined in:
- lib/all_collections_hooks.rb
Overview
Creates an array of ‘APage` called site.all_collections, which will be available from :site, :pre_render onwards
Defined Under Namespace
Classes: APage
Class Method Summary collapse
- .all_collections_defined?(site) ⇒ Boolean
-
.apages_from_objects(objects) ⇒ Object
The collection value is just the collection label, not the entire collection object.
-
.compute(site) ⇒ Object
Yes, all_collections is defined for this hook Jekyll::Hooks.register(:site, :pre_render, priority: :normal) do |site, _payload| defined = AllCollectionsHooks.all_collections_defined?(site) @logger.debug { “Jekyll::Hooks.register(:site, :pre_render: #defined” } end.
Class Method Details
.all_collections_defined?(site) ⇒ Boolean
64 65 66 |
# File 'lib/all_collections_hooks.rb', line 64 def self.all_collections_defined?(site) "site.all_collections #{site.class.method_defined?(:all_collections) ? 'IS' : 'IS NOT'} defined" end |
.apages_from_objects(objects) ⇒ Object
The collection value is just the collection label, not the entire collection object
55 56 57 58 59 60 61 62 |
# File 'lib/all_collections_hooks.rb', line 55 def self.apages_from_objects(objects) pages = [] objects.each do |object| page = APage.new(object) pages << page unless page.data['exclude_from_all'] end pages end |
.compute(site) ⇒ Object
Yes, all_collections is defined for this hook Jekyll::Hooks.register(:site, :pre_render, priority: :normal) do |site, _payload|
defined = AllCollectionsHooks.all_collections_defined?(site)
@logger.debug { "Jekyll::Hooks.register(:site, :pre_render: #{defined}" }
end
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/all_collections_hooks.rb', line 41 def self.compute(site) objects = site.collections .values .map { |x| x.class.method_defined?(:docs) ? x.docs : x } .flatten site.class.module_eval { attr_accessor :all_collections } apages = AllCollectionsHooks.apages_from_objects(objects) site.all_collections = apages end |