class Presentation
An immutable collection of slides with configuration.
Use .load to create a presentation from a directory of Markdown files.
Each loaded class Presently::Slide is attached to its presentation and identified by a
path relative to the presentation root.
Definitions
def self.load(root = "slides", templates = Templates.for)
Load a presentation from a directory of Markdown slide files.
Signature
-
parameter
rootString The directory containing
.mdslide files.-
parameter
templatesTemplates The template resolver for loading slide templates.
-
returns
Presentation A new presentation with slides loaded from the directory.
Implementation
def self.load(root = "slides", templates = Templates.for)
new(root, templates)
end
def initialize(root = "slides", templates = Templates.for)
Initialize a new presentation.
Signature
-
parameter
rootString The root directory containing slide files.
-
parameter
templatesTemplates The template resolver for loading slide templates.
Implementation
def initialize(root = "slides", templates = Templates.for)
@root = File.expand_path(root)
@templates = templates
@slides = load_slides
end
attr :root
Signature
-
attribute
String The absolute root directory containing slide files.
attr :slides
Signature
-
attribute
Array(Slide) The ordered list of slides.
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
indexInteger 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.
Signature
-
returns
Presentation A new presentation instance.
Implementation
def reload
self.class.new(@root, @templates.reload)
end
def load_slides
Load slides recursively in relative path order.
Signature
-
returns
Array(Slide) The loaded, sorted, non-skipped slides.
Implementation
def load_slides
Dir.glob("**/*.md", base: @root).sort.filter_map do |path|
components = path.split(File::SEPARATOR)
next unless components.all?{|component| component.match?(/\A\d/)}
slide = Slide.load(self, path)
slide unless slide.skip?
end
end