Sha256: 77ceb269876a3c25fb83038ae1f670e80d328230d04375a981c8cae5e0dc5ad3

Contents?: true

Size: 789 Bytes

Versions: 12

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true

module Playbook
  module PbKitHelper
    def pb_rails(kit, props: {}, &block)
      previous = prefix_partial_path_with_controller_namespace
      self.prefix_partial_path_with_controller_namespace = false
      kit = build_view_model(kit.to_s, props, &block)
      render(partial: kit, as: :object)
    ensure
      self.prefix_partial_path_with_controller_namespace = previous
    end

  private

    def is_subkit?(kit)
      kit.match(%r{[/\\]})
    end

    def build_view_model(kit, props, &block)
      folder = is_subkit?(kit) ? kit.split("/")[0] : kit
      item = is_subkit?(kit) ? kit.split("/")[-1] : kit
      class_name = "Playbook::Pb#{folder.camelize}::#{item.camelize}"
      class_name.safe_constantize.new(props, &block)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
playbook_ui-7.14.0.pre.alpha1 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.16.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.15.1 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.15.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.14.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.13.0.pre.alpha1 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.13.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.12.1 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.12.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.11.1 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.11.0 app/helpers/playbook/pb_kit_helper.rb
playbook_ui-7.11.0.pre.alpha1 app/helpers/playbook/pb_kit_helper.rb