class Nanoc::Core::CompiledContentStore

@api private

Public Class Methods

new() click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 9
def initialize
  @contents = Hash.new { |hash, rep| hash[rep] = {} }
  @current_content = {}
end

Public Instance Methods

compiled_content(rep:, snapshot: nil) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 66
def compiled_content(rep:, snapshot: nil)
  snapshot_content = raw_compiled_content(rep: rep, snapshot: snapshot)

  if snapshot_content.binary?
    raise Nanoc::Core::Errors::CannotGetCompiledContentOfBinaryItem.new(rep)
  end

  snapshot_content.string
end
get(rep, snapshot_name) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 15
def get(rep, snapshot_name)
  @contents[rep][snapshot_name]
end
get_all(rep) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 35
def get_all(rep)
  @contents[rep]
end
get_current(rep) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 20
def get_current(rep)
  @current_content[rep]
end
raw_compiled_content(rep:, snapshot: nil) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 45
def raw_compiled_content(rep:, snapshot: nil)
  # Get name of last pre-layout snapshot
  has_pre = rep.snapshot_defs.any? { |sd| sd.name == :pre }
  snapshot_name = snapshot || (has_pre ? :pre : :last)

  # Check existance of snapshot
  snapshot_def = rep.snapshot_defs.reverse.find { |sd| sd.name == snapshot_name }
  unless snapshot_def
    raise Nanoc::Core::Errors::NoSuchSnapshot.new(rep, snapshot_name)
  end

  # Return content if it is available
  content = get(rep, snapshot_name)
  return content if content

  # Content is unavailable; notify and try again
  Fiber.yield(Nanoc::Core::Errors::UnmetDependency.new(rep, snapshot_name))
  get(rep, snapshot_name)
end
set(rep, snapshot_name, contents) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 25
def set(rep, snapshot_name, contents)
  @contents[rep][snapshot_name] = contents
end
set_all(rep, contents_per_snapshot) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 40
def set_all(rep, contents_per_snapshot)
  @contents[rep] = contents_per_snapshot
end
set_current(rep, content) click to toggle source
# File lib/nanoc/core/compiled_content_store.rb, line 30
def set_current(rep, content)
  @current_content[rep] = content
end