Skip to content

Preview Components that require helpers #955

Answered by henrikbjorn
henrikbjorn asked this question in Q&A
Discussion options

You must be logged in to vote

Gonna answer my own questions by throwing code at it:

# frozen_string_literal: true

class Settings::BreadcrumbsComponent < ApplicationComponent

  def initialize(breadcrumbs: [], **options)
    @breadcrumbs = breadcrumbs.map { |b| wrap_element(b) }

    @options = options.merge(
      separator: ' <span class=\'seperator\'>></span> '
    )
  end

  def breadcrumbs
    builder.render.html_safe
  end

  protected

  def builder
    @builder ||= BreadcrumbsOnRails::Breadcrumbs::SimpleBuilder.new(self, @breadcrumbs || helpers.breadcrumbs, @options)
  end

  def wrap_element(elm)
    return elm unless elm.is_a? Array

    BreadcrumbsOnRails::Breadcrumbs::Element.new(b.first, b.last)
  end
end

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by henrikbjorn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant