Sha256: 466979bd662ce549e38bbcf8d64b1f66858a6fa0663058d79d481951d2563004

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Nanoc
  module Int
    # @api private
    class ItemRepBuilder
      include Nanoc::Core::ContractsSupport

      attr_reader :reps

      def initialize(site, action_provider, reps)
        @site = site
        @action_provider = action_provider
        @reps = reps
      end

      def run
        @site.items.each do |item|
          @action_provider.rep_names_for(item).each do |rep_name|
            @reps << Nanoc::Core::ItemRep.new(item, rep_name)
          end
        end

        action_sequences = Nanoc::Int::ItemRepRouter.new(@reps, @action_provider, @site).run

        @reps.each do |rep|
          rep.snapshot_defs = self.class.snapshot_defs_for(action_sequences[rep])
        end

        action_sequences
      end

      contract Nanoc::Core::ActionSequence => C::ArrayOf[Nanoc::Core::SnapshotDef]
      def self.snapshot_defs_for(action_sequence)
        is_binary = action_sequence.item_rep.item.content.binary?
        snapshot_defs = []

        action_sequence.each do |action|
          case action
          when Nanoc::Core::ProcessingActions::Snapshot
            action.snapshot_names.each do |snapshot_name|
              snapshot_defs << Nanoc::Core::SnapshotDef.new(snapshot_name, binary: is_binary)
            end
          when Nanoc::Core::ProcessingActions::Filter
            is_binary = Nanoc::Filter.named!(action.filter_name).to_binary?
          end
        end

        snapshot_defs
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
nanoc-4.11.9 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.8 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.7 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.6 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.5 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.4 lib/nanoc/base/services/item_rep_builder.rb
nanoc-4.11.3 lib/nanoc/base/services/item_rep_builder.rb