Sha256: 029359523bafece2cd7cb0364b389f94ed67038b0c40323154088dd8cf0dcf0f

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 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}"
    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}"
    end

  end # Presentation

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.6.25 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.24 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.23 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.22 lib/vedeu/output/presentation/presentation.rb
vedeu-0.6.21 lib/vedeu/output/presentation/presentation.rb