class Glimmer::DSL::Expression
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 printout with puts_debuggerer when troubleshooting.
Public Class Methods
# File lib/glimmer/dsl/expression.rb, line 35 def dsl @dsl ||= name.split(/::/)[-2].downcase.to_sym end
Public Instance Methods
Adds block content to newly interpreted parent object (Optional)
Only expressions that receive a content block should implement
# File lib/glimmer/dsl/expression.rb, line 53 def add_content(new_parent, keyword, *args, &block) # No Op by default end
Executes code around the ‘interpret_and_add_content` block, which invokes `interpret` and `add_content` when called without args (parent, keyword, args, block are supplied automatically). Clients may invoke yield as an alternative to calling `interpret_and_add_content` directly. This method takes parent, keyword, args, block in case they are needed in its around logic.
# File lib/glimmer/dsl/expression.rb, line 63 def around(parent, keyword, args, block, &interpret_and_add_content) interpret_and_add_content.call end
Checks if it can interpret parameters (subclass must override)
# File lib/glimmer/dsl/expression.rb, line 41 def can_interpret?(parent, keyword, *args, &block) raise Error, "#can_interpret? must be implemented by an Expression subclass" end
Interprets parameters (subclass must override)
# File lib/glimmer/dsl/expression.rb, line 46 def interpret(parent, keyword, *args, &block) raise Error, "#interpret must be implemented by an Expression subclass" end
Checks if object is a Symbol or a String
# File lib/glimmer/dsl/expression.rb, line 68 def textual?(object) object.is_a?(Symbol) or object.is_a?(String) end