Sha256: 55677af641f474164cd61056d13e677862c1bf6a6d2d79df55b20e9a68cb76b5

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

require 'glimmer'
require 'glimmer/dsl/expression'
require 'glimmer/dsl/parent_expression'
require 'glimmer/ui/custom_widget'
require 'glimmer/ui/custom_shell'

module Glimmer
  module DSL
    class CustomWidgetExpression < Expression
      include ParentExpression
      def can_interpret?(parent, keyword, *args, &block)
        custom_widget_class = UI::CustomWidget.for(keyword)
        custom_widget_class and
          (widget?(parent) or
          custom_widget_class.ancestors.include?(UI::CustomShell))
      end

      def interpret(parent, keyword, *args, &block)
        options = args.last.is_a?(Hash) ? args.pop : {}
        UI::CustomWidget.for(keyword).new(parent, *args, options, &block)
      end

      def add_content(parent, &block)
        # TODO consider avoiding source_location
        if block.source_location == parent.content&.__getobj__.source_location
          parent.content.call(parent) unless parent.content.called?
        else
          super
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
glimmer-0.5.11 lib/glimmer/dsl/custom_widget_expression.rb
glimmer-0.5.10 lib/glimmer/dsl/custom_widget_expression.rb
glimmer-0.5.9 lib/glimmer/dsl/custom_widget_expression.rb