Sha256: 2705216d66c3377ec7499f81580bfad437ee03f58071b5142154e6f61fb66f07

Contents?: true

Size: 1.36 KB

Versions: 19

Compression:

Stored size: 1.36 KB

Contents

require 'glimmer/error'

module Glimmer
  module DSL
    # Represents a Glimmer DSL expression (e.g. label(:center) { ... })
    #
    # An expression object can interpret a keyword, args, and a block into a UI object
    #
    # Expressions subclasses follow the convention of using `and` and `or`
    # english versino of Ruby's boolean operations. This allows easy DSL-like
    # readability of the rules, and easy tagging with pd when troubleshooting.
    class Expression
      class << self
        def dsl
          @dsl ||= name.split(/::/)[-2].downcase.to_sym
        end
      end

      # Checks if it can interpret parameters (subclass must override)
      def can_interpret?(parent, keyword, *args, &block)
        raise Error, "#can_interpret? must be implemented by an Expression subclass"
      end

      # Interprets parameters (subclass must override)
      def interpret(parent, keyword, *args, &block)
        raise Error, "#interpret must be implemented by an Expression subclass"
      end

      # Adds block content to specified parent UI object (Optional)
      #
      # Only expressions that receive a content block should implement
      def add_content(parent, &block)
        # No Op by default
      end

      # Checks if object is a Symbol or a String
      def textual?(object)
        object.is_a?(Symbol) or object.is_a?(String)
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
glimmer-0.10.4 lib/glimmer/dsl/expression.rb
glimmer-0.10.3 lib/glimmer/dsl/expression.rb
glimmer-0.10.2 lib/glimmer/dsl/expression.rb
glimmer-0.10.1 lib/glimmer/dsl/expression.rb
glimmer-0.10.0 lib/glimmer/dsl/expression.rb
glimmer-0.9.5 lib/glimmer/dsl/expression.rb
glimmer-0.9.4 lib/glimmer/dsl/expression.rb
glimmer-0.9.3 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.7 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.6 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.5 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.4 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.3 lib/glimmer/dsl/expression.rb
glimmer-0.9.2 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.2 lib/glimmer/dsl/expression.rb
glimmer-0.9.1 lib/glimmer/dsl/expression.rb
glimmer-dsl-css-0.1.0 lib/glimmer/dsl/expression.rb
glimmer-dsl-opal-0.0.1 lib/glimmer/dsl/expression.rb
glimmer-0.9.0 lib/glimmer/dsl/expression.rb