Sha256: 77234c737355cdada85b875d6e92a2d223e0363288bbac3a651edd7b3324dfb0

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rabbit-1.0.4 lib/rabbit/element/text-element.rb
rabbit-1.0.3 lib/rabbit/element/text-element.rb
rabbit-1.0.2 lib/rabbit/element/text-element.rb
rabbit-1.0.1 lib/rabbit/element/text-element.rb
rabbit-1.0.0 lib/rabbit/element/text-element.rb
rabbit-0.9.3 lib/rabbit/element/text-element.rb
rabbit-0.9.2 lib/rabbit/element/text-element.rb
rabbit-0.9.1 lib/rabbit/element/text-element.rb
rabbit-0.9.0 lib/rabbit/element/text-element.rb
rabbit-0.6.4 lib/rabbit/element/text-element.rb
rabbit-0.6.3 lib/rabbit/element/text-element.rb
rabbit-0.6.2 lib/rabbit/element/text-element.rb