Class: Jekyll::Regenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/regenerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Regenerator

Returns a new instance of Regenerator.


5
6
7
8
9
10
11
12
13
# File 'lib/jekyll/regenerator.rb', line 5

def initialize(site)
  @site = site

  # Read metadata from file
  

  # Initialize cache to an empty hash
  @cache = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache


3
4
5
# File 'lib/jekyll/regenerator.rb', line 3

def cache
  @cache
end

#metadataObject (readonly)

Returns the value of attribute metadata


3
4
5
# File 'lib/jekyll/regenerator.rb', line 3

def 
  @metadata
end

#siteObject (readonly)

Returns the value of attribute site


3
4
5
# File 'lib/jekyll/regenerator.rb', line 3

def site
  @site
end

Instance Method Details

#add(path) ⇒ Object

Add a path to the metadata

Returns true, also on failure.


37
38
39
40
41
42
43
44
45
# File 'lib/jekyll/regenerator.rb', line 37

def add(path)
  return true unless File.exist?(path)

  [path] = {
    "mtime" => File.mtime(path),
    "deps" => []
  }
  cache[path] = true
end

#add_dependency(path, dependency) ⇒ Object

Add a dependency of a path

Returns nothing.


96
97
98
99
100
101
# File 'lib/jekyll/regenerator.rb', line 96

def add_dependency(path, dependency)
  return if ([path].nil? || @disabled)

  [path]["deps"] << dependency unless [path]["deps"].include? dependency
  regenerate? dependency
end

#clearObject

Clear the metadata and cache

Returns nothing


57
58
59
60
# File 'lib/jekyll/regenerator.rb', line 57

def clear
  @metadata = {}
  @cache = {}
end

#disabled?Boolean

Check if metadata has been disabled

Returns a Boolean (true for disabled, false for enabled).

Returns:

  • (Boolean)

122
123
124
125
# File 'lib/jekyll/regenerator.rb', line 122

def disabled?
  @disabled = site.full_rebuild? if @disabled.nil?
  @disabled
end

#force(path) ⇒ Object

Force a path to regenerate

Returns true.


50
51
52
# File 'lib/jekyll/regenerator.rb', line 50

def force(path)
  cache[path] = true
end

#metadata_fileObject

Produce the absolute path of the metadata file

Returns the String path of the file.


115
116
117
# File 'lib/jekyll/regenerator.rb', line 115

def 
  site.in_source_dir('.jekyll-metadata')
end

#modified?(path) ⇒ Boolean

Checks if a path's (or one of its dependencies) mtime has changed

Returns a boolean.

Returns:

  • (Boolean)

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jekyll/regenerator.rb', line 66

def modified?(path)
  return true if disabled?

  # Check for path in cache
  if cache.has_key? path
    return cache[path]
  end

  # Check path that exists in metadata
  data = [path]
  if data
    data["deps"].each do |dependency|
      if modified?(dependency)
        return cache[dependency] = cache[path] = true
      end
    end
    if data["mtime"].eql? File.mtime(path)
      return cache[path] = false
    else
      return add(path)
    end
  end

  # Path does not exist in metadata, add it
  return add(path)
end

#regenerate?(document) ⇒ Boolean

Checks if a renderable object needs to be regenerated

Returns a boolean.

Returns:

  • (Boolean)

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jekyll/regenerator.rb', line 18

def regenerate?(document)
  case document
  when Post, Page
    document.asset_file? || document.data['regenerate'] ||
      modified?(site.in_source_dir(document.relative_path))
  when Document
    !document.write? || document.data['regenerate'] || modified?(document.path)
  else
    if document.respond_to?(:path)
      modified?(document.path)
    else
      true
    end
  end
end

#write_metadataObject

Write the metadata to disk

Returns nothing.


106
107
108
109
110
# File 'lib/jekyll/regenerator.rb', line 106

def 
  File.open(, 'w') do |f|
    f.write(.to_yaml)
  end
end