lib/macros4cuke/templating/engine.rb in macros4cuke-0.5.15 vs lib/macros4cuke/templating/engine.rb in macros4cuke-0.5.16

- old
+ new

@@ -61,11 +61,11 @@ # (when not present in the locals Hash). # @param theLocals [Hash] Contains one or more pairs of the form: # tag/placeholder name => actual value. # @return [String] The rendition of the template given # the passed argument values. - def render(aContextObject = Object.new, theLocals) + def render(aContextObject = Object.new, theLocals = {}) return '' if @representation.empty? prev = nil result = @representation.each_with_object('') do |element, subResult| # Output compaction rules: @@ -79,11 +79,10 @@ end return result end - # Retrieve all placeholder names that appear in the template. # @return [Array] The list of placeholder names. def variables() # The result will be cached/memoized... @variables ||= begin @@ -152,13 +151,13 @@ raise(StandardError, "Missing opening chevron '<'.") if unbalance < 0 end raise(StandardError, "Missing closing chevron '>'.") if unbalance == 1 end - - private + private + # Create the internal representation of the given template. def compile(aSourceTemplate) # Split the input text into lines. input_lines = aSourceTemplate.split(/\r\n?|\n/) @@ -166,11 +165,11 @@ raw_lines = input_lines.map do |line| line_items = self.class.parse(line) line_items.each do |(kind, text)| # A tag text cannot be empty nor blank next if (kind != :dynamic) || !text.strip.empty? - + raise(EmptyArgumentError.new(line.strip)) end line_items end @@ -210,11 +209,10 @@ end return line_rep end - # Apply rule: if last item in line is an end of section marker, # then place eoline before that item. # Otherwise, end the line with a eoline marker. def line_rep_ending(theLineRep) if theLineRep.last.is_a?(SectionEndMarker) @@ -224,11 +222,10 @@ else theLineRep << EOLine.new end end - # @param aCouple [Array] a two-element array of the form: [kind, text] # Where kind must be one of :static, :dynamic def compile_couple(aCouple) (kind, text) = aCouple @@ -239,11 +236,10 @@ end return result end - # Parse the contents of a tag entry. # @param aText [String] The text that is enclosed between chevrons. def parse_tag(aText) # Recognize the first character if aText =~ %r{^[\?/]} @@ -306,9 +302,10 @@ if sections.empty? msg = 'found while no corresponding section is open.' raise(StandardError, msg_prefix + msg) end return if marker.name == sections.last.name + msg = "doesn't match current section '#{sections.last.name}'." raise(StandardError, msg_prefix + msg) end end # class end # module