Sha256: 7bace7a5465cb70d44d0c78da1f2c13a16303678cc89d73f7fd6be50d633060a

Contents?: true

Size: 836 Bytes

Versions: 49

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

module Ariadne
  # Conditionally renders a `Ariadne::BaseComponent` around the given content. If the given condition
  # is true, a `Ariadne::BaseComponent` will render around the content. If the condition is false, only
  # the content is rendered.
  class ConditionalWrapper < Ariadne::BaseComponent
    # @param condition [Boolean] Whether or not to wrap the content in a `Ariadne::BaseComponent`.
    # @param base_component_arguments [Hash] The arguments to pass to `Ariadne::BaseComponent`.
    def initialize(condition:, **base_component_arguments)
      @condition = condition
      @base_component_arguments = base_component_arguments
    end

    def call
      return content unless @condition

      BaseComponent.new(**@base_component_arguments).render_in(self) { content }
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.93.2 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.93.1 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.93 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.92 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.91 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.90 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.89.1 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.89 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.88 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.87 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.9 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.8 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.7 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.6 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.5 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.4 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.3 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.2 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86.1 app/components/ariadne/conditional_wrapper.rb
ariadne_view_components-0.0.86 app/components/ariadne/conditional_wrapper.rb