Class: Nanoc::Spec::HelperContext

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ HelperContext



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nanoc/spec.rb', line 57

def initialize(mod)
  @mod = mod

  @erbout = +''
  @action_sequence = {}
  @config = Nanoc::Core::Configuration.new(dir: Dir.getwd).with_defaults
  @reps = Nanoc::Core::ItemRepRepo.new
  @items = Nanoc::Core::ItemCollection.new(@config)
  @layouts = Nanoc::Core::LayoutCollection.new(@config)
  @dependency_tracker = Nanoc::Core::DependencyTracker.new(Object.new)
  @compiled_content_store = Nanoc::Core::CompiledContentStore.new
  @action_provider = new_action_provider
end

Instance Attribute Details

#dependency_trackerNanoc::Core::DependencyTracker (readonly)



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

def dependency_tracker
  @dependency_tracker
end

#erboutObject (readonly)

Returns the value of attribute erbout.



54
55
56
# File 'lib/nanoc/spec.rb', line 54

def erbout
  @erbout
end

Instance Method Details

#action_sequence_for(obj) ⇒ Object



154
155
156
# File 'lib/nanoc/spec.rb', line 154

def action_sequence_for(obj)
  @action_sequence.fetch(obj, [])
end

#compiled_content_storeObject



162
163
164
# File 'lib/nanoc/spec.rb', line 162

def compiled_content_store
  view_context.compiled_content_store
end

#configNanoc::Core::MutableConfigView



130
131
132
# File 'lib/nanoc/spec.rb', line 130

def config
  assigns[:config]
end

#create_item(content, attributes, identifier) ⇒ Nanoc::Core::CompilationItemView

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



80
81
82
83
84
# File 'lib/nanoc/spec.rb', line 80

def create_item(content, attributes, identifier)
  item = Nanoc::Core::Item.new(content, attributes, identifier)
  @items = @items.add(item)
  self
end

#create_layout(content, attributes, identifier) ⇒ Nanoc::Core::CompilationItemView

Creates a new layout and adds it to the site’s collection of layouts.



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

def create_layout(content, attributes, identifier)
  layout = Nanoc::Core::Layout.new(content, attributes, identifier)
  @layouts = @layouts.add(layout)
  self
end

#create_rep(item, path, rep = :default) ⇒ Object

Creates a new representation for the given item.



107
108
109
110
111
112
# File 'lib/nanoc/spec.rb', line 107

def create_rep(item, path, rep = :default)
  rep = Nanoc::Core::ItemRep.new(item._unwrap, rep)
  rep.paths[:last] = [path]
  @reps << rep
  self
end

#helperObject



115
116
117
118
119
# File 'lib/nanoc/spec.rb', line 115

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

#itemNanoc::Core::CompilationItemView?



135
136
137
# File 'lib/nanoc/spec.rb', line 135

def item
  assigns[:item]
end

#item=(item) ⇒ Object



121
122
123
# File 'lib/nanoc/spec.rb', line 121

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

#item_repNanoc::Core::BasicItemRepView?



140
141
142
# File 'lib/nanoc/spec.rb', line 140

def item_rep
  assigns[:item_rep]
end

#item_rep=(item_rep) ⇒ Object



125
126
127
# File 'lib/nanoc/spec.rb', line 125

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

#itemsNanoc::Core::ItemCollectionWithRepsView



145
146
147
# File 'lib/nanoc/spec.rb', line 145

def items
  assigns[:items]
end

#layoutsNanoc::Core::LayoutCollectionView



150
151
152
# File 'lib/nanoc/spec.rb', line 150

def layouts
  assigns[:layouts]
end

#update_action_sequence(obj, memory) ⇒ Object



158
159
160
# File 'lib/nanoc/spec.rb', line 158

def update_action_sequence(obj, memory)
  @action_sequence[obj] = memory
end