Sha256: 78fbd61f8de185945192c51005ca6911cc5d3d29f3cbac7cb02ec5cecb7d61cb

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
module Middleman
  module Presentation
    # List of slides
    class SlideList
      include Enumerable

      private

      attr_accessor :transformers, :slides

      public

      def initialize(names, slide_builder:, **args, &block)
        @slides = Array(names).map { |n| slide_builder.new(n, **args) }
        @transformers = []

        block.call(self) if block_given?

        @slides = transformers.reduce(@slides) { |a, e| e.transform(a) }
      end

      def transform_with(transformer)
        transformers << transformer
      end

      def all
        slides.dup
      end

      def each(&block)
        slides.each(&block)
      end

      def each_new(&block)
        all.keep_if { |s| s.respond_to?(:exist?) && !s.exist? }.each(&block)
      end

      def each_existing(&block)
        all.keep_if { |s| s.respond_to?(:exist?) && s.exist? }.each(&block)
      end

      def existing_slides
        all.keep_if { |s| s.respond_to?(:exist?) && s.exist? }
      end

      def to_a
        all
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
middleman-presentation-core-0.17.7 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.17.6 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.17.5 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.17.2 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.17.1 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.17.0 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.3 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.2 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.0 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.0.rc2 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.0.rc1 lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.0.beta lib/middleman-presentation-core/slide_list.rb
middleman-presentation-core-0.16.0.alpha lib/middleman-presentation-core/slide_list.rb