glimmer-dsl-opal 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,42 +0,0 @@
1
- require 'glimmer/error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Represents a Glimmer DSL expression (e.g. label(:center) { ... })
6
- #
7
- # An expression object can interpret a keyword, args, and a block into a UI object
8
- #
9
- # Expressions subclasses follow the convention of using `and` and `or`
10
- # english versino of Ruby's boolean operations. This allows easy DSL-like
11
- # readability of the rules, and easy tagging with pd when troubleshooting.
12
- class Expression
13
- class << self
14
- def dsl
15
- @dsl ||= name.split(/::/)[-2].downcase.to_sym
16
- end
17
- end
18
-
19
- # Checks if it can interpret parameters (subclass must override)
20
- def can_interpret?(parent, keyword, *args, &block)
21
- raise Error, "#can_interpret? must be implemented by an Expression subclass"
22
- end
23
-
24
- # Interprets parameters (subclass must override)
25
- def interpret(parent, keyword, *args, &block)
26
- raise Error, "#interpret must be implemented by an Expression subclass"
27
- end
28
-
29
- # Adds block content to specified parent UI object (Optional)
30
- #
31
- # Only expressions that receive a content block should implement
32
- def add_content(parent, &block)
33
- # No Op by default
34
- end
35
-
36
- # Checks if object is a Symbol or a String
37
- def textual?(object)
38
- object.is_a?(Symbol) or object.is_a?(String)
39
- end
40
- end
41
- end
42
- end
@@ -1,48 +0,0 @@
1
- require 'glimmer/invalid_keyword_error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Expression handler for a Glimmer DSL specific expression
6
- #
7
- # Follows the Chain of Responsibility Design Pattern
8
- #
9
- # Handlers are configured in Glimmer::DSL in the right order
10
- # to attempt handling Glimmer DSL interpretation calls
11
- #
12
- # Each handler knows the next handler in the chain of responsibility.
13
- #
14
- # If it handles successfully, it returns. Otherwise, it forwards to the next
15
- # handler in the chain of responsibility
16
- class ExpressionHandler
17
- def initialize(expression)
18
- @expression = expression
19
- end
20
-
21
- # Handles interpretation of Glimmer DSL expression if expression supports it
22
- # If it succeeds, it returns the correct Glimmer DSL expression object
23
- # Otherwise, it forwards to the next handler configured via `#next=` method
24
- # If there is no handler next, then it raises an error
25
- def handle(parent, keyword, *args, &block)
26
- Glimmer::Config.logger&.debug "Attempting to handle #{keyword} with #{@expression.class.name.split(":").last}"
27
- if @expression.can_interpret?(parent, keyword, *args, &block)
28
- Glimmer::Config.logger&.debug "#{@expression.class.name} will handle expression keyword #{keyword}"
29
- return @expression
30
- elsif @next_expression_handler
31
- return @next_expression_handler.handle(parent, keyword, *args, &block)
32
- else
33
- # TODO see if we need a better response here (e.g. dev mode error raising vs production mode silent failure)
34
- message = "Glimmer keyword #{keyword} with args #{args} cannot be handled"
35
- message += " inside parent #{parent}" if parent
36
- message += "! Check the validity of the code."
37
- # Glimmer::Config.logger&.error message
38
- raise InvalidKeywordError, message
39
- end
40
- end
41
-
42
- # Sets the next handler in the expression handler chain of responsibility
43
- def next=(next_expression_handler)
44
- @next_expression_handler = next_expression_handler
45
- end
46
- end
47
- end
48
- end
@@ -1,12 +0,0 @@
1
- require 'glimmer/error'
2
-
3
- module Glimmer
4
- module DSL
5
- # Mixin that represents expressions that always have a content block
6
- module ParentExpression
7
- def add_content(parent, &block)
8
- block.call(parent)
9
- end
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- require 'glimmer/error'
2
- require 'glimmer/dsl/engine'
3
- require 'glimmer/dsl/expression'
4
-
5
- module Glimmer
6
- module DSL
7
- # Represents a StaticExpression for expressions where
8
- # the keyword does not vary dynamically. These static keywords are then
9
- # predefined as methods in Glimmer instead of needing method_missing
10
- #
11
- # StaticExpression subclasses may optionally implement `#can_interpret?`
12
- # (not needed if it only checks for keyword)
13
- #
14
- # StaticExpression subclasses must define `#interpret`.
15
- #
16
- # The direct parent namespace of a StaticExpression subclass must match the DSL name (case-insensitive)
17
- # (e.g. Glimmer::DSL::SWT::WidgetExpression has a DSL of :swt)
18
- class StaticExpression < Expression
19
- class << self
20
- def inherited(base)
21
- Glimmer::DSL::Engine.add_static_expression(base.new)
22
- super
23
- end
24
-
25
- def keyword
26
- @keyword ||= name.split(/::/).last.sub(/Expression$/, '').underscore
27
- end
28
- end
29
-
30
- # Subclasses may optionally implement
31
- def can_interpret?(parent, keyword, *args, &block)
32
- true
33
- end
34
- end
35
- end
36
- end
@@ -1,7 +0,0 @@
1
- module Glimmer
2
- module DSL
3
- # Mixin that represents expressions that are always at the top with parent nil
4
- module TopLevelExpression
5
- end
6
- end
7
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class Error < RuntimeError
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Glimmer
2
- # Represents Glimmer errors that occur due to invalid use of Glimmer
3
- # without handing control flow back to original method_missing
4
- class InvalidKeywordError < RuntimeError
5
- end
6
- end