Class: Perennial::Generator
Defined Under Namespace
Classes: CommandEnv
Instance Attribute Summary collapse
-
#destination_path ⇒ Object
Returns the value of attribute destination_path.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
Instance Method Summary collapse
- #download(from, to) ⇒ Object
- #file(name, contents) ⇒ Object
- #folders(*args) ⇒ Object
-
#initialize(destination, opts = {}) ⇒ Generator
constructor
A new instance of Generator.
- #template(source, destination, environment = {}) ⇒ Object
Constructor Details
#initialize(destination, opts = {}) ⇒ Generator
Returns a new instance of Generator.
32 33 34 35 36 |
# File 'lib/perennial/generator.rb', line 32 def initialize(destination, opts = {}) @destination_path = destination @template_path = opts[:template_path] || File.join(Settings.library_root, "templates") puts "Starting generator for #{destination}" end |
Instance Attribute Details
#destination_path ⇒ Object
Returns the value of attribute destination_path.
30 31 32 |
# File 'lib/perennial/generator.rb', line 30 def destination_path @destination_path end |
#template_path ⇒ Object
Returns the value of attribute template_path.
30 31 32 |
# File 'lib/perennial/generator.rb', line 30 def template_path @template_path end |
Instance Method Details
#download(from, to) ⇒ Object
38 39 40 41 |
# File 'lib/perennial/generator.rb', line 38 def download(from, to) describe "Downloading #{from}" file to, open(from).read end |
#file(name, contents) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/perennial/generator.rb', line 50 def file(name, contents) dest_folder = File.dirname(name) folders(dest_folder) unless File.directory?((dest_folder)) describe "Creating file #{name}" File.open((name), "w+") do |f| f.write(contents) end end |
#folders(*args) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/perennial/generator.rb', line 43 def folders(*args) args.each do |f| describe "Creating folder #{f}" FileUtils.mkdir_p((f)) end end |
#template(source, destination, environment = {}) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/perennial/generator.rb', line 59 def template(source, destination, environment = {}) describe "Processing template #{source}" raw_template = File.read((source)) processed_template = ERB.new(raw_template).result(binding_for(environment)) file destination, processed_template end |