Sha256: 7607c0a461d60a511e80c826985cff932f652acf1cb2fc7b6aa3dda644862090

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

# Scarpe::TextWidget

class Scarpe
  class TextWidget < Scarpe::Widget
    class << self
      # rubocop:disable Lint/MissingSuper
      def inherited(subclass)
        Scarpe::Widget.widget_classes ||= []
        Scarpe::Widget.widget_classes << subclass
      end
      # rubocop:enable Lint/MissingSuper
    end
  end

  class << self
    def default_text_widget_with(element)
      class_name = element.capitalize

      widget_class = Class.new(Scarpe::TextWidget) do
        display_property :content

        def initialize(content)
          @content = content

          super

          create_display_widget
        end
      end
      Scarpe.const_set class_name, widget_class
      widget_class.class_eval do
        display_property :content
      end
    end
  end
end

Scarpe.default_text_widget_with(:code)
Scarpe.default_text_widget_with(:em)
Scarpe.default_text_widget_with(:strong)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scarpe-0.2.1 lib/scarpe/text_widget.rb
scarpe-0.2.0 lib/scarpe/text_widget.rb