Sha256: 099d6f30574d21b86dee5110363f8796b32e10bcfb04ece8e0a6eef12f7f4686

Contents?: true

Size: 1.12 KB

Versions: 31

Compression:

Stored size: 1.12 KB

Contents

# @Opulent
module Opulent
  # @Nodes
  module Nodes
    # @Define
    #
    # Define a custom HTML element
    #
    class Define < Node
      # Node evaluation method which goes through all the child nodes and
      # evaluates them using their own eval method
      #
      def evaluate(context, blocks = {})
        yields = @yields.clone

        @children.map do |child|
          evaluated_child = child.evaluate context

          # Check to see if the child element being mapped is one of the yield
          # node parent pointers
          if yields.include? child
            yields.delete child

            # We need to replace the yield nodes with the matching named block
            # in order to map the yield node correctly
            evaluated_child.children.map! do |subchild|
              if subchild.is_a?(Yield) && blocks[subchild.name]
                blocks[subchild.name]
              else
                subchild
              end
            end
            evaluated_child.children.compact!
            evaluated_child.children.flatten!
          end

          evaluated_child
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
opulent-1.5.5 .libold/opulent/nodes/define.rb
opulent-1.5.4 .libold/opulent/nodes/define.rb
opulent-1.5.3 .libold/opulent/nodes/define.rb
opulent-1.5.2 .libold/opulent/nodes/define.rb
opulent-1.5.1 .libold/opulent/nodes/define.rb
opulent-1.5.0 .libold/opulent/nodes/define.rb
opulent-1.4.8 .libold/opulent/nodes/define.rb
opulent-1.4.7 .libold/opulent/nodes/define.rb
opulent-1.4.6 .libold/opulent/nodes/define.rb
opulent-1.4.5 .libold/opulent/nodes/define.rb
opulent-1.4.3 .libold/opulent/nodes/define.rb
opulent-1.4.2 .libold/opulent/nodes/define.rb
opulent-1.4.1 .libold/opulent/nodes/define.rb
opulent-1.4.0 .libold/opulent/nodes/define.rb
opulent-1.3.3 .libold/opulent/nodes/define.rb
opulent-1.3.2 .libold/opulent/nodes/define.rb
opulent-1.3.1 .libold/opulent/nodes/define.rb
opulent-1.3.0 .libold/opulent/nodes/define.rb
opulent-1.2.1 .libold/opulent/nodes/define.rb
opulent-1.2.0 .libold/opulent/nodes/define.rb