Sha256: f20b690b6d8da21176925836371c61b80c6280aead343cd3ba82168c47e65794

Contents?: true

Size: 1.35 KB

Versions: 31

Compression:

Stored size: 1.35 KB

Contents

require 'rabbit/element/text-renderer'

module Rabbit
  module Element
    module TextElement
      include TextRenderer

      attr_reader :text

      def initialize(text)
        super()
        @text = text
      end

      def text=(new_text)
        old_text = @text
        @text = new_text
        dirty! if old_text != @text
        @text
      end

      def substitute_text
        result = yield(@text.dup)
        return false if result == @text
        case result
        when Array
          new_elements = result.collect do |element|
            if element.is_a?(Base)
              element
            else
              new_element = clone
              new_element.text = element
              new_element
            end
          end
          parent.replace_element(self, *new_elements)
        else
          self.text = result
        end
        true
      end

      def draw_element(canvas, x, y, w, h, simulation)
        unless simulation
          draw_layout(canvas, x, y)
        end
        [x + width, y, w - width, h]
      end

      def to_html(generator)
        text_to_html(generator)
      end

      def empty?
        @text.nil? or /\A\s*\z/ =~ @text
      end

      def inspect(verbose=false)
        if verbose
          super()
        else
          "<#{self.class.name} #{@text.inspect}>"
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
rabbit-3.0.3 lib/rabbit/element/text-element.rb
rabbit-3.0.2 lib/rabbit/element/text-element.rb
rabbit-3.0.1 lib/rabbit/element/text-element.rb
rabbit-3.0.0 lib/rabbit/element/text-element.rb
rabbit-2.2.1 lib/rabbit/element/text-element.rb
rabbit-2.2.0 lib/rabbit/element/text-element.rb
rabbit-2.1.9 lib/rabbit/element/text-element.rb
rabbit-2.1.8 lib/rabbit/element/text-element.rb
rabbit-2.1.7 lib/rabbit/element/text-element.rb
rabbit-2.1.6 lib/rabbit/element/text-element.rb
rabbit-2.1.5 lib/rabbit/element/text-element.rb
rabbit-2.1.4 lib/rabbit/element/text-element.rb
rabbit-2.1.3 lib/rabbit/element/text-element.rb
rabbit-2.1.2 lib/rabbit/element/text-element.rb
rabbit-2.1.1 lib/rabbit/element/text-element.rb
rabbit-2.1.0 lib/rabbit/element/text-element.rb
rabbit-2.0.9 lib/rabbit/element/text-element.rb
rabbit-2.0.8 lib/rabbit/element/text-element.rb
rabbit-2.0.7 lib/rabbit/element/text-element.rb
rabbit-2.0.6 lib/rabbit/element/text-element.rb