Class: Merb::Generators::Generator
- Inherits:
-
Templater::Generator
- Object
- Templater::Generator
- Merb::Generators::Generator
- Defined in:
- lib/merb-gen/generator.rb
Direct Known Subclasses
FreezerGenerator, MerbGenerator, MigrationGenerator, NamedGenerator, ResourceGenerator, SessionMigrationGenerator
Class Method Summary collapse
Instance Method Summary collapse
-
#go_up(num) ⇒ String
Returns a string of num times ‘..’, useful for example in tests for namespaced generators to find the spec_helper higher up in the directory structure.
-
#initialize(*args) ⇒ Generator
constructor
A new instance of Generator.
-
#with_modules(modules, options = {}, &block) ⇒ Object
Inside a template, wraps a block of code properly in modules, keeping the indentation correct.
Constructor Details
Class Method Details
.source_root ⇒ Object
46 47 48 |
# File 'lib/merb-gen/generator.rb', line 46 def self.source_root File.join(File.dirname(__FILE__), '..', 'generators', 'templates') end |
Instance Method Details
#go_up(num) ⇒ String
Returns a string of num times ‘..’, useful for example in tests for namespaced generators to find the spec_helper higher up in the directory structure.
42 43 44 |
# File 'lib/merb-gen/generator.rb', line 42 def go_up(num) (["'..'"] * num).join(', ') end |
#with_modules(modules, options = {}, &block) ⇒ Object
Inside a template, wraps a block of code properly in modules, keeping the indentation correct
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/merb-gen/generator.rb', line 24 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 = 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 |