Class: Templatron::Generator
- Inherits:
-
Object
- Object
- Templatron::Generator
- Defined in:
- lib/templatron/generator.rb
Overview
Base class used to generates skeleton from template Basically, you just instantiate a Generator and call its #build method
Instance Method Summary collapse
-
#build ⇒ Object
Public: Effectively process a template to generate it.
-
#initialize(template_name, args, output_dir, delete_dir, verbose) ⇒ Generator
constructor
Public: Initialize this Generator.
Constructor Details
#initialize(template_name, args, output_dir, delete_dir, verbose) ⇒ Generator
Public: Initialize this Generator
template_name - Name of the template to generate args - Array of arguments to use output_dir - Where to put the generated stuff delete_dir - Should I clean the output folder? verbose - Should I explain?
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/templatron/generator.rb', line 19 def initialize(template_name, args, output_dir, delete_dir, verbose) @template = template_name @output = File.(output_dir) @verbose = verbose @clear = delete_dir @collector = Collector.new(@template, true, true) process_raw_arguments(args) end |
Instance Method Details
#build ⇒ Object
Public: Effectively process a template to generate it
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/templatron/generator.rb', line 31 def build # Check template existence if !check_template_dir(@collector.full_path) puts "The template #{@template} does not appear to exist in #{@full_template_path}" exit end # If sets, remove the output folder first if @clear puts "Clearing #{@output}" if @verbose begin FileUtils.remove_dir(@output) rescue => ex puts """Could not clear the folder, maybe someone is accessing it? #{ex.} """ exit(1) end end # Print details if verbose is on if @verbose puts "Starting building #{@collector.full_path} to #{@output}" puts "With:" if !@arguments.empty? @arguments.each_with_index do |arg, i| puts "\t{$#{i}} => #{arg}" if !arg.nil? end end # So process them right now process_files(@collector.list) end |