Module: Ritsu::TemplatePolicies::FlexibleBlockMatchingAndCreateMissingBlockButLeaveUserTextBe
- Includes:
- FlexibleBlockMatching
- Included in:
- SrcFiles::TargetCmakeLists::Template
- Defined in:
- lib/ritsu/template_policies.rb
Instance Method Summary collapse
-
#position_to_insert(block, new_block) ⇒ Integer
The position in block.contents to insert the given new block.
- #update_block(block, options = {}) ⇒ Object
Methods included from FlexibleBlockMatching
Instance Method Details
#position_to_insert(block, new_block) ⇒ Integer
Returns the position in block.contents to insert the given new block.
129 130 131 |
# File 'lib/ritsu/template_policies.rb', line 129 def position_to_insert(block, new_block) raise NotImplementedError end |
#update_block(block, options = {}) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ritsu/template_policies.rb', line 102 def update_block(block, ={}) = {:new_line_after_block => true}.merge() matching_child_blocks = match_child_blocks(block) child_templates.each do |child_template| if matching_child_blocks[child_template].nil? new_block = child_template.create_block() position = position_to_insert(block, new_block) if position block.contents.insert(position, new_block) if [:new_line_after_block] block.contents.insert(position+1, "") end else raise ArgumentError.new("cannot find position to insert '#{new_block.name}'") end else matching = matching_child_blocks[child_template] child_template.update_block(matching) end end end |