Class: AnimateIt::ChapterNavigationBuilder
- Inherits:
-
Object
- Object
- AnimateIt::ChapterNavigationBuilder
- Defined in:
- lib/animate_it/chapter_navigation.rb
Instance Method Summary collapse
-
#initialize(view, composition, interactive:, preset: :pills, mobile: nil, frame: 0) ⇒ ChapterNavigationBuilder
constructor
A new instance of ChapterNavigationBuilder.
- #render(**attributes, &block) ⇒ Object
Constructor Details
#initialize(view, composition, interactive:, preset: :pills, mobile: nil, frame: 0) ⇒ ChapterNavigationBuilder
Returns a new instance of ChapterNavigationBuilder.
70 71 72 73 74 75 76 77 |
# File 'lib/animate_it/chapter_navigation.rb', line 70 def initialize(view, composition, interactive:, preset: :pills, mobile: nil, frame: 0) @view = view @composition = composition @interactive = interactive @preset = preset&.to_sym @mobile = mobile&.to_sym @frame = frame.to_i end |
Instance Method Details
#render(**attributes, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/animate_it/chapter_navigation.rb', line 79 def render(**attributes, &block) current_index = current_chapter_index chapters = @composition.chapters.each_with_index.map do |chapter, index| presenter = ChapterPresenter.new(@view, chapter, interactive: @interactive, state: chapter_state(chapter, index, current_index)) block ? @view.capture(presenter, &block) : presenter.default_control(preset: @preset || :pills) end classes = ["animate-it-chapters", @preset && "animate-it-chapters--#{@preset}", @mobile && "animate-it-chapters--mobile-#{@mobile}", attributes.delete(:class)].compact.join(" ") data = (attributes.delete(:data) || {}).merge(animate_it_chapter_navigation: true) attributes[:"aria-label"] ||= "Animation chapters" if @interactive tag = @interactive ? :nav : :div @view.tag.public_send(tag, @view.safe_join(chapters), **attributes, class: classes, data:) end |