macros4cuke 0.4.08 → 0.4.09

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +4 -0
  5. data/README.md +5 -3
  6. data/features/{1_Basics → 1_the_basics}/README.md +0 -0
  7. data/features/{1_Basics → 1_the_basics}/demo01.feature +5 -5
  8. data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/README.md +0 -0
  9. data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/demo02.feature +10 -10
  10. data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/demo03.feature +5 -5
  11. data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/README.md +0 -0
  12. data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/demo04.feature +5 -5
  13. data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/demo05.feature +4 -4
  14. data/features/{4_Conditional_steps → 4_conditional_steps}/demo06.feature +18 -16
  15. data/features/{5_Goodies → 5_goodies}/demo07.feature +6 -5
  16. data/features/{5_Goodies → 5_goodies}/demo08.feature +0 -0
  17. data/features/step_definitions/demo_steps.rb +5 -4
  18. data/lib/macro_steps.rb +6 -6
  19. data/lib/macros4cuke/coll-walker-factory.rb +12 -12
  20. data/lib/macros4cuke/constants.rb +4 -4
  21. data/lib/macros4cuke/formatter/all-notifications.rb +8 -8
  22. data/lib/macros4cuke/formatter/to-gherkin.rb +2 -2
  23. data/lib/macros4cuke/formatter/to-null.rb +10 -10
  24. data/lib/macros4cuke/formatting-service.rb +74 -74
  25. data/lib/macros4cuke/macro-collection.rb +13 -13
  26. data/lib/macros4cuke/macro-step-support.rb +19 -12
  27. data/lib/macros4cuke/macro-step.rb +48 -48
  28. data/lib/macros4cuke/templating/engine.rb +79 -79
  29. data/lib/macros4cuke/templating/placeholder.rb +52 -52
  30. data/lib/macros4cuke/templating/section.rb +116 -116
  31. data/lib/macros4cuke/templating/template-element.rb +88 -88
  32. data/lib/macros4cuke/templating/unary-element.rb +37 -37
  33. data/lib/macros4cuke.rb +1 -1
  34. data/spec/macros4cuke/coll-walker-factory_spec.rb +269 -269
  35. data/spec/macros4cuke/formatter/to-gherkin_spec.rb +5 -5
  36. data/spec/macros4cuke/formatter/to-null_spec.rb +62 -62
  37. data/spec/macros4cuke/formatter/to-trace_spec.rb +8 -8
  38. data/spec/macros4cuke/formatting-service_spec.rb +7 -7
  39. data/spec/macros4cuke/macro-collection_spec.rb +3 -3
  40. data/spec/macros4cuke/macro-step-support_spec.rb +4 -4
  41. data/spec/macros4cuke/macro-step_spec.rb +8 -8
  42. data/spec/macros4cuke/templating/comment_spec.rb +45 -0
  43. data/spec/macros4cuke/templating/engine_spec.rb +23 -23
  44. data/spec/macros4cuke/templating/eo-line_spec.rb +39 -0
  45. data/spec/macros4cuke/templating/section_spec.rb +1 -1
  46. data/spec/macros4cuke/templating/static_text_spec.rb +45 -0
  47. data/spec/macros4cuke/use-sample-collection.rb +7 -7
  48. data/spec/spec_helper.rb +3 -3
  49. metadata +31 -14
@@ -1,116 +1,116 @@
1
- # File: section.rb
2
- # Purpose: Implementation of the Section and ConditionalSection classes.
3
-
4
- require_relative 'unary-element' # Load the superclass
5
-
6
-
7
- module Macros4Cuke # Module used as a namespace
8
-
9
-
10
- # Module containing all classes implementing the simple template engine
11
- # used internally in Macros4Cuke.
12
- module Templating
13
-
14
- # Base class used internally by the template engine.
15
- # Represents a section in a template, that is,
16
- # a set of template elements for which its rendition depends
17
- # on the value of a variable.
18
- class Section < UnaryElement
19
- # The child elements of the section
20
- attr_reader(:children)
21
-
22
- # @param aVarName [String] The name of the placeholder from a template.
23
- def initialize(aVarName)
24
- super(aVarName)
25
- @children = []
26
- end
27
-
28
- public
29
-
30
- # Add a child element as member of the section
31
- def add_child(aChild)
32
- children << aChild
33
- end
34
-
35
- # Retrieve all placeholder names that appear in the template.
36
- # @return [Array] The list of placeholder names.
37
- def variables()
38
- all_vars = children.each_with_object([]) do |a_child, subResult|
39
- case a_child
40
- when Placeholder
41
- subResult << a_child.name
42
- when Section
43
- subResult.concat(a_child.variables)
44
- else
45
- # Do nothing
46
- end
47
- end
48
-
49
- return all_vars.flatten.uniq
50
- end
51
-
52
-
53
- # Render the placeholder given the passed arguments.
54
- # This method has the same signature as the {Engine#render} method.
55
- # @return [String] The text value assigned to the placeholder.
56
- # Returns an empty string when no value is assigned to the placeholder.
57
- def render(aContextObject, theLocals)
58
- msg = "Method Section.#{__method__} must be implemented in subclass."
59
- fail(NotImplementedError, msg)
60
- end
61
-
62
- end # class
63
-
64
-
65
- # A specialized section in a template for which its rendition
66
- # depends on the (in)existence of an actual value bound to the variable name.
67
- class ConditionalSection < Section
68
- # A boolean that indicates whether the rendition condition is
69
- # the existence of a value for the variable (true)
70
- # or its non-existence (false).
71
- attr_reader(:existence)
72
-
73
- # @param aVarName [String] The name of the placeholder from a template.
74
- # @param renderWhenExisting [boolean] When true, render the children elements
75
- # if a value exists for the variable.
76
- def initialize(aVarName, renderWhenExisting = true)
77
- super(aVarName)
78
- @existence = renderWhenExisting
79
- end
80
-
81
- public
82
-
83
- # Render the placeholder given the passed arguments.
84
- # This method has the same signature as the {Engine#render} method.
85
- # @return [String] The text value assigned to the placeholder.
86
- # Returns an empty string when no value is assigned to the placeholder.
87
- def render(aContextObject, theLocals)
88
- actual_value = retrieve_value_from(aContextObject, theLocals)
89
- if (!actual_value.nil? && existence) || (actual_value.nil? && !existence)
90
- # Let render the children
91
- result = children.each_with_object('') do |a_child, sub_result|
92
- sub_result << a_child.render(aContextObject, theLocals)
93
- end
94
- else
95
- result = ''
96
- end
97
-
98
- return result
99
- end
100
-
101
-
102
- # @return [String] The original text representation of the tag.
103
- def to_s()
104
- return "<?#{name}>"
105
- end
106
-
107
- end # class
108
-
109
-
110
- SectionEndMarker = Struct.new(:name)
111
-
112
- end # module
113
-
114
- end # module
115
-
116
- # End of file
1
+ # File: section.rb
2
+ # Purpose: Implementation of the Section and ConditionalSection classes.
3
+
4
+ require_relative 'unary-element' # Load the superclass
5
+
6
+
7
+ module Macros4Cuke # Module used as a namespace
8
+
9
+
10
+ # Module containing all classes implementing the simple template engine
11
+ # used internally in Macros4Cuke.
12
+ module Templating
13
+
14
+ # Base class used internally by the template engine.
15
+ # Represents a section in a template, that is,
16
+ # a set of template elements for which its rendition depends
17
+ # on the value of a variable.
18
+ class Section < UnaryElement
19
+ # The child elements of the section
20
+ attr_reader(:children)
21
+
22
+ # @param aVarName [String] The name of the placeholder from a template.
23
+ def initialize(aVarName)
24
+ super(aVarName)
25
+ @children = []
26
+ end
27
+
28
+ public
29
+
30
+ # Add a child element as member of the section
31
+ def add_child(aChild)
32
+ children << aChild
33
+ end
34
+
35
+ # Retrieve all placeholder names that appear in the template.
36
+ # @return [Array] The list of placeholder names.
37
+ def variables()
38
+ all_vars = children.each_with_object([]) do |a_child, subResult|
39
+ case a_child
40
+ when Placeholder
41
+ subResult << a_child.name
42
+ when Section
43
+ subResult.concat(a_child.variables)
44
+ else
45
+ # Do nothing
46
+ end
47
+ end
48
+
49
+ return all_vars.flatten.uniq
50
+ end
51
+
52
+
53
+ # Render the placeholder given the passed arguments.
54
+ # This method has the same signature as the {Engine#render} method.
55
+ # @return [String] The text value assigned to the placeholder.
56
+ # Returns an empty string when no value is assigned to the placeholder.
57
+ def render(aContextObject, theLocals)
58
+ msg = "Method Section.#{__method__} must be implemented in subclass."
59
+ fail(NotImplementedError, msg)
60
+ end
61
+
62
+ end # class
63
+
64
+
65
+ # A specialized section in a template for which its rendition
66
+ # depends on the (in)existence of an actual value bound to the variable name.
67
+ class ConditionalSection < Section
68
+ # A boolean that indicates whether the rendition condition is
69
+ # the existence of a value for the variable (true)
70
+ # or its non-existence (false).
71
+ attr_reader(:existence)
72
+
73
+ # @param aVarName [String] The name of the placeholder from a template.
74
+ # @param renderWhenExisting [boolean] When true, render the children elements
75
+ # if a value exists for the variable.
76
+ def initialize(aVarName, renderWhenExisting = true)
77
+ super(aVarName)
78
+ @existence = renderWhenExisting
79
+ end
80
+
81
+ public
82
+
83
+ # Render the placeholder given the passed arguments.
84
+ # This method has the same signature as the {Engine#render} method.
85
+ # @return [String] The text value assigned to the placeholder.
86
+ # Returns an empty string when no value is assigned to the placeholder.
87
+ def render(aContextObject, theLocals)
88
+ actual_value = retrieve_value_from(aContextObject, theLocals)
89
+ if (!actual_value.nil? && existence) || (actual_value.nil? && !existence)
90
+ # Let render the children
91
+ result = children.each_with_object('') do |a_child, sub_result|
92
+ sub_result << a_child.render(aContextObject, theLocals)
93
+ end
94
+ else
95
+ result = ''
96
+ end
97
+
98
+ return result
99
+ end
100
+
101
+
102
+ # @return [String] The original text representation of the tag.
103
+ def to_s()
104
+ return "<?#{name}>"
105
+ end
106
+
107
+ end # class
108
+
109
+
110
+ SectionEndMarker = Struct.new(:name)
111
+
112
+ end # module
113
+
114
+ end # module
115
+
116
+ # End of file
@@ -1,88 +1,88 @@
1
- # File: template-element.rb
2
- # Purpose: Implementation of core classes used in the template engine.
3
-
4
-
5
- require_relative '../exceptions' # Load the custom exception classes.
6
-
7
-
8
-
9
- module Macros4Cuke # Module used as a namespace
10
-
11
-
12
- # Module containing all classes implementing the simple template engine
13
- # used internally in Macros4Cuke.
14
- module Templating
15
-
16
- # Class used internally by the template engine.
17
- # Represents a static piece of text from a template.
18
- # A static text is a text that is reproduced verbatim
19
- # when rendering a template.
20
- class StaticText
21
- # The static text extracted from the original template.
22
- attr_reader(:source)
23
-
24
-
25
- # @param aSourceText [String] A piece of text extracted
26
- # from the template that must be rendered verbatim.
27
- def initialize(aSourceText)
28
- @source = aSourceText
29
- end
30
-
31
- public
32
-
33
- # Render the static text.
34
- # This method has the same signature as the {Engine#render} method.
35
- # @return [String] Static text is returned verbatim ("as is")
36
- def render(aContextObject, theLocals)
37
- return source
38
- end
39
- end # class
40
-
41
-
42
- # Class used internally by the template engine.
43
- # Represents a comment from a template.
44
- # A static text is a text that is reproduced verbatim
45
- # when rendering a template.
46
- class Comment
47
- # The comment as extracted from the original template.
48
- attr_reader(:source)
49
-
50
-
51
- # @param aSourceText [String] A piece of text extracted
52
- # from the template that must be rendered verbatim.
53
- def initialize(aSourceText)
54
- @source = aSourceText
55
- end
56
-
57
- public
58
-
59
- # Render the comment.
60
- # Comments are rendered as empty text. This is necessary because
61
- # Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
62
- # This method has the same signature as the {Engine#render} method.
63
- # @return [String] Empty string ("as is")
64
- def render(aContextObject, theLocals)
65
- return ''
66
- end
67
- end # class
68
-
69
-
70
- # Class used internally by the template engine.
71
- # Represents an end of line that must be rendered as such.
72
- class EOLine
73
-
74
- public
75
-
76
- # Render an end of line.
77
- # This method has the same signature as the {Engine#render} method.
78
- # @return [String] An end of line marker. Its exact value is OS-dependent.
79
- def render(aContextObject, theLocals)
80
- return "\n"
81
- end
82
- end # class
83
-
84
- end # module
85
-
86
- end # module
87
-
88
- # End of file
1
+ # File: template-element.rb
2
+ # Purpose: Implementation of core classes used in the template engine.
3
+
4
+
5
+ require_relative '../exceptions' # Load the custom exception classes.
6
+
7
+
8
+
9
+ module Macros4Cuke # Module used as a namespace
10
+
11
+
12
+ # Module containing all classes implementing the simple template engine
13
+ # used internally in Macros4Cuke.
14
+ module Templating
15
+
16
+ # Class used internally by the template engine.
17
+ # Represents a static piece of text from a template.
18
+ # A static text is a text that is reproduced verbatim
19
+ # when rendering a template.
20
+ class StaticText
21
+ # The static text extracted from the original template.
22
+ attr_reader(:source)
23
+
24
+
25
+ # @param aSourceText [String] A piece of text extracted
26
+ # from the template that must be rendered verbatim.
27
+ def initialize(aSourceText)
28
+ @source = aSourceText
29
+ end
30
+
31
+ public
32
+
33
+ # Render the static text.
34
+ # This method has the same signature as the {Engine#render} method.
35
+ # @return [String] Static text is returned verbatim ("as is")
36
+ def render(aContextObject, theLocals)
37
+ return source
38
+ end
39
+ end # class
40
+
41
+
42
+ # Class used internally by the template engine.
43
+ # Represents a comment from a template.
44
+ # A static text is a text that is reproduced verbatim
45
+ # when rendering a template.
46
+ class Comment
47
+ # The comment as extracted from the original template.
48
+ attr_reader(:source)
49
+
50
+
51
+ # @param aSourceText [String] A piece of text extracted
52
+ # from the template that must be rendered verbatim.
53
+ def initialize(aSourceText)
54
+ @source = aSourceText
55
+ end
56
+
57
+ public
58
+
59
+ # Render the comment.
60
+ # Comments are rendered as empty text. This is necessary because
61
+ # Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
62
+ # This method has the same signature as the {Engine#render} method.
63
+ # @return [String] Empty string ("as is")
64
+ def render(aContextObject, theLocals)
65
+ return ''
66
+ end
67
+ end # class
68
+
69
+
70
+ # Class used internally by the template engine.
71
+ # Represents an end of line that must be rendered as such.
72
+ class EOLine
73
+
74
+ public
75
+
76
+ # Render an end of line.
77
+ # This method has the same signature as the {Engine#render} method.
78
+ # @return [String] An end of line marker. Its exact value is OS-dependent.
79
+ def render(aContextObject, theLocals)
80
+ return "\n"
81
+ end
82
+ end # class
83
+
84
+ end # module
85
+
86
+ end # module
87
+
88
+ # End of file
@@ -1,37 +1,37 @@
1
- # File: unary-element.rb
2
- # Purpose: Implementation of the Section and ConditionalSection classes.
3
-
4
-
5
- module Macros4Cuke # Module used as a namespace
6
-
7
- # Base class used internally by the template engine.
8
- # The generalization of any element from a template that has one variable
9
- # whose actual value influences the rendition.
10
- class UnaryElement
11
- # The name of the placeholder/variable.
12
- attr_reader(:name)
13
-
14
- # @param aVarName [String] The name of the placeholder from a template.
15
- def initialize(aVarName)
16
- @name = aVarName
17
- end
18
-
19
- protected
20
-
21
- # This method has the same signature as the {Engine#render} method.
22
- # @return [Object] The actual value from the locals or context
23
- # that is assigned to the variable.
24
- def retrieve_value_from(aContextObject, theLocals)
25
- actual_value = theLocals[name]
26
- if actual_value.nil? && aContextObject.respond_to?(name.to_sym)
27
- actual_value = aContextObject.send(name.to_sym)
28
- end
29
-
30
- return actual_value
31
- end
32
-
33
- end # class
34
-
35
- end # module
36
-
37
- # End of file
1
+ # File: unary-element.rb
2
+ # Purpose: Implementation of the Section and ConditionalSection classes.
3
+
4
+
5
+ module Macros4Cuke # Module used as a namespace
6
+
7
+ # Base class used internally by the template engine.
8
+ # The generalization of any element from a template that has one variable
9
+ # whose actual value influences the rendition.
10
+ class UnaryElement
11
+ # The name of the placeholder/variable.
12
+ attr_reader(:name)
13
+
14
+ # @param aVarName [String] The name of the placeholder from a template.
15
+ def initialize(aVarName)
16
+ @name = aVarName
17
+ end
18
+
19
+ protected
20
+
21
+ # This method has the same signature as the {Engine#render} method.
22
+ # @return [Object] The actual value from the locals or context
23
+ # that is assigned to the variable.
24
+ def retrieve_value_from(aContextObject, theLocals)
25
+ actual_value = theLocals[name]
26
+ if actual_value.nil? && aContextObject.respond_to?(name.to_sym)
27
+ actual_value = aContextObject.send(name.to_sym)
28
+ end
29
+
30
+ return actual_value
31
+ end
32
+
33
+ end # class
34
+
35
+ end # module
36
+
37
+ # End of file
data/lib/macros4cuke.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # File: macros4cuke.rb
2
- # This file acts as a jumping-off point for loading dependencies expected
2
+ # This file acts as a jumping-off point for loading dependencies expected
3
3
  # for a Macros4Cuke user.
4
4
 
5
5
  require_relative './macros4cuke/constants'