Module: Ritsu::TemplatePolicies::FlexibleBlockMatching

Instance Method Summary collapse

Instance Method Details

#match_child_blocks(block) ⇒ Hash

Returns a hash mapping each child template to a child block with the same id. If there is no such child block, the child template is mapped to nil.

Parameters:

Returns:

  • (Hash)

    a hash mapping each child template to a child block with the same id. If there is no such child block, the child template is mapped to nil.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ritsu/template_policies.rb', line 58

def match_child_blocks(block)
  child_blocks = block.child_blocks
  matching_child_blocks = {}
  child_templates.each do |child_template|
    matching = nil
    child_blocks.each do |child_block|
      if child_template.id == child_block.id
        matching = child_block
        break
      end
    end
    child_blocks.delete(matching) unless matching.nil?
    matching_child_blocks[child_template] = matching
  end
  matching_child_blocks
end