lib/macros4cuke/templating/engine.rb in macros4cuke-0.3.29 vs lib/macros4cuke/templating/engine.rb in macros4cuke-0.3.30
- old
+ new
@@ -140,16 +140,16 @@
# Retrieve all placeholder names that appear in the template.
# @return [Array] The list of placeholder names.
def variables()
all_vars = children.each_with_object([]) do |a_child, subResult|
case a_child
- when Placeholder
- subResult << a_child.name
- when Section
- subResult.concat(a_child.variables)
- else
- # Do nothing
+ when Placeholder
+ subResult << a_child.name
+ when Section
+ subResult.concat(a_child.variables)
+ else
+ # Do nothing
end
end
return all_vars.flatten.uniq
end
@@ -275,18 +275,18 @@
def variables()
# The result will be cached/memoized...
@variables ||= begin
vars = @representation.each_with_object([]) do |element, subResult|
case element
- when Placeholder
- subResult << element.name
-
- when Section
- subResult.concat(element.variables)
-
- else
- # Do nothing
+ when Placeholder
+ subResult << element.name
+
+ when Section
+ subResult.concat(element.variables)
+
+ else
+ # Do nothing
end
end
vars.flatten.uniq
end
@@ -331,14 +331,12 @@
# var. equals count_of(<) - count_of(>): can only be 0 or temporarily 1
unbalance = 0
no_escaped.each_char do |ch|
case ch
- when '<'
- unbalance += 1
- when '>'
- unbalance -= 1
+ when '<' then unbalance += 1
+ when '>' then unbalance -= 1
end
raise StandardError, "Nested opening chevron '<'." if unbalance > 1
raise StandardError, "Missing opening chevron '<'." if unbalance < 0
end
@@ -377,22 +375,22 @@
# Apply the rule: when a line just consist of spaces
# and a section element, then remove all the spaces from that line.
section_item = nil
line_to_squeeze = line_rep.all? do |item|
case item
- when StaticText
- item.source =~ /\s+/
-
- when Section, SectionEndMarker
- if section_item.nil?
- section_item = item
- true
- else
- false
- end
+ when StaticText
+ item.source =~ /\s+/
+
+ when Section, SectionEndMarker
+ if section_item.nil?
+ section_item = item
+ true
else
false
+ end
+ else
+ false
end
end
if line_to_squeeze && ! section_item.nil?
line_rep = [section_item]
else
@@ -421,16 +419,13 @@
# Where kind must be one of :static, :dynamic
def compile_couple(aCouple)
(kind, text) = aCouple
result = case kind
- when :static
- StaticText.new(text)
-
- when :dynamic
- parse_tag(text)
- end
+ when :static then StaticText.new(text)
+ when :dynamic then parse_tag(text)
+ end
return result
end
# Parse the contents of a tag entry.
@@ -463,23 +458,22 @@
def compile_sections(flat_sequence)
open_sections = [] # The list of nested open sections
compiled = flat_sequence.each_with_object([]) do |element, subResult|
case element
- when Section
- open_sections << element
-
- when SectionEndMarker
- validate_section_end(element, open_sections)
- subResult << open_sections.pop()
-
+ when Section
+ open_sections << element
+
+ when SectionEndMarker
+ validate_section_end(element, open_sections)
+ subResult << open_sections.pop()
+
+ else
+ if open_sections.empty?
+ subResult << element
else
- if open_sections.empty?
- subResult << element
- else
- open_sections.last.add_child(element)
- end
-
+ open_sections.last.add_child(element)
+ end
end
end
unless open_sections.empty?
error_message = "Unterminated section #{open_sections.last}."
\ No newline at end of file