Sha256: 1e586987822b4e878fccaff540182f1e5ad500516d00119d6aa8a9e833717c51

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

require 'vedeu/output/presentation/colour'
require 'vedeu/output/presentation/style'

module Vedeu

  # This module allows the sharing of presentation concerns between the models:
  # Interface, View, Line and Stream.
  #
  module Presentation

    include Vedeu::Presentation::Colour
    include Vedeu::Presentation::Style

    # 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

    # 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
      if self.respond_to?(:position) && position.is_a?(Vedeu::Position)
        position.to_s { yield }

      else
        yield

      end
    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

14 entries across 14 versions & 1 rubygems

Version Path
vedeu-0.6.4 lib/vedeu/output/presentation.rb
vedeu-0.6.3 lib/vedeu/output/presentation.rb
vedeu-0.6.2 lib/vedeu/output/presentation.rb
vedeu-0.6.1 lib/vedeu/output/presentation.rb
vedeu-0.6.0 lib/vedeu/output/presentation.rb
vedeu-0.5.13 lib/vedeu/output/presentation.rb
vedeu-0.5.12 lib/vedeu/output/presentation.rb
vedeu-0.5.11 lib/vedeu/output/presentation.rb
vedeu-0.5.10 lib/vedeu/output/presentation.rb
vedeu-0.5.9 lib/vedeu/output/presentation.rb
vedeu-0.5.8 lib/vedeu/output/presentation.rb
vedeu-0.5.7 lib/vedeu/output/presentation.rb
vedeu-0.5.6 lib/vedeu/output/presentation.rb
vedeu-0.5.5 lib/vedeu/output/presentation.rb