Class: Nanoc::Int::CompilationContext
- Inherits:
-
Object
- Object
- Nanoc::Int::CompilationContext
- Defined in:
- lib/nanoc/base/services/compilation_context.rb
Instance Attribute Summary collapse
-
#compiled_content_cache ⇒ Object
readonly
Returns the value of attribute compiled_content_cache.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#snapshot_repo ⇒ Object
readonly
Returns the value of attribute snapshot_repo.
Instance Method Summary collapse
-
#assigns_for(rep, dependency_tracker) ⇒ Object
-
#create_view_context(dependency_tracker) ⇒ Object
-
#filter_name_and_args_for_layout(layout) ⇒ Object
-
#initialize(action_provider:, reps:, site:, compiled_content_cache:, snapshot_repo:) ⇒ CompilationContext
constructor
A new instance of CompilationContext.
Constructor Details
#initialize(action_provider:, reps:, site:, compiled_content_cache:, snapshot_repo:) ⇒ CompilationContext
Returns a new instance of CompilationContext
9 10 11 12 13 14 15 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 9 def initialize(action_provider:, reps:, site:, compiled_content_cache:, snapshot_repo:) @action_provider = action_provider @reps = reps @site = site @compiled_content_cache = compiled_content_cache @snapshot_repo = snapshot_repo end |
Instance Attribute Details
#compiled_content_cache ⇒ Object (readonly)
Returns the value of attribute compiled_content_cache
6 7 8 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 6 def compiled_content_cache @compiled_content_cache end |
#site ⇒ Object (readonly)
Returns the value of attribute site
5 6 7 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 5 def site @site end |
#snapshot_repo ⇒ Object (readonly)
Returns the value of attribute snapshot_repo
7 8 9 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 7 def snapshot_repo @snapshot_repo end |
Instance Method Details
#assigns_for(rep, dependency_tracker) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 35 def assigns_for(rep, dependency_tracker) last_content = @snapshot_repo.get(rep, :last) content_or_filename_assigns = if last_content.binary? { filename: last_content.filename } else { content: last_content.string } end view_context = create_view_context(dependency_tracker) content_or_filename_assigns.merge( item: Nanoc::CompilationItemView.new(rep.item, view_context), rep: Nanoc::CompilationItemRepView.new(rep, view_context), item_rep: Nanoc::CompilationItemRepView.new(rep, view_context), items: Nanoc::ItemCollectionWithRepsView.new(@site.items, view_context), layouts: Nanoc::LayoutCollectionView.new(@site.layouts, view_context), config: Nanoc::ConfigView.new(@site.config, view_context), ) end |
#create_view_context(dependency_tracker) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 25 def create_view_context(dependency_tracker) Nanoc::ViewContextForCompilation.new( reps: @reps, items: @site.items, dependency_tracker: dependency_tracker, compilation_context: self, snapshot_repo: @snapshot_repo, ) end |
#filter_name_and_args_for_layout(layout) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/nanoc/base/services/compilation_context.rb', line 17 def filter_name_and_args_for_layout(layout) seq = @action_provider.action_sequence_for(layout) if seq.nil? || seq.size != 1 || !seq[0].is_a?(Nanoc::Int::ProcessingActions::Filter) raise Nanoc::Int::Errors::UndefinedFilterForLayout.new(layout) end [seq[0].filter_name, seq[0].params] end |