Sha256: a27e1c2a1e9f18214a044f2a07db33db534fd308a33d0790eabd9f7b7a1c4283

Contents?: true

Size: 1.35 KB

Versions: 25

Compression:

Stored size: 1.35 KB

Contents

module Lookbook
  # Helpers for documentation page templates
  #
  # @api public
  module PageHelper
    # Returns the URL path to a page.
    #
    # @api private
    # @param id [String, PageEntity] The id or PageEntity instance to generate a URL path for
    def page_path(id)
      page = id.is_a?(PageEntity) ? id : Engine.pages.find_by_id(id)
      if page.present?
        page.docs_path
      else
        Lookbook.logger.warn "Could not find page with id ':#{id}'"
      end
    end

    # Render a 'live' embed of a component preview.
    #
    # If no scenario name is provided then the default (first) preview
    # scenario will be rendered in the embed.
    #
    # @param preview [String] Name of the preview class to embed
    # @param scenario [String] Example method name
    # @param opts [Hash] Options hash
    def embed(preview, scenario = nil, **opts)
      preview_entity = if preview.is_a?(Symbol)
        Engine.previews.find_by_path(preview)
      else
        Engine.previews.find_by_preview_class(preview)
      end
      scenario_entity = scenario ? preview_entity&.scenario(scenario) : preview_entity&.default_scenario
      opts[:actions] ||= ["inspect", "open"]

      lookbook_render Embed::Component.new(
        scenario: scenario_entity,
        params: opts.fetch(:params, {}),
        options: opts.except(:params)
      )
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
lookbook-2.3.5 lib/lookbook/helpers/page_helper.rb
lookbook-2.3.4 lib/lookbook/helpers/page_helper.rb
lookbook-2.3.3 lib/lookbook/helpers/page_helper.rb
lookbook-2.3.2 lib/lookbook/helpers/page_helper.rb
lookbook-2.3.0 lib/lookbook/helpers/page_helper.rb
lookbook-2.2.2 lib/lookbook/helpers/page_helper.rb
lookbook-2.2.1 lib/lookbook/helpers/page_helper.rb
lookbook-2.2.0 lib/lookbook/helpers/page_helper.rb
lookbook-2.1.1 lib/lookbook/helpers/page_helper.rb
lookbook-2.1.0 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.5 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.4 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.3 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.2 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.1 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.0 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.0.rc.3 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.0.rc.2 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.0.rc.1 lib/lookbook/helpers/page_helper.rb
lookbook-2.0.0.beta.9 lib/lookbook/helpers/page_helper.rb