Sha256: 0c580c235181ca5b69ca92a3494d77db9a4298d3fbf3aaa42aa858909ca64c9d

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module Trestle
  class Toolbar
    # The toolbar Context is the object that is yielded to a toolbar block and handles the delegation of builder methods.
    class Context
      attr_reader :builder

      def initialize(builder, enumerator, *args)
        @builder, @enumerator = builder, enumerator
        @args = args
      end

      def group
        if @current_group
          yield
        else
          @current_group = []
          yield
          @enumerator << @current_group
          @current_group = nil
        end
      end

    private
      def self.ruby2_keywords(*)
      end unless respond_to?(:ruby2_keywords, true)

      ruby2_keywords def method_missing(name, *args, &block)
        result = builder.send(name, *args, &block)

        if builder.builder_methods.include?(name)
          group { @current_group << result }
        else
          result
        end
      end

      def respond_to_missing?(name, include_all=false)
        builder.respond_to?(name) || super
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trestle-0.10.0 lib/trestle/toolbar/context.rb
trestle-0.10.0.pre2 lib/trestle/toolbar/context.rb