Sha256: 672923d831d0eaf5549103006a22803b26f7b59d6270c5668c71bbb34cc71df9

Contents?: true

Size: 927 Bytes

Versions: 18

Compression:

Stored size: 927 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("/", "-")

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lookbook-1.0.8 app/helpers/lookbook/page_helper.rb
lookbook-1.0.7 app/helpers/lookbook/page_helper.rb
lookbook-1.0.6 app/helpers/lookbook/page_helper.rb
lookbook-1.0.5 app/helpers/lookbook/page_helper.rb
lookbook-1.0.4 app/helpers/lookbook/page_helper.rb
lookbook-1.0.3 app/helpers/lookbook/page_helper.rb
lookbook-1.0.2 app/helpers/lookbook/page_helper.rb
lookbook-1.0.1 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.rc.3 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.rc.2 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.rc.1 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.8 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.7 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.6 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.5 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.4 app/helpers/lookbook/page_helper.rb
lookbook-1.0.0.beta.3 app/helpers/lookbook/page_helper.rb