lib/glimmer/dsl/engine.rb in glimmer-1.0.5 vs lib/glimmer/dsl/engine.rb in glimmer-1.0.6
- old
+ new
@@ -1,18 +1,18 @@
# Copyright (c) 2007-2020 Andy Maleh
-#
+#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
-#
+#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
-#
+#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
@@ -49,23 +49,23 @@
raise e if static_expression_dsl.nil? || !Glimmer::DSL::Engine.static_expressions[keyword][static_expression_dsl].is_a?(TopLevelExpression)
end
end
if interpretation
interpretation
- else
+ else
raise Glimmer::Error, "Unsupported keyword: #{keyword}" unless static_expression_dsl || retrieved_static_expression
Glimmer::DSL::Engine.dsl_stack.push(static_expression_dsl || Glimmer::DSL::Engine.dsl)
static_expression = Glimmer::DSL::Engine.static_expressions[keyword][Glimmer::DSL::Engine.dsl]
if !static_expression.can_interpret?(Glimmer::DSL::Engine.parent, keyword, *args, &block)
raise Error, "Invalid use of Glimmer keyword #{keyword} with args #{args} under parent #{Glimmer::DSL::Engine.parent}"
else
Glimmer::Config.logger.info {"#{static_expression.class.name} will handle expression keyword #{keyword}"}
Glimmer::DSL::Engine.interpret_expression(static_expression, keyword, *args, &block)
end
end
- end
- end
+ end
+ end
end
class << self
extend Forwardable
@@ -113,11 +113,11 @@
end
# Static expressions indexed by keyword and dsl
def static_expressions
@static_expressions ||= {}
- end
+ end
# Sets dynamic expression chains of responsibility. Useful for internal testing
attr_writer :dynamic_expression_chains_of_responsibility
# Sets static expressions. Useful for internal testing
@@ -130,19 +130,19 @@
#
# They are used in order following the Chain of Responsibility Design
# Pattern when interpretting a DSL expression
def add_dynamic_expressions(dsl_namespace, *expression_names)
expression_names = expression_names.flatten
- dsl = dsl_namespace.name.split("::").last.downcase.to_sym
+ dsl = dsl_namespace.name.split("::").last.downcase.to_sym
dynamic_expression_chains_of_responsibility[dsl] = expression_names.reverse.map do |expression_name|
expression_class(dsl_namespace, expression_name).new
end.reduce(nil) do |last_expresion_handler, expression|
Glimmer::Config.logger.info {"Adding dynamic expression: #{expression.class.name}"}
expression_handler = ExpressionHandler.new(expression)
expression_handler.next = last_expresion_handler if last_expresion_handler
expression_handler
- end
+ end
end
def add_static_expression(static_expression)
Glimmer::Config.logger.info {"Adding static expression: #{static_expression.class.name}"}
keyword = static_expression.class.keyword
@@ -159,11 +159,11 @@
def expression_class_name(expression_name)
"#{expression_name}_expression".camelcase(:upper)
end
# Interprets Glimmer dynamic DSL expression consisting of keyword, args, and block (e.g. shell(:no_resize) { ... })
- def interpret(keyword, *args, &block)
+ def interpret(keyword, *args, &block)
return puts(MESSAGE_NO_DSLS) if no_dsls?
keyword = keyword.to_s
dynamic_expression_dsl = (dynamic_expression_chains_of_responsibility.keys - disabled_dsls).first if dsl.nil?
dsl_stack.push(dynamic_expression_dsl || dsl)
expression = dynamic_expression_chains_of_responsibility[dsl].handle(parent, keyword, *args, &block)
@@ -183,10 +183,10 @@
#
# For example, a shell widget would get properties set and children added
def add_content(parent, expression, &block)
if block_given? && expression.is_a?(ParentExpression)
dsl_stack.push(expression.class.dsl)
- parent_stack.push(parent)
+ parent_stack.push(parent)
begin
expression.add_content(parent, &block)
ensure
parent_stack.pop
dsl_stack.pop