PresentlySourcePresentlyPresentation

class Presentation

An immutable collection of slides with configuration.

Use .load to create a presentation from a directory of Markdown files, or initialize directly with an array of class Presently::Slide instances.

Definitions

def self.slides_from(slides_root)

Load and sort slide files from a directory.

Signature

parameter slides_root String

The directory containing .md slide files.

returns Array(Slide)

The loaded, sorted, non-skipped slides.

Implementation

def self.slides_from(slides_root)
	Dir.glob(File.join(slides_root, "*.md")).sort.map{|path| Slide.load(path)}.reject(&:skip?)
end

def self.load(slides_root = "slides", **options)

Load a presentation from a directory of Markdown slide files.

Signature

parameter slides_root String

The directory containing .md slide files.

parameter options Hash

Additional options passed to #initialize.

returns Presentation

A new presentation with slides loaded from the directory.

Implementation

def self.load(slides_root = "slides", **options)
	new(slides_from(slides_root), slides_root: slides_root, **options)
end

def initialize(slides = [], slides_root: nil, templates: Templates.for)

Initialize a new presentation.

Signature

parameter slides Array(Slide)

The ordered list of slides.

parameter slides_root String | Nil

The directory slides were loaded from, used by #reload.

parameter templates Templates

The template resolver for loading slide templates.

Implementation

def initialize(slides = [], slides_root: nil, templates: Templates.for)
	@slides = slides
	@slides_root = slides_root
	@templates = templates
end

attr :slides

Signature

attribute Array(Slide)

The ordered list of slides.

attr :slides_root

Signature

attribute String | Nil

The directory slides were loaded from.

attr :templates

Signature

attribute Templates

The template resolver.

def slide_count

The number of slides in the presentation.

Signature

returns Integer

The slide count.

Implementation

def slide_count
	@slides.length
end

def total_duration

The total expected duration of the presentation in seconds.

Signature

returns Numeric

The sum of all slide durations.

Implementation

def total_duration
	@slides.sum(&:duration)
end

def expected_time_at(index)

Calculate the expected elapsed time for slides up to the given index.

Signature

parameter index Integer

The slide index (exclusive).

returns Numeric

The sum of durations for slides before the given index.

Implementation

def expected_time_at(index)
	@slides[0...index].sum(&:duration)
end

def reload

Return a new class Presently::Presentation with freshly loaded slides and a cleared template cache. Only works if the presentation was created with .load.

Signature

returns Presentation

A new presentation instance, or self if no slides root is set.

Implementation

def reload
	return self unless @slides_root
	
	self.class.new(self.class.slides_from(@slides_root), slides_root: @slides_root, templates: @templates.reload)
end