Sha256: 4f4e99614a45319643241551477e5f7be540d3fead1e079d0d99f9c2be992fe3

Contents?: true

Size: 1.26 KB

Versions: 111

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

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

Version data entries

111 entries across 111 versions & 1 rubygems

Version Path
playbook_ui-10.6.1.pre.alpha1 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.6.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.5.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.4.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.3.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.2.1.alpha.sisensefix app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.2.1 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.2.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.1.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.3.pre.alpha.walkthrough2 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.3.pre.alpha.walkthrough app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.1.alpha.railscusticon app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.2.pre.alpha.pre.iconfix app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.1.alpha.rtflexfix app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.0.pre.alphafonts app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.1 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-10.0.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-9.19.0.pre.alpha.pre.fonts2 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-9.19.0 app/pb_kits/playbook/pb_docs/kit_example.rb
playbook_ui-9.19.0.pre.alphafonts app/pb_kits/playbook/pb_docs/kit_example.rb