Class: AnimateIt::ChapterPresenter
- Inherits:
-
Object
- Object
- AnimateIt::ChapterPresenter
- Defined in:
- lib/animate_it/chapter_navigation.rb
Instance Attribute Summary collapse
-
#chapter ⇒ Object
readonly
Returns the value of attribute chapter.
Instance Method Summary collapse
- #button(content = nil, **attributes, &block) ⇒ Object
- #default_control(preset: :pills) ⇒ Object
- #element(content = nil, tag: :div, **attributes, &block) ⇒ Object
-
#initialize(view, chapter, interactive:, state:) ⇒ ChapterPresenter
constructor
A new instance of ChapterPresenter.
- #thumbnail ⇒ Object
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
#chapter ⇒ Object (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 (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.(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 (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 |
#thumbnail ⇒ Object
14 15 16 |
# File 'lib/animate_it/chapter_navigation.rb', line 14 def thumbnail [:thumbnail] || ["thumbnail"] end |