example_puzzles/compile_examples.rb
# Compiles a given node of the YAML tree into markdown.
# - If the node is an Array, it will be compiled and concatenated.
# - If the node contains :section, it will be compiled recursively.
# - If the node contains :example, it is an example that will be executed.
# - If the node contains :comment, it is a paragraph.
#
# @param node [Object] the object that was parsed from the YAML document.
# @param level [Fixnum] the current subsection level.
# @return [String] the examples compiled into markdown.
Compiles a given node of the YAML tree into markdown.
If the node is an Array, it will be compiled and concatenated.
If the node contains :section, it will be compiled recursively.
If the node contains :example, it is an example that will be executed.
If the node contains :comment, it is a paragraph.
Compiles a given node of the YAML tree into markdown . If the node is an Array it will be compiled and concatenated . If the node contains : section it will be compiled recursively . If the node contains : example it is an example that will be executed . If the node contains : comment it is a paragraph .
def compile(node, level=1)
  return node.collect{|e| compile(e,level)}.join("\n") if node.is_a?(Array)
  if node.has_key?(:section) then
    "#{("#"*level)}#{node[:section]}\n" <<
    "#{node[:comment]}\n" <<
    compile(node[:content], level+1)
  elsif node.has_key?(:example)
    example_to_markdown(verify(execute(node)), level)
  elsif node.has_key?(:comment)
    "#{node[:comment]}\n"
  end
end
def compile ( node , level = 1 ) return node . collect { | e | compile ( e , level ) } . join ( "\n" ) if node . is_a? ( Array ) if node . has_key? ( :section ) then "#{("#"*level)}#{node[:section]}\n" << "#{node[:comment]}\n" << compile ( node [ :content ] , level + 1 ) elsif node . has_key? ( :example ) example_to_markdown ( verify ( execute ( node ) ) , level ) elsif node . has_key? ( :comment ) "#{node[:comment]}\n" end end
Compiles a given node of the YAML tree into markdown.
Compiles a given node of the YAML tree into markdown .
the examples compiled into markdown.
the examples compiled into markdown .
String
node
the object that was parsed from the YAML document.
the object that was parsed from the YAML document .
level
the current subsection level.
the current subsection level .