Sha256: ba2fc2d66f11399948bf04c1f17646326c8c6c01766bf8f62b704fa51e9bf7f9

Contents?: true

Size: 1.55 KB

Versions: 25

Compression:

Stored size: 1.55 KB

Contents

module Coco
  class Page < Coco::Component
    include Concerns::AcceptsOptions

    component_name :page_layout

    accepts_option :width, from: [:full, :constrained], default: :constrained

    renders_one :header
    renders_many :hidden_sections

    renders_many :sections, ->(tag_name = :section, **kwargs, &block) do
      stack.with_space(@spacing) unless stack.starts_with_spacer?
      stack.with_item(tag_name, **kwargs) { block&.call }
    end

    renders_one :previous_link, ->(**kwargs) do
      Coco::PagerButton.new(**kwargs, direction: :previous, class: "page-control-previous")
    end

    renders_one :next_link, ->(**kwargs) do
      Coco::PagerButton.new(**kwargs, direction: :next, class: "page-control-next")
    end

    renders_one :poll_controller, ->(interval) do
      Coco::PollController.new(interval: interval)
    end

    before_render do
      with_poll_controller(@poll) unless poll_controller? || @poll.nil?
      with_next_link(href: @next_page) if @next_page
      with_previous_link(href: @previous_page) if @previous_page

      with_section(class: "contents") { content } if content.present?
      stack.with_space(@spacing) unless stack.ends_with_spacer?
    end

    delegate :with_space, to: :stack

    def initialize(spacing: 4, poll: nil, **kwargs)
      @poll = poll
      @previous_page = kwargs[:previous]
      @next_page = kwargs[:next]
      @spacing = spacing
    end

    def stack
      @stack ||= Coco::Stack.new(
        spacing: @spacing,
        direction: :vertical,
        class: "page-body-content"
      )
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
coveragebook_components-0.16.0 app/components/coco/layout/page/page.rb
coveragebook_components-0.15.0 app/components/coco/layout/page/page.rb
coveragebook_components-0.14.0 app/components/coco/layout/page/page.rb
coveragebook_components-0.13.1 app/components/coco/layout/page/page.rb
coveragebook_components-0.13.0 app/components/coco/layout/page/page.rb