Class: Nanoc::Spec::HelperContext Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc/spec.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ HelperContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HelperContext.

Parameters:

  • mod (Module)

    The helper module to create a context for



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nanoc/spec.rb', line 11

def initialize(mod)
  @mod = mod

  @erbout = ''
  @rule_memory = {}
  @config = Nanoc::Int::Configuration.new.with_defaults
  @reps = Nanoc::Int::ItemRepRepo.new
  @items = Nanoc::Int::IdentifiableCollection.new(@config)
  @layouts = Nanoc::Int::IdentifiableCollection.new(@config)
  @dependency_tracker = Nanoc::Int::DependencyTracker.new(Object.new)
end

Instance Attribute Details

#dependency_trackerNanoc::Int::DependencyTracker (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/nanoc/spec.rb', line 6

def dependency_tracker
  @dependency_tracker
end

#erboutObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def erbout
  @erbout
end

Instance Method Details

#configNanoc::MutableConfigView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
# File 'lib/nanoc/spec.rb', line 73

def config
  assigns[:config]
end

#create_item(content, attributes, identifier) ⇒ Nanoc::ItemWithRepsView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new item and adds it to the site’s collection of items.

Parameters:

  • content (String)

    The uncompiled item content

  • attributes (Hash)

    A hash containing this item’s attributes

  • identifier (Nanoc::Identifier, String)

    This item’s identifier

Returns:



32
33
34
35
36
# File 'lib/nanoc/spec.rb', line 32

def create_item(content, attributes, identifier)
  item = Nanoc::Int::Item.new(content, attributes, identifier)
  @items << item
  Nanoc::ItemWithRepsView.new(item, view_context)
end

#create_layout(content, attributes, identifier) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: document



39
40
41
42
43
# File 'lib/nanoc/spec.rb', line 39

def create_layout(content, attributes, identifier)
  layout = Nanoc::Int::Layout.new(content, attributes, identifier)
  @layouts << layout
  Nanoc::LayoutView.new(layout, view_context)
end

#create_rep(item, path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new representation for the given item.

Parameters:

  • item (Nanoc::ItemWithRepsView)

    The item to create a represetation for

  • path (String)

    The path of the ‘:last` snapshot of this item representation



50
51
52
53
54
55
# File 'lib/nanoc/spec.rb', line 50

def create_rep(item, path)
  rep = Nanoc::Int::ItemRep.new(item.unwrap, :default)
  rep.paths[:last] = path
  @reps << rep
  Nanoc::ItemRepView.new(rep, view_context)
end

#helperObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns An object that includes the helper functions.

Returns:

  • (Object)

    An object that includes the helper functions



58
59
60
61
62
# File 'lib/nanoc/spec.rb', line 58

def helper
  mod = @mod
  klass = Class.new(Nanoc::Int::Context) { include mod }
  klass.new(assigns)
end

#itemNanoc::ItemWithRepsView?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



78
79
80
# File 'lib/nanoc/spec.rb', line 78

def item
  assigns[:item]
end

#item=(item) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
# File 'lib/nanoc/spec.rb', line 64

def item=(item)
  @item = item ? item.unwrap : nil
end

#item_repNanoc::ItemRepView?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



83
84
85
# File 'lib/nanoc/spec.rb', line 83

def item_rep
  assigns[:item_rep]
end

#item_rep=(item_rep) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
# File 'lib/nanoc/spec.rb', line 68

def item_rep=(item_rep)
  @item_rep = item_rep ? item_rep.unwrap : nil
end

#itemsNanoc::ItemCollectionWithRepsView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



88
89
90
# File 'lib/nanoc/spec.rb', line 88

def items
  assigns[:items]
end

#layoutsNanoc::LayoutCollectionView

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



93
94
95
# File 'lib/nanoc/spec.rb', line 93

def layouts
  assigns[:layouts]
end

#rule_memory_for(obj) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
# File 'lib/nanoc/spec.rb', line 97

def rule_memory_for(obj)
  @rule_memory.fetch(obj, [])
end

#update_rule_memory(obj, memory) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
# File 'lib/nanoc/spec.rb', line 101

def update_rule_memory(obj, memory)
  @rule_memory[obj] = memory
end