lib/erbook/document.rb
# Data from the format specification file.
Data from the format specification file.
Data from the format specification file .
def calculate_node_outputs
      actual_output_by_node = {}
      visitor = lambda do |n|
         allow child nodes to calculate their actual
         output and to set their identifier as Nodeoutput
         we do this nodes first because this node's
         content contains the child nodes' output
        n.children.each {|c| visitor.call c }
         calculate the output for this node
        actual_output = Template.new(
          "{@format_file}:nodes:{n.type}:output",
          n.definition['output'].to_s.chomp
        ).render_with(@template_vars.merge(:@node => n))
         reveal child nodes' actual output in this node's actual output
        n.children.each do |c|
          if c.silent?
             this child's output is not meant to be revealed at this time
            next
          elsif c.inline?
            actual_output[c.output] = actual_output_by_node[c]
          else
             remove <p> around block-level child (added by Markdown)
            actual_output.sub! %r{(<p>\s*)?{
              Regexp.quote c.output
            }(\s*</p>)?} do
              actual_output_by_node[c] +
                if $1 and $2
                  ''
                else
                  [$1, $2].join
                end
            end
          end
        end
        actual_output_by_node[n] = actual_output
         allow the parent node to calculate its actual
         output without interference from the output of
         this node (Nodeto_s is aliased to Nodeoutput)
         this assumes that having this node's string
         representation be a consecutive sequence of digits
         will not interfere with the text-to-whatever
         transformation defined by the format specification
        n.output = Digest::SHA1.digest(n.object_id.to_s).unpack('I*').join
      end
      @roots.each {|n| visitor.call n }
       replace the temporary identifier with each node's actual output
      @nodes.each {|n| n.output = actual_output_by_node[n] }
    end
def calculate_node_outputs actual_output_by_node = { } visitor = lambda do | n | n . children . each { | c | visitor . call c } actual_output = Template . new ( "#{@format_file}:nodes:#{n.type}:output" , n . definition [ 'output' ] . to_s . chomp ) . render_with ( @template_vars . merge ( :@node => n ) ) n . children . each do | c | if c . silent? next elsif c . inline? actual_output [ c . output ] = actual_output_by_node [ c ] else actual_output . sub! %r{ (<p> \s *)? #{ Regexp . quote c . output } ( \s *</p>)? } do actual_output_by_node [ c ] + if $1 and $2 '' else [ $1 , $2 ] . join end end end end actual_output_by_node [ n ] = actual_output n . output = Digest :: SHA1 . digest ( n . object_id . to_s ) . unpack ( 'I*' ) . join end @roots . each { | n | visitor . call n } @nodes . each { | n | n . output = actual_output_by_node [ n ] } end
Data from the format specification file.
Data from the format specification file .
# # allow child nodes to calculate their actual # output and to set their identifier as Node#output # # we do this nodes first because this node's # content contains the child nodes' output # # calculate the output for this node # reveal child nodes' actual output in this node's actual output # this child's output is not meant to be revealed at this time # remove <p> around block-level child (added by Markdown) # # allow the parent node to calculate its actual # output without interference from the output of # this node (Node#to_s is aliased to Node#output) # # this assumes that having this node's string # representation be a consecutive sequence of digits # will not interfere with the text-to-whatever # transformation defined by the format specification # # replace the temporary identifier with each node's actual output