Method: Merb::Generators::Generator#with_modules
- Defined in:
- lib/merb-gen/generator.rb
#with_modules(modules, options = {}, &block) ⇒ Object
Inside a template, wraps a block of code properly in modules, keeping the indentation correct
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/merb-gen/generator.rb', line 55 def with_modules(modules, ={}, &block) indent = [:indent] || 0 text = capture(&block) modules.each_with_index do |mod, i| concat((" " * (indent + i)) + "module #{mod}\n", block.binding) end text = Array(text).map{ |line| (" " * modules.size) + line }.join concat(text, block.binding) modules.reverse.each_with_index do |mod, i| concat((" " * (indent + modules.size - i - 1)) + "end # #{mod}\n", block.binding) end end |