Class: Nanoc::Core::ViewContextForCompilation

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/view_context_for_compilation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(reps:, items:, dependency_tracker:, compilation_context:, compiled_content_store:) ⇒ ViewContextForCompilation

Returns a new instance of ViewContextForCompilation.



21
22
23
24
25
26
27
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 21

def initialize(reps:, items:, dependency_tracker:, compilation_context:, compiled_content_store:)
  @reps = reps
  @items = items
  @dependency_tracker = dependency_tracker
  @compilation_context = compilation_context
  @compiled_content_store = compiled_content_store
end

Instance Attribute Details

#compilation_contextObject (readonly)

Returns the value of attribute compilation_context.



11
12
13
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 11

def compilation_context
  @compilation_context
end

#compiled_content_storeObject (readonly)

Returns the value of attribute compiled_content_store.



12
13
14
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 12

def compiled_content_store
  @compiled_content_store
end

#dependency_trackerObject (readonly)

Returns the value of attribute dependency_tracker.



10
11
12
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 10

def dependency_tracker
  @dependency_tracker
end

#itemsObject (readonly)

Returns the value of attribute items.



9
10
11
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 9

def items
  @items
end

#repsObject (readonly)

Returns the value of attribute reps.



8
9
10
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 8

def reps
  @reps
end

Instance Method Details

#assigns_for(rep, site:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/nanoc/core/view_context_for_compilation.rb', line 30

def assigns_for(rep, site:)
  last_content = @compiled_content_store.get_current(rep)
  content_or_filename_assigns =
    if last_content.binary?
      { filename: last_content.filename }
    else
      { content: last_content.string }
    end

  content_or_filename_assigns.merge(
    item: Nanoc::Core::CompilationItemView.new(rep.item, self),
    rep: Nanoc::Core::CompilationItemRepView.new(rep, self),
    item_rep: Nanoc::Core::CompilationItemRepView.new(rep, self),
    items: Nanoc::Core::ItemCollectionWithRepsView.new(site.items, self),
    layouts: Nanoc::Core::LayoutCollectionView.new(site.layouts, self),
    config: Nanoc::Core::ConfigView.new(site.config, self),
  )
end