macros4cuke 0.4.02 → 0.4.03

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmI3NDI4NzIzZjFiYjEwNjAyNjZhZTdlMTc0MzcwY2EyMWJlNzQyOA==
4
+ NmEwYWE3ZGQxYzQ3MzdiMzhmMDAxNDk1YWJkMGZhMmVlZWVlMTdhNA==
5
5
  data.tar.gz: !binary |-
6
- ZDU1NzNjYjk0MjFkYjFmYzE0NTAyZTM5NTk4MmY0MDc1NjUyN2FiZQ==
6
+ NjYwZDQwNDg0MmQ1MzlkN2QyNjVkNWU5OWZmODFkMmI4NDY3ZmRlNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjZjMWViYzg0NjdhNDA5YTlhMzU0YWQ1M2FiOTk1ZjJmZmU4YWVlMWEzOWU2
10
- OTRkZTlmYzU0M2I4YzFmZWU1NGEyNmQ5MjgwYTIzYzU4MjI0YmZhOGNkODAz
11
- N2Y1ZmI5NTcxMzI3MTljODJiZGQ5YTJhYWJhYmZkZjU5ODdkMDc=
9
+ NjMxYzAxMDYyNmNiMmFhZjEyNTRkNDAxMDk3NDc4MmQ2MmRjOTZiN2I2MDgx
10
+ YmRmMTljODRiMmNmYmU0NzE4ZjU3MGZmNTI5MDNmYTg1MDk2ZDRlZDk1ZWZm
11
+ MmRiMDYxZTJlYjI5YjkxOWFjMGQ1ZTgwZjVlMjkwODc2MzYzNjM=
12
12
  data.tar.gz: !binary |-
13
- MWI0YTkzZWMzMGQ0YjliNWJiMmEyNzYzYjY2YThmNjZkNDM1MTJmMTljMGMx
14
- N2Y4YmVkYjJlM2Y2YzAyM2U3Y2M3ZmE5NWE4MTI1YmEyMWNkMmNhZGI2NjA5
15
- OGIwY2JmMDAzY2U2MjNkOGI4N2I4MTlkMjQwNjU4OTc4Y2ZmNDI=
13
+ NTRiNTkwYjY2ODBmNmJlNDdiYmMwNDliNjQ3MDA3YzA3MmE2YWMwMWIzYmU4
14
+ NDBjZWE3OWY2OTYzNDgxNjEzZmYzYTVjYzE2MWVjMzA2ZjFiMWMwNDhhNWNh
15
+ NzM1YWE1ZTZlNDBmNTA1MDJiOTcwYTJiNDgyYTgyYjA3MWYyNDA=
data/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
- ### 0.4.02 / 2013-11_17
1
+ ### 0.4.03 / 2013-12-11
2
+ * [CHANGE] File `engine.rb`: Monolithic file splitted into more class-specific files.
3
+ * [CHANGE] File `constants.rb`: Removal of legacy app in comment.
4
+
5
+
6
+ ### 0.4.02 / 2013-11-17
2
7
  * [CHANGE] File `README.md`: Added section on new feature: capability to list all macros.
3
8
  * [CHANGE] Files from `macro_steps.rb`: Added the `require` to enable the new step.
4
9
 
5
- ### 0.4.01 / 2013-11_17
10
+ ### 0.4.01 / 2013-11-17
6
11
  * [CHANGE] File `.rubocop.yml`: Disabled a few new 0.15.0 cops
7
12
  * [CHANGE] Files from `lib` and `spec` dirs updated for Rubocop 0.15.0
8
13
 
@@ -5,9 +5,6 @@
5
5
  # to use the Macros4Cuke gem.
6
6
 
7
7
  require 'pp'
8
- #require_relative '../../lib/macros4cuke/macro-collection'
9
- #require_relative '../../lib/macros4cuke/formatting-service'
10
- #require_relative '../../lib/macros4cuke/formatter/to-gherkin'
11
8
 
12
9
  begin
13
10
  require 'simplecov' # Development dependency only...
@@ -3,6 +3,7 @@
3
3
 
4
4
  require_relative 'macro-collection'
5
5
 
6
+
6
7
  module Macros4Cuke # Module used as a namespace
7
8
 
8
9
 
@@ -3,12 +3,12 @@
3
3
 
4
4
  module Macros4Cuke # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.4.02'
6
+ Version = '0.4.03'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = 'Macro-steps for Cucumber'
10
10
 
11
- # Constant Macros4Cuke::RootDir contains the absolute path of Rodent's
11
+ # Constant Macros4Cuke::RootDir contains the absolute path of Macro4Cuke's
12
12
  # root directory. Note: it also ends with a slash character.
13
13
  unless defined?(RootDir)
14
14
  # The initialisation of constant RootDir is guarded in order
@@ -1,9 +1,13 @@
1
1
  # File: engine.rb
2
- # Purpose: Implementation of the MacroStep class.
2
+ # Purpose: Implementation of the Engine class.
3
3
 
4
4
  require 'strscan' # Use the StringScanner for lexical analysis.
5
5
  require_relative '../exceptions' # Load the custom exception classes.
6
6
 
7
+ require_relative 'template-element'
8
+ require_relative 'placeholder'
9
+ require_relative 'section' # Load the Section and ConditionalSection
10
+
7
11
 
8
12
  module Macros4Cuke # Module used as a namespace
9
13
 
@@ -81,170 +85,6 @@ class EOLine
81
85
  end # class
82
86
 
83
87
 
84
- # Base class used internally by the template engine.
85
- # The generalization of any element from a template that has one variable
86
- # whose actual value influences the rendition.
87
- class UnaryElement
88
- # The name of the placeholder/variable.
89
- attr_reader(:name)
90
-
91
- # @param aVarName [String] The name of the placeholder from a template.
92
- def initialize(aVarName)
93
- @name = aVarName
94
- end
95
-
96
- protected
97
-
98
- # This method has the same signature as the {Engine#render} method.
99
- # @return [Object] The actual value from the locals or context
100
- # that is assigned to the variable.
101
- def retrieve_value_from(aContextObject, theLocals)
102
- actual_value = theLocals[name]
103
- if actual_value.nil? && aContextObject.respond_to?(name.to_sym)
104
- actual_value = aContextObject.send(name.to_sym)
105
- end
106
-
107
- return actual_value
108
- end
109
-
110
- end # class
111
-
112
-
113
-
114
- # Class used internally by the template engine.
115
- # Represents a named placeholder in a template, that is,
116
- # a name placed between <..> in the template.
117
- # At rendition, a placeholder is replaced by the text value
118
- # that is associated with it.
119
- class Placeholder < UnaryElement
120
-
121
- public
122
-
123
- # Render the placeholder given the passed arguments.
124
- # This method has the same signature as the {Engine#render} method.
125
- # @return [String] The text value assigned to the placeholder.
126
- # Returns an empty string when no value is assigned to the placeholder.
127
- def render(aContextObject, theLocals)
128
- actual_value = retrieve_value_from(aContextObject, theLocals)
129
-
130
- result = case actual_value
131
- when NilClass
132
- ''
133
-
134
- when Array
135
- # TODO: Move away from hard-coded separator.
136
- actual_value.join('<br/>')
137
-
138
- when String
139
- actual_value
140
- else
141
- actual_value.to_s
142
- end
143
-
144
- return result
145
- end
146
-
147
- end # class
148
-
149
-
150
- # Base class used internally by the template engine.
151
- # Represents a section in a template, that is,
152
- # a set of template elements for which its rendition depends
153
- # on the value of a variable.
154
- class Section < UnaryElement
155
- # The child elements of the section
156
- attr_reader(:children)
157
-
158
- # @param aVarName [String] The name of the placeholder from a template.
159
- def initialize(aVarName)
160
- super(aVarName)
161
- @children = []
162
- end
163
-
164
- public
165
-
166
- # Add a child element as member of the section
167
- def add_child(aChild)
168
- children << aChild
169
- end
170
-
171
- # Retrieve all placeholder names that appear in the template.
172
- # @return [Array] The list of placeholder names.
173
- def variables()
174
- all_vars = children.each_with_object([]) do |a_child, subResult|
175
- case a_child
176
- when Placeholder
177
- subResult << a_child.name
178
- when Section
179
- subResult.concat(a_child.variables)
180
- else
181
- # Do nothing
182
- end
183
- end
184
-
185
- return all_vars.flatten.uniq
186
- end
187
-
188
-
189
- # Render the placeholder given the passed arguments.
190
- # This method has the same signature as the {Engine#render} method.
191
- # @return [String] The text value assigned to the placeholder.
192
- # Returns an empty string when no value is assigned to the placeholder.
193
- def render(aContextObject, theLocals)
194
- msg = "Method Section.#{__method__} must be implemented in subclass."
195
- fail(NotImplementedError, msg)
196
- end
197
-
198
- end # class
199
-
200
-
201
- # A specialized section in a template for which its rendition
202
- # depends on the (in)existence of an actual value bound to the variable name.
203
- class ConditionalSection < Section
204
- # A boolean that indicates whether the rendition condition is
205
- # the existence of a value for the variable (true)
206
- # or its inexistence (false).
207
- attr_reader(:existence)
208
-
209
- # @param aVarName [String] The name of the placeholder from a template.
210
- # @param renderWhenExisting [boolean] When true, render the children elements
211
- # if a value exists for the variable.
212
- def initialize(aVarName, renderWhenExisting = true)
213
- super(aVarName)
214
- @existence = renderWhenExisting
215
- end
216
-
217
- public
218
-
219
- # Render the placeholder given the passed arguments.
220
- # This method has the same signature as the {Engine#render} method.
221
- # @return [String] The text value assigned to the placeholder.
222
- # Returns an empty string when no value is assigned to the placeholder.
223
- def render(aContextObject, theLocals)
224
- actual_value = retrieve_value_from(aContextObject, theLocals)
225
- if (!actual_value.nil? && existence) || (actual_value.nil? && !existence)
226
- # Let render the children
227
- result = children.each_with_object('') do |a_child, sub_result|
228
- sub_result << a_child.render(aContextObject, theLocals)
229
- end
230
- else
231
- result = ''
232
- end
233
-
234
- return result
235
- end
236
-
237
-
238
- # @return [String] The original text representation of the tag.
239
- def to_s()
240
- return "<?#{name}>"
241
- end
242
-
243
- end # class
244
-
245
-
246
- SectionEndMarker = Struct.new(:name)
247
-
248
88
 
249
89
  # A very simple implementation of a templating engine.
250
90
  # Earlier versions of Macros4Cuke relied on the logic-less
@@ -0,0 +1,52 @@
1
+ # File: placeholder.rb
2
+ # Purpose: Implementation of the Placeholder class.
3
+
4
+ require_relative 'unary-element' # Load the superclass
5
+
6
+
7
+ module Macros4Cuke # Module used as a namespace
8
+
9
+ # Module containing all classes implementing the simple template engine
10
+ # used internally in Macros4Cuke.
11
+ module Templating
12
+
13
+ # Class used internally by the template engine.
14
+ # Represents a named placeholder in a template, that is,
15
+ # a name placed between <..> in the template.
16
+ # At rendition, a placeholder is replaced by the text value
17
+ # that is associated with it.
18
+ class Placeholder < UnaryElement
19
+
20
+ public
21
+
22
+ # Render the placeholder given the passed arguments.
23
+ # This method has the same signature as the {Engine#render} method.
24
+ # @return [String] The text value assigned to the placeholder.
25
+ # Returns an empty string when no value is assigned to the placeholder.
26
+ def render(aContextObject, theLocals)
27
+ actual_value = retrieve_value_from(aContextObject, theLocals)
28
+
29
+ result = case actual_value
30
+ when NilClass
31
+ ''
32
+
33
+ when Array
34
+ # TODO: Move away from hard-coded separator.
35
+ actual_value.join('<br/>')
36
+
37
+ when String
38
+ actual_value
39
+ else
40
+ actual_value.to_s
41
+ end
42
+
43
+ return result
44
+ end
45
+
46
+ end # class
47
+
48
+ end # module
49
+
50
+ end # module
51
+
52
+ # End of file
@@ -0,0 +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 inexistence (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
@@ -0,0 +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
@@ -0,0 +1,39 @@
1
+ # File: unary-element.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
+ # Base class used internally by the template engine.
10
+ # The generalization of any element from a template that has one variable
11
+ # whose actual value influences the rendition.
12
+ class UnaryElement
13
+ # The name of the placeholder/variable.
14
+ attr_reader(:name)
15
+
16
+ # @param aVarName [String] The name of the placeholder from a template.
17
+ def initialize(aVarName)
18
+ @name = aVarName
19
+ end
20
+
21
+ protected
22
+
23
+ # This method has the same signature as the {Engine#render} method.
24
+ # @return [Object] The actual value from the locals or context
25
+ # that is assigned to the variable.
26
+ def retrieve_value_from(aContextObject, theLocals)
27
+ actual_value = theLocals[name]
28
+ if actual_value.nil? && aContextObject.respond_to?(name.to_sym)
29
+ actual_value = aContextObject.send(name.to_sym)
30
+ end
31
+
32
+ return actual_value
33
+ end
34
+
35
+ end # class
36
+
37
+ end # module
38
+
39
+ # End of file
@@ -3,7 +3,7 @@
3
3
  require_relative '../../spec_helper'
4
4
 
5
5
  # Load the classes under test
6
- require_relative '../../../lib/macros4cuke/templating/engine'
6
+ require_relative '../../../lib/macros4cuke/templating/placeholder'
7
7
 
8
8
  module Macros4Cuke
9
9
 
@@ -1,9 +1,12 @@
1
1
  # File: section_spec.rb
2
2
 
3
3
  require_relative '../../spec_helper'
4
+ require_relative '../../../lib/macros4cuke/templating/template-element'
5
+ require_relative '../../../lib/macros4cuke/templating/placeholder'
4
6
 
5
7
  # Load the classes under test
6
- require_relative '../../../lib/macros4cuke/templating/engine'
8
+ require_relative '../../../lib/macros4cuke/templating/section'
9
+
7
10
 
8
11
  module Macros4Cuke
9
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macros4cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.02
4
+ version: 0.4.03
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-17 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -114,6 +114,10 @@ files:
114
114
  - lib/macros4cuke/macro-step-support.rb
115
115
  - lib/macros4cuke/macro-step.rb
116
116
  - lib/macros4cuke/templating/engine.rb
117
+ - lib/macros4cuke/templating/placeholder.rb
118
+ - lib/macros4cuke/templating/section.rb
119
+ - lib/macros4cuke/templating/template-element.rb
120
+ - lib/macros4cuke/templating/unary-element.rb
117
121
  - examples/demo/cucumber.yml
118
122
  - examples/demo/features/basic.feature
119
123
  - examples/demo/features/multiline.feature