Sha256: e5d2b22173f67d8f476e5c5232282c2a28206df90db5da0eace5471c17fe7461

Contents?: true

Size: 1.54 KB

Versions: 34

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbBody
    class Body
      include Playbook::Props
      include ActionView::Helpers
      
      partial "pb_body/body"

      prop :color, type: Playbook::Props::Enum,
                   values: %w[default light lighter],
                   default: "default"
      prop :status, type: Playbook::Props::Enum,
                    values: %w[neutral negative positive],
                    default: "neutral"
      prop :tag, type: Playbook::Props::Enum,
                 values: %w[h1 h2 h3 h4 h5 h6 p span div],
                 default: "div"
      prop :text
      prop :highlighting, type: Playbook::Props::Boolean,
                              default: false
      prop :highlighted_text, type: Playbook::Props::Array,
                              default: []

      def classname
        generate_classname("pb_body_kit", color_class, status_class)
      end

      def content
        highlighting ? apply_highlight : text
      end

    private

      def apply_highlight
        pb_highlight = Playbook::PbHighlight::Highlight.new() {"|"}
        pb_highlight_output = ApplicationController.renderer.render(partial: pb_highlight, as: :object)
        highlight_tags = pb_highlight_output.split("|")
        highlight(text, highlighted_text, highlighter: "#{highlight_tags.first.html_safe} \\1 #{highlight_tags.last.html_safe}")
      end

      def color_class
        color == "default" ? nil : color
      end

      def status_class
        status == "neutral" ? nil : status
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
playbook_ui-7.3.0.pre.alpha2 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.1.2 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.1.1.pre.alpha1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.1.1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.1.0.pre.alpha1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.1.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha15 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.1.pre.alpha14 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha14 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha13 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha12 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha11 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-6.8.1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-6.8.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-6.7.0.pre.alpha1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-6.7.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-6.6.1 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-7.0.0.pre.alpha10 app/pb_kits/playbook/pb_body/body.rb