Class: Nanoc::Spec::HelperContext
- Inherits:
-
Object
- Object
- Nanoc::Spec::HelperContext
- Defined in:
- lib/nanoc/spec.rb
Instance Attribute Summary collapse
-
#erbout ⇒ Object
readonly
Returns the value of attribute erbout.
Instance Method Summary collapse
- #action_sequence_for(obj) ⇒ Object
- #assigns ⇒ Object
- #compiled_content_repo ⇒ Object
- #config ⇒ Nanoc::Core::MutableConfigView
-
#create_item(content, attributes, identifier) ⇒ Nanoc::Core::CompilationItemView
Creates a new item and adds it to the site’s collection of items.
-
#create_layout(content, attributes, identifier) ⇒ Nanoc::Core::CompilationItemView
Creates a new layout and adds it to the site’s collection of layouts.
-
#create_rep(item, path, rep = :default) ⇒ Object
Creates a new representation for the given item.
- #dependency_store ⇒ Object
- #dependency_tracker ⇒ Object
-
#helper ⇒ Object
An object that includes the helper functions.
-
#initialize(mod) ⇒ HelperContext
constructor
A new instance of HelperContext.
- #item ⇒ Nanoc::Core::CompilationItemView?
- #item=(item) ⇒ Object
- #item_rep ⇒ Nanoc::Core::BasicItemRepView?
- #item_rep=(item_rep) ⇒ Object
- #items ⇒ Nanoc::Core::ItemCollectionWithRepsView
- #layouts ⇒ Nanoc::Core::LayoutCollectionView
- #update_action_sequence(obj, memory) ⇒ Object
Constructor Details
#initialize(mod) ⇒ HelperContext
Returns a new instance of HelperContext.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nanoc/spec.rb', line 54 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) @compiled_content_repo = Nanoc::Core::CompiledContentRepo.new @action_provider = new_action_provider end |
Instance Attribute Details
#erbout ⇒ Object (readonly)
Returns the value of attribute erbout.
51 52 53 |
# File 'lib/nanoc/spec.rb', line 51 def erbout @erbout end |
Instance Method Details
#action_sequence_for(obj) ⇒ Object
150 151 152 |
# File 'lib/nanoc/spec.rb', line 150 def action_sequence_for(obj) @action_sequence.fetch(obj, []) end |
#assigns ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/nanoc/spec.rb', line 162 def assigns { config: Nanoc::Core::MutableConfigView.new(@config, view_context), item_rep: @item_rep ? Nanoc::Core::CompilationItemRepView.new(@item_rep, view_context) : nil, item: @item ? Nanoc::Core::CompilationItemView.new(@item, view_context) : nil, items: Nanoc::Core::ItemCollectionWithRepsView.new(@items, view_context), layouts: Nanoc::Core::LayoutCollectionView.new(@layouts, view_context), _erbout: @erbout, } end |
#compiled_content_repo ⇒ Object
158 159 160 |
# File 'lib/nanoc/spec.rb', line 158 def compiled_content_repo view_context.compiled_content_repo end |
#config ⇒ Nanoc::Core::MutableConfigView
126 127 128 |
# File 'lib/nanoc/spec.rb', line 126 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.
76 77 78 79 80 |
# File 'lib/nanoc/spec.rb', line 76 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.
91 92 93 94 95 |
# File 'lib/nanoc/spec.rb', line 91 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.
103 104 105 106 107 108 |
# File 'lib/nanoc/spec.rb', line 103 def create_rep(item, path, rep = :default) rep = Nanoc::Core::ItemRep.new(item._unwrap, rep) rep.paths[:last] = [path] @reps << rep self end |
#dependency_store ⇒ Object
173 174 175 |
# File 'lib/nanoc/spec.rb', line 173 def dependency_store @_dependency_store ||= Nanoc::Core::DependencyStore.new(@items, @layouts, @config) end |
#dependency_tracker ⇒ Object
177 178 179 180 181 182 |
# File 'lib/nanoc/spec.rb', line 177 def dependency_tracker @_dependency_tracker ||= Nanoc::Core::DependencyTracker.new( dependency_store, root: Nanoc::Core::Item.new('root', {}, '/root.md'), ) end |
#helper ⇒ Object
Returns An object that includes the helper functions.
111 112 113 114 115 |
# File 'lib/nanoc/spec.rb', line 111 def helper mod = @mod klass = Class.new(Nanoc::Core::Context) { include mod } klass.new(assigns) end |
#item ⇒ Nanoc::Core::CompilationItemView?
131 132 133 |
# File 'lib/nanoc/spec.rb', line 131 def item assigns[:item] end |
#item=(item) ⇒ Object
117 118 119 |
# File 'lib/nanoc/spec.rb', line 117 def item=(item) @item = item&._unwrap end |
#item_rep ⇒ Nanoc::Core::BasicItemRepView?
136 137 138 |
# File 'lib/nanoc/spec.rb', line 136 def item_rep assigns[:item_rep] end |
#item_rep=(item_rep) ⇒ Object
121 122 123 |
# File 'lib/nanoc/spec.rb', line 121 def item_rep=(item_rep) @item_rep = item_rep&._unwrap end |
#items ⇒ Nanoc::Core::ItemCollectionWithRepsView
141 142 143 |
# File 'lib/nanoc/spec.rb', line 141 def items assigns[:items] end |
#layouts ⇒ Nanoc::Core::LayoutCollectionView
146 147 148 |
# File 'lib/nanoc/spec.rb', line 146 def layouts assigns[:layouts] end |
#update_action_sequence(obj, memory) ⇒ Object
154 155 156 |
# File 'lib/nanoc/spec.rb', line 154 def update_action_sequence(obj, memory) @action_sequence[obj] = memory end |