Class: Yuzu::Generators::PaginateGenerator

Inherits:
Generator show all
Defined in:
lib/yuzu/generators/paginate.rb

Constant Summary collapse

@@generated =
[]

Instance Attribute Summary

Attributes inherited from Generator

#directive, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generator

generators, registry

Constructor Details

#initializePaginateGenerator

Returns a new instance of PaginateGenerator.



21
22
23
24
# File 'lib/yuzu/generators/paginate.rb', line 21

def initialize
  @name = "paginate"
  @directive = "INSERTCATALOG"
end

Class Method Details

.add_generator(generator) ⇒ Object



13
14
15
# File 'lib/yuzu/generators/paginate.rb', line 13

def self.add_generator(generator)
  @@generated.push(generator)
end

.get_generatedObject



9
10
11
# File 'lib/yuzu/generators/paginate.rb', line 9

def self.get_generated
  @@generated
end

.is_generated?(generator) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/yuzu/generators/paginate.rb', line 17

def self.is_generated?(generator)
  @@generated.include?(generator)
end

Instance Method Details

#generate!(website_file) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/yuzu/generators/paginate.rb', line 35

def generate!(website_file)
  # Attempt to ensure this website_file isn't generated twice.
  return if website_file.is_a?(Yuzu::Core::PaginatedWebsiteFile) or \
    PaginateGenerator.is_generated?(website_file)

  CatalogPaginator.new(website_file, self).generate!
  PaginateGenerator.add_generator(website_file)
end

#should_generate?(website_file) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/yuzu/generators/paginate.rb', line 26

def should_generate?(website_file)
  not PaginateGenerator.is_generated?(website_file) and \
    not website_file.raw_contents.scan(regex).flatten.empty?
end

#visitor_filterObject



31
32
33
# File 'lib/yuzu/generators/paginate.rb', line 31

def visitor_filter
  proc {|c| c.file?}
end