Sha256: 5c202cbe9ec1c1217d187f1731c4f98791b3b58a2f5727f25a5329c5c6c03472

Contents?: true

Size: 1.26 KB

Versions: 34

Compression:

Stored size: 1.26 KB

Contents

module Vedeu

  module Presentation

    include Vedeu::Presentation::Colour
    include Vedeu::Presentation::Styles

    # Converts the colours and styles to escape sequences, and when
    # the parent model has previously set the colour and style,
    # reverts back to that for consistent formatting.
    #
    # @return [String] An escape sequence with value interpolated.
    def to_s
      render_position { render_colour { render_style { value } } }
    end
    alias_method :to_str, :to_s

    private

    # Returns a boolean indicating the model has a position
    # attribute.
    #
    # @return [Boolean]
    def position?
      self.respond_to?(:position) && position.is_a?(Vedeu::Geometry::Position)
    end

    # Renders the colour attributes of the receiver and yields (to
    # then render the styles).
    #
    # @return [String]
    def render_colour
      "#{colour}#{yield}".freeze
    end

    # @return [String]
    def render_position
      return yield unless position?

      position.to_s { yield }
    end

    # Renders the style attributes of the receiver and yields (to
    # then render the next model, or finally, the content).
    #
    # @return [String]
    def render_style
      "#{style}#{yield}".freeze
    end

  end # Presentation

end # Vedeu

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
vedeu-0.6.60 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.59 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.58 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.57 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.56 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.54 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.53 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.52 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.51 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.50 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.49 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.48 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.47 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.46 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.45 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.44 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.43 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.42 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.41 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.40 lib/vedeu/output/presentation/presentation.rb