Sha256: 952b53f143383992c532cae911d61aab988379ea47b2b63925bd305e161b2a57

Contents?: true

Size: 1.41 KB

Versions: 127

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

# :nocov:
module Primer
  module Yard
    # Helper methods for documentation generated in Lookbook pages.
    module LookbookDocsHelper
      # Adheres to the same signature as Primer::Yard::DocsHelper#link_to_component so link_to_component
      # may be used in a Gatsby or Lookbook context and produce the correct link for each platform.
      #
      # @param component [Class] The component class to link to.
      # @return [String] The link, either in HTML or markdown format.
      def link_to_component(component)
        backend = Primer::Yard::LookbookPagesBackend.new(Primer::Yard::Registry.make, nil)
        component_ref = Primer::Yard::ComponentManifest.ref_for(component)
        page = backend.page_for(component_ref)

        # If the page_path method is available, we're being rendered into HTML by Lookbook
        # and should emit an HTML <a> tag. No page_path means we're being rendered into
        # markdown by LookbookPagesBackend and should emit a markdown + ERB link that
        # Lookbook will eventually render on page load.
        if respond_to?(:page_path)
          link_to(page.docs.short_name, page_path(page.page_id.to_sym.inspect))
        else
          # rubocop:disable Rails/OutputSafety
          "[#{page.docs.short_name}](<%= page_path(#{page.page_id.to_sym.inspect}) %>)".html_safe
          # rubocop:enable Rails/OutputSafety
        end
      end
    end
  end
end

Version data entries

127 entries across 127 versions & 2 rubygems

Version Path
primer_view_components-0.35.2 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.49.1 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.49.0 lib/primer/yard/lookbook_docs_helper.rb
primer_view_components-0.35.1 lib/primer/yard/lookbook_docs_helper.rb
primer_view_components-0.35.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.48.2 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.48.1 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.48.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.47.1 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.47.0 lib/primer/yard/lookbook_docs_helper.rb
primer_view_components-0.34.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.46.1 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.46.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.45.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.44.3 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.44.2 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.44.1 lib/primer/yard/lookbook_docs_helper.rb
primer_view_components-0.33.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.44.0 lib/primer/yard/lookbook_docs_helper.rb
openproject-primer_view_components-0.43.1 lib/primer/yard/lookbook_docs_helper.rb