Sha256: 896cf2ca9b94c96e8ca610627ffea6b59be5ea00710f6c1e2a9574fed1817c69

Contents?: true

Size: 926 Bytes

Versions: 8

Compression:

Stored size: 926 Bytes

Contents

module Lookbook
  module PageHelper
    include Utils

    def page_path(id)
      page = id.is_a?(Page) ? id : Lookbook.pages.find(id)
      if page.present?
        lookbook_page_path page.lookup_path
      else
        Lookbook.logger.warn "Could not find page with id ':#{id}'"
      end
    end

    def embed(*args, params: {}, type: :preview, max_height: nil, **opts)
      return unless args.any?

      @embed_counter ||= 0

      preview_lookup = args.first.is_a?(Symbol) ? args.first : preview_class_path(args.first)
      preview = Lookbook.previews.find(preview_lookup)
      example = args[1] ? preview&.example(args[1]) : preview&.default_example

      embed_id = "#{url_for}/embed/#{example.lookup_path}".delete_prefix("/").tr("/", "-")

      lookbook_render :embed,
        id: embed_id,
        example: example,
        params: params,
        max_height: max_height,
        opts: opts
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lookbook-1.3.4 app/helpers/lookbook/page_helper.rb
lookbook-1.3.3 app/helpers/lookbook/page_helper.rb
lookbook-1.3.1 app/helpers/lookbook/page_helper.rb
lookbook-1.3.0 app/helpers/lookbook/page_helper.rb
lookbook-1.2.1 app/helpers/lookbook/page_helper.rb
lookbook-1.2.0 app/helpers/lookbook/page_helper.rb
lookbook-1.1.1 app/helpers/lookbook/page_helper.rb
lookbook-1.1.0 app/helpers/lookbook/page_helper.rb