Sha256: 142eeebaa3dbcaba18f8b86acab483bfcfb2f86c660776f5073aa7c6cb1b6543

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

require_relative 'components/style_not_found_error'
require_relative 'contextual_classes'

module Bootstrap
  module ViewHelpers
    class Component
      attr_reader :view, :options, :block, :style

      def initialize(view_context, options, &block)
        @view = view_context
        parse_options(options)
        @block = block
      end

      def to_html; end

      protected

      delegate :content_tag, :safe_join, :concat, :capture, :link_to,
               :button_tag, to: :view

      def defaults
        { style: ContextualClasses::PRIMARY }
      end

      def assign_and_validate_style
        style = options.delete(:style) || defaults[:style]
        return @style = style if ContextualClasses.valid?(style)
        raise Components::StyleNotFoundError, style
      end

      def parse_options(options)
        @options = options
        assign_and_validate_style
      end
    end

    module Components; end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bootstrap-view_helpers-0.0.3 lib/bootstrap/view_helpers/component.rb
bootstrap-view_helpers-0.0.2 lib/bootstrap/view_helpers/component.rb