Sha256: 52cef164ba7c0e4375e37f5842fad800fab2c665676517f5a293bbef365cfe4c

Contents?: true

Size: 1.33 KB

Versions: 174

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

# rubocop:disable Style/CaseLikeIf

module Playbook
  module PbDocs
    class KitExample < Playbook::KitBase
      include Playbook::Markdown::Helper

      prop :kit, type: Playbook::Props::String, required: true
      prop :example_title, type: Playbook::Props::String, required: true
      prop :example_key, type: Playbook::Props::String, required: true
      prop :show_code, type: Playbook::Props::Boolean, default: true
      prop :type, type: Playbook::Props::Enum, values: %w[rails react], default: "rails"
      prop :dark, type: Playbook::Props::Boolean, default: false

      def example
        if type == "rails"
          render inline: source
        elsif type == "react"
          react_component example_key.camelize, { dark: dark }
        end
      end

      def description
        @description ||= read_kit_file("_#{example_key}.md")
      end

      def highlighter
        type.eql?("rails") ? "erb" : "react"
      end

      def source
        @source ||= begin
          extension = type == "react" ? "jsx" : "html.erb"
          read_kit_file("_#{example_key}.#{extension}")
        end
      end

    private

      def read_kit_file(*args)
        path = ::Playbook.kit_path(kit, "docs", *args)
        path.exist? ? path.read : ""
      end
    end
  end
end

# rubocop:enable Style/CaseLikeIf

Version data entries

174 entries across 174 versions & 1 rubygems

Version Path
playbook_ui-12.9.1.pre.alpha.menucleanup345 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.9.1.pre.alpha.menucleanup342 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.9.1 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.9.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark301 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark300 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.PLAY649mapkitstyles299 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep298 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep297 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease296 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease295 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease294 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.8.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease293 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease292 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease291 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.alpharubyrelease281 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.menu2 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1.pre.alpha.menu1 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-12.7.1 app/pb_kits/playbook/pb_docs/kit_example.rb