Class: Jekyll::Metadata

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Metadata

Returns a new instance of Metadata



5
6
7
8
9
10
11
12
13
# File 'lib/jekyll/metadata.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/metadata.rb', line 3

def cache
  @cache
end

#metadataObject (readonly)

Returns the value of attribute metadata



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

def 
  @metadata
end

#siteObject (readonly)

Returns the value of attribute site



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

def site
  @site
end

Instance Method Details

#add(path) ⇒ Object

Add a path to the metadata

Returns true, also on failure.



18
19
20
21
22
23
24
25
26
# File 'lib/jekyll/metadata.rb', line 18

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.



76
77
78
79
80
81
# File 'lib/jekyll/metadata.rb', line 76

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



38
39
40
41
# File 'lib/jekyll/metadata.rb', line 38

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

#disabled?Boolean

Check if metadata has been disabled

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

Returns:

  • (Boolean)


102
103
104
105
# File 'lib/jekyll/metadata.rb', line 102

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

#force(path) ⇒ Object

Force a path to regenerate

Returns true.



31
32
33
# File 'lib/jekyll/metadata.rb', line 31

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

#metadata_fileObject

Produce the absolute path of the metadata file

Returns the String path of the file.



95
96
97
# File 'lib/jekyll/metadata.rb', line 95

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

#regenerate?(path, add = true) ⇒ Boolean

Checks if a path should be regenerated

Returns a boolean.

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/jekyll/metadata.rb', line 46

def regenerate?(path, add = true)
  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 regenerate?(dependency)
        return cache[dependency] = cache[path] = true
      end
    end
    if data["mtime"].eql? File.mtime(path)
      return cache[path] = false
    else
      return !add || add(path)
    end
  end

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

#writeObject

Write the metadata to disk

Returns nothing.



86
87
88
89
90
# File 'lib/jekyll/metadata.rb', line 86

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