Class: Bowline::Generators::Generator

Inherits:
Templater::Generator
  • Object
show all
Defined in:
lib/bowline/generators.rb

Direct Known Subclasses

MigrationGenerator, NamedGenerator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



25
26
27
# File 'lib/bowline/generators.rb', line 25

def self.source_root
  File.join(File.dirname(__FILE__), *%w[.. .. templates])
end

Instance Method Details

#with_modules(modules, options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bowline/generators.rb', line 12

def with_modules(modules, options={}, &block)
  indent = options[:indent] || 0
  text = capture(&block)
  modules.each_with_index do |mod, i|
    concat(("  " * (indent + i)) + "module #{mod}\n", block.binding)
  end
  text = text.to_a.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