Class: Slyde::Presentation

Inherits:
Object
  • Object
show all
Defined in:
lib/slyde/presentation.rb

Defined Under Namespace

Classes: Parser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Presentation

Returns a new instance of Presentation.



20
21
22
# File 'lib/slyde/presentation.rb', line 20

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/slyde/presentation.rb', line 5

def path
  @path
end

Class Method Details

.rendererObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/slyde/presentation.rb', line 9

def self.renderer
  @renderer ||= Redcarpet::Markdown.new(HTMLRenderer, {
    tables: true,
    fenced_code_blocks: true,
    autolink: true,
    strikethrough: true,
    space_after_headers: true,
    superscript: true
  })
end

Instance Method Details

#index_for_slide(slide) ⇒ Object



65
66
67
# File 'lib/slyde/presentation.rb', line 65

def index_for_slide(slide)
  slides.index(slide)
end

#parserObject



36
37
38
# File 'lib/slyde/presentation.rb', line 36

def parser
  @parser ||= Parser.new(raw_html)
end

#raw_htmlObject



48
49
50
# File 'lib/slyde/presentation.rb', line 48

def raw_html
  self.class.renderer.render(to_s)
end

#slide_after(slide) ⇒ Object



56
57
58
# File 'lib/slyde/presentation.rb', line 56

def slide_after(slide)
  slides[index_for_slide(slide) + 1]
end

#slide_before(slide) ⇒ Object



60
61
62
63
# File 'lib/slyde/presentation.rb', line 60

def slide_before(slide)
  index = index_for_slide(slide)
  index == 0 ? nil : slides[index - 1]
end

#slide_with_id(id) ⇒ Object



24
25
26
# File 'lib/slyde/presentation.rb', line 24

def slide_with_id(id)
  slides.find { |s| s.id == id }
end

#slidesObject



28
29
30
31
32
33
34
# File 'lib/slyde/presentation.rb', line 28

def slides
  @slides ||= parser.slides.each_with_index.map do |slide, index|
    slide_attributes = slide.merge(page: index + 1)

    Slide.new(slide_attributes)
  end
end

#titleObject



40
41
42
# File 'lib/slyde/presentation.rb', line 40

def title
  parser.title
end

#to_htmlObject



44
45
46
# File 'lib/slyde/presentation.rb', line 44

def to_html
  @to_html ||= slides.map(&:to_html).join
end

#to_sObject



52
53
54
# File 'lib/slyde/presentation.rb', line 52

def to_s
  File.read(path)
end