Class: Slidict::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/slidict/generator.rb

Overview

Framework-independent application API for integrations such as slidict.io. It turns source prose into both a Deck and presentation source without involving CLI input/output or the filesystem.

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(client:, renderer: Output::Renderer.new) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
# File 'lib/slidict/generator.rb', line 10

def initialize(client:, renderer: Output::Renderer.new)
  @client = client
  @renderer = renderer
end

Instance Method Details

#generate(text:, topic: nil, duration: nil, audience: nil, goal: nil, framework: "slidev", language: nil, presentation_method: nil) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slidict/generator.rb', line 15

def generate(text:, topic: nil, duration: nil, audience: nil, goal: nil,
             framework: "slidev", language: nil, presentation_method: nil)
  source = text.to_s.strip
  raise ArgumentError, "text must not be empty" if source.empty?

  deck = Deck.new(
    topic: topic || title_from(source),
    duration: duration,
    audience: audience,
    goal: goal || "communicate the source text clearly",
    framework: framework,
    presentation_method: presentation_method,
    source: source
  )
  slides = @client.generate_slides(deck, language: language)
  generated_deck = Deck.new(
    topic: deck.topic, duration: deck.duration, audience: deck.audience, goal: deck.goal,
    framework: deck.framework, slides: slides, presentation_method: deck.presentation_method,
    source: source
  )

  Result.new(deck: generated_deck, content: @renderer.render(generated_deck))
end