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
  clear_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.



40
41
42
43
44
45
46
47
48
# File 'lib/jekyll/regenerator.rb', line 40

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.



117
118
119
120
121
122
123
124
125
# File 'lib/jekyll/regenerator.rb', line 117

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

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

#clearObject

Clear the metadata and cache

Returns nothing



60
61
62
63
# File 'lib/jekyll/regenerator.rb', line 60

def clear
  @metadata = {}
  clear_cache
end

#clear_cacheObject

Clear just the cache

Returns nothing



68
69
70
# File 'lib/jekyll/regenerator.rb', line 68

def clear_cache
  @cache = {}
end

#disabled?Boolean

Check if metadata has been disabled

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

Returns:

  • (Boolean)


146
147
148
149
# File 'lib/jekyll/regenerator.rb', line 146

def disabled?
  @disabled = !site.incremental? if @disabled.nil?
  @disabled
end

#force(path) ⇒ Object

Force a path to regenerate

Returns true.



53
54
55
# File 'lib/jekyll/regenerator.rb', line 53

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

#metadata_fileObject

Produce the absolute path of the metadata file

Returns the String path of the file.



139
140
141
# File 'lib/jekyll/regenerator.rb', line 139

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)


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/jekyll/regenerator.rb', line 84

def modified?(path)
  return true if disabled?

  # objects that don't have a path are always regenerated
  return true if path.nil?

  # Check for path in cache
  if cache.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 File.exist?(path) && 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
33
34
35
# File 'lib/jekyll/regenerator.rb', line 18

def regenerate?(document)
  case document
  when Page
    document.asset_file? || document.data['regenerate'] ||
      source_modified_or_dest_missing?(
        site.in_source_dir(document.relative_path), document.destination(@site.dest)
      )
  when Document
    !document.write? || document.data['regenerate'] ||
      source_modified_or_dest_missing?(
        document.path, document.destination(@site.dest)
      )
  else
    source_path = document.respond_to?(:path)        ? document.path                    : nil
    dest_path   = document.respond_to?(:destination) ? document.destination(@site.dest) : nil
    source_modified_or_dest_missing?(source_path, dest_path)
  end
end

#source_modified_or_dest_missing?(source_path, dest_path) ⇒ Boolean

Checks if the source has been modified or the destination is missing

returns a boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/jekyll/regenerator.rb', line 76

def source_modified_or_dest_missing?(source_path, dest_path)
  modified?(source_path) || (dest_path && !File.exist?(dest_path))
end

#write_metadataObject

Write the metadata to disk

Returns nothing.



130
131
132
133
134
# File 'lib/jekyll/regenerator.rb', line 130

def 
  unless disabled?
    File.binwrite(, Marshal.dump())
  end
end