Sha256: 6d208eb7c370a02e97eb3548070b8c6bdd421963d8e4a5280252cd810da8c40f

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

module Vedeu

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

    # @return [Vedeu::Colour]
    def colour
      Vedeu::Colour.coerce(@colour)
    end

    # @return [Vedeu::Colour]
    def colour=(value)
      @colour = Vedeu::Colour.coerce(value)
    end

    # @return [Vedeu::Style]
    def style
      Vedeu::Style.coerce(@style)
    end

    # @return [Vedeu::Style]
    def style=(value)
      @style = Vedeu::Style.coerce(value)
    end

    # Converts the colours and styles to escape sequences, and if 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

    private

    # @return [String]
    def parent_colour
      return '' unless parent

      parent.colour
    end

    # @return [String]
    def parent_style
      return '' unless parent

      parent.style
    end

    # Renders the colour attributes of the receiver, yields (to then render the
    # the styles) and once returned, attempts to set the colours back to the
    # those of the receiver's parent.
    #
    # @return [String]
    def render_colour
      [
        colour,
        yield,
        parent_colour
      ].join
    end

    # @return [String]
    def render_position
      if self.respond_to?(:position) && position.is_a?(Position)
        position.to_s { yield }

      else
        yield

      end
    end

    # Renders the style attributes of the receiver, yields (to then render the
    # next model, or finally, the content) and once returned, attempts to set
    # the style back to that of the receiver's parent.
    #
    # @return [String]
    def render_style
      [
        style,
        yield,
        parent_style
      ].join
    end

  end # Presentation

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.3.4 lib/vedeu/presentation/presentation.rb
vedeu-0.3.3 lib/vedeu/presentation/presentation.rb
vedeu-0.3.2 lib/vedeu/presentation/presentation.rb