Sha256: edee05316c4b1eda76b1314fd3eba94e217ef9a9af4d7b7948d0407b4105b585

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Vedeu

  module Cells

    # Presents a {Vedeu::Cells} member class as a HTML string.
    #
    # @api private
    #
    class HTML

      include Vedeu::Common

      # @param cell [void] The {Vedeu::Cells} class to be presented as
      #   HTML.
      # @param options [Hash] Options provided by
      #   {Vedeu::Renderers::HTML}.
      # @return [Vedeu::Cells::HTML]
      def initialize(cell, options = {})
        @cell    = cell
        @options = options || {}
      end

      # @return [String]
      def to_html
        "#{start_tag}#{style_attribute}>#{value}#{end_tag}"
      end

      protected

      # @!attribute [r] cell
      # @return [Vedeu::Cells]
      attr_reader :cell

      # @!attribute [r] options
      # @return [Hash]
      attr_reader :options

      private

      # @return [String]
      def background
        return '' unless cell.respond_to?(:background)

        cell.background.to_html
      end

      # @return [String]
      def end_tag
        options.fetch(:end_tag, '</td>')
      end

      # @return [String]
      def foreground
        return '' unless cell.respond_to?(:foreground)

        cell.foreground.to_html
      end

      # @return [String]
      def start_tag
        options.fetch(:start_tag, '<td')
      end

      # @return [String]
      def style_attribute
        return '' if absent?(background) && absent?(foreground)

        " style='#{background}#{foreground}'"
      end

      # @return [String]
      def value
        if cell.respond_to?(:as_html) && present?(cell.as_html)
          cell.as_html

        else
          '&nbsp;'

        end
      end

    end # HTML

  end # Cells

end # Vedeu

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/cells/support/html.rb
vedeu-0.8.31 lib/vedeu/cells/support/html.rb
vedeu-0.8.30 lib/vedeu/cells/support/html.rb
vedeu-0.8.29 lib/vedeu/cells/support/html.rb
vedeu-0.8.28 lib/vedeu/cells/support/html.rb
vedeu-0.8.27 lib/vedeu/cells/support/html.rb
vedeu-0.8.26 lib/vedeu/cells/support/html.rb
vedeu-0.8.25 lib/vedeu/cells/support/html.rb
vedeu-0.8.24 lib/vedeu/cells/support/html.rb
vedeu-0.8.23 lib/vedeu/cells/support/html.rb
vedeu-0.8.22 lib/vedeu/cells/support/html.rb
vedeu-0.8.21 lib/vedeu/cells/support/html.rb
vedeu-0.8.20 lib/vedeu/cells/support/html.rb
vedeu-0.8.19 lib/vedeu/cells/support/html.rb
vedeu-0.8.18 lib/vedeu/cells/support/html.rb
vedeu-0.8.17 lib/vedeu/cells/support/html.rb
vedeu-0.8.16 lib/vedeu/cells/support/html.rb