Module: AllCollectionsHooks

Included in:
JekyllAllCollections
Defined in:
lib/hooks/a_page.rb,
lib/hooks/class_methods.rb,
lib/hooks/all_collections_hooks.rb

Defined Under Namespace

Classes: APage

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.all_collectionsObject

Returns the value of attribute all_collections.



3
4
5
# File 'lib/hooks/class_methods.rb', line 3

def all_collections
  @all_collections
end

.all_documentsObject

Returns the value of attribute all_documents.



3
4
5
# File 'lib/hooks/class_methods.rb', line 3

def all_documents
  @all_documents
end

.everythingObject

Returns the value of attribute everything.



3
4
5
# File 'lib/hooks/class_methods.rb', line 3

def everything
  @everything
end

.loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/hooks/all_collections_hooks.rb', line 3

def logger
  @logger
end

.sorted_lru_filesObject

Returns the value of attribute sorted_lru_files.



3
4
5
# File 'lib/hooks/class_methods.rb', line 3

def sorted_lru_files
  @sorted_lru_files
end

Class Method Details

.all_collections_defined?(site) ⇒ String

Returns indicating if :all_collections is defined or not.

Returns:

  • (String)

    indicating if :all_collections is defined or not



9
10
11
# File 'lib/hooks/class_methods.rb', line 9

def self.all_collections_defined?(site)
  "site.all_collections #{site.class.method_defined?(:all_collections) ? 'IS' : 'IS NOT'} defined"
end

.apages_from_objects(objects, origin) ⇒ Object

Create Array of AllCollectionsHooks::APage from objects

Parameters:

  • objects (Array)

    An array of Jekyll::Document, Jekyll::Page or file names

  • origin (String)

    Indicates type of objects being passed



16
17
18
19
20
21
22
23
# File 'lib/hooks/class_methods.rb', line 16

def self.apages_from_objects(objects, origin)
  pages = []
  objects.each do |object|
    page = APage.new(object, origin)
    pages << page unless page.data['exclude_from_all'] || page.path == 'redirect.html'
  end
  pages
end

.compute(site) ⇒ Object

Called by early, high-priority hook. Computes site.all_collections, site.all_documents, site.everything, and site.sorted_lru_files



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hooks/class_methods.rb', line 27

def self.compute(site)
  site.class.module_eval { attr_accessor :all_collections, :all_documents, :everything, :sorted_lru_files }

  documents = site.collections
                  .values
                  .map { |x| x.class.method_defined?(:docs) ? x.docs : x }
                  .flatten
                  .compact
  @all_collections = AllCollectionsHooks.apages_from_objects(documents, 'collection')
  @all_documents   = @all_collections +
                     AllCollectionsHooks.apages_from_objects(site.pages, 'individual_page')
  @everything      = @all_documents +
                     AllCollectionsHooks.apages_from_objects(site.static_files, 'static_file')
  @sorted_lru_files = SortedLruFiles.new.add_pages @everything

  site.all_collections  = @all_collections
  site.all_documents    = @all_documents
  site.everything       = @everything
  site.sorted_lru_files = @sorted_lru_files
rescue StandardError => e
  JekyllSupport.error_short_trace(AllCollectionsHooks.logger, e)
  # JekyllSupport.warn_short_trace(AllCollectionsHooks.logger, e)
end