Class: AnimateIt::ChapterPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/animate_it/chapter_navigation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, chapter, interactive:, state:) ⇒ ChapterPresenter

Returns a new instance of ChapterPresenter.



7
8
9
10
11
12
# File 'lib/animate_it/chapter_navigation.rb', line 7

def initialize(view, chapter, interactive:, state:)
  @view = view
  @chapter = chapter
  @interactive = interactive
  @state = state
end

Instance Attribute Details

#chapterObject (readonly)

Returns the value of attribute chapter.



3
4
5
# File 'lib/animate_it/chapter_navigation.rb', line 3

def chapter
  @chapter
end

Instance Method Details

#button(content = nil, **attributes, &block) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/animate_it/chapter_navigation.rb', line 18

def button(content = nil, **attributes, &block)
  body = block ? @view.capture(self, &block) : (content || label)
  classes = ["animate-it-chapter", attributes.delete(:class)].compact.join(" ")
  attributes, data = stateful_attributes(attributes)
  attributes[:type] ||= "button"
  attributes[:"aria-label"] ||= "Jump to #{label}"
  @view.tag.button(body, **attributes, class: classes, data:)
end

#default_control(preset: :pills) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/animate_it/chapter_navigation.rb', line 34

def default_control(preset: :pills)
  progress = @view.tag.svg(
    @view.tag.rect(x: 1, y: 1, width: 98, height: 38, rx: 19, pathLength: 1),
    class: "animate-it-chapter__progress", viewBox: "0 0 100 40", preserveAspectRatio: "none", aria: { hidden: true }
  )
  body = @view.safe_join([progress, @view.tag.span(label, class: "animate-it-chapter__label")])
  classes = "animate-it-chapter animate-it-chapter--#{preset}"
  if @interactive
    button(body, class: classes.delete_prefix("animate-it-chapter "))
  else
    element(body, class: classes.delete_prefix("animate-it-chapter "))
  end
end

#element(content = nil, tag: :div, **attributes, &block) ⇒ Object



27
28
29
30
31
32
# File 'lib/animate_it/chapter_navigation.rb', line 27

def element(content = nil, tag: :div, **attributes, &block)
  body = block ? @view.capture(self, &block) : (content || label)
  classes = ["animate-it-chapter", attributes.delete(:class)].compact.join(" ")
  attributes, data = stateful_attributes(attributes)
  @view.tag.public_send(tag, body, **attributes, class: classes, data:)
end

#thumbnailObject



14
15
16
# File 'lib/animate_it/chapter_navigation.rb', line 14

def thumbnail
  [:thumbnail] || ["thumbnail"]
end