Class: Nanoc::Core::CompilationItemRepView

Inherits:
BasicItemRepView show all
Defined in:
lib/nanoc/core/compilation_item_rep_view.rb

Constant Summary collapse

FILE_APPEAR_TIMEOUT =

How long to wait before the requested file appears.

This is a bit of a hack – ideally, Nanoc would know that the file is being generated, and wait the appropriate amount of time.

10.0

Instance Method Summary collapse

Methods inherited from BasicItemRepView

#==, #_unwrap, #binary?, #eql?, #hash, #initialize, #inspect, #item, #name, #path, #snapshot?

Methods inherited from View

#_context, #_unwrap, #frozen?, #initialize, #inspect

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

This class inherits a constructor from Nanoc::Core::BasicItemRepView

Instance Method Details

#compiled_content(snapshot: nil) ⇒ String

Returns the compiled content.

Parameters:

  • snapshot (String) (defaults to: nil)

    The name of the snapshot from which to fetch the compiled content. By default, the returned compiled content will be the content compiled right before the first layout call (if any).

Returns:

  • (String)

    The content at the given snapshot.



51
52
53
54
# File 'lib/nanoc/core/compilation_item_rep_view.rb', line 51

def compiled_content(snapshot: nil)
  @context.dependency_tracker.bounce(_unwrap.item, compiled_content: true)
  @context.compiled_content_store.compiled_content(rep: _unwrap, snapshot:)
end

#item_view_classObject

This method is abstract.


13
14
15
# File 'lib/nanoc/core/compilation_item_rep_view.rb', line 13

def item_view_class
  Nanoc::Core::CompilationItemView
end

#raw_path(snapshot: :last) ⇒ String

Returns the item rep’s raw path. It includes the path to the output directory and the full filename.

Parameters:

  • snapshot (Symbol) (defaults to: :last)

    The snapshot for which the path should be returned.

Returns:

  • (String)

    The item rep’s raw path.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nanoc/core/compilation_item_rep_view.rb', line 24

def raw_path(snapshot: :last)
  @context.dependency_tracker.bounce(_unwrap.item, compiled_content: true)

  res = @item_rep.raw_path(snapshot:)

  unless @item_rep.compiled?
    Fiber.yield(Nanoc::Core::Errors::UnmetDependency.new(@item_rep, snapshot))
  end

  # Wait for file to exist
  if res
    start = Time.now
    sleep 0.05 until File.file?(res) || Time.now - start > FILE_APPEAR_TIMEOUT
    raise Nanoc::Core::Errors::InternalInconsistency, "File raw_path did not appear in time (#{FILE_APPEAR_TIMEOUT}s): #{res}" unless File.file?(res)
  end

  res
end