Module: AnimateIt::ChapterNavigationHelper

Defined in:
lib/animate_it/chapter_navigation.rb

Instance Method Summary collapse

Instance Method Details

#animate_it_chapter_navigation(composition: nil, preset: nil, mobile: nil, hide_when_embedded: false, frame: nil, **attributes) ⇒ Object

Raises:

  • (ArgumentError)


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/animate_it/chapter_navigation.rb', line 140

def animate_it_chapter_navigation(
  composition: nil, preset: nil, mobile: nil, hide_when_embedded: false, frame: nil, **attributes, &
)
  target = composition || instance_variable_get(:@composition)
  raise ArgumentError, "animate_it_chapter_navigation requires a composition" unless target

  target.chapters.validate!
  data = (attributes.delete(:data) || {}).merge(animate_it_hide_when_embedded: hide_when_embedded ? "true" : "false")
  attributes[:style] = ["--animate-it-chapter-count: #{target.chapters.count}", attributes[:style]].compact.join(";")
  builder = ChapterNavigationBuilder.new(
    self, target, interactive: false, preset:, mobile:, frame: frame || instance_variable_get(:@frame) || 0
  )
  safe_join(
    [
      tag.style(AnimateIt::EmbedStyles.chapter_source.html_safe, data: { animate_it_chapter_styles: true }),
      builder.render(**attributes, data:, &)
    ]
  )
end