Class: LetterGenerator::Runner

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/letter_generator/runner.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/letter_generator/runner.rb', line 5

def self.exit_on_failure?
  true
end

Instance Method Details

#buildObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/letter_generator/runner.rb', line 21

def build
  enable_debug_mode

  invoke :generate, [], output_file: File.join(options[:build_directory], 'letter-<%= to_s %>.tex')

  Dir.chdir File.expand_path(options[:build_directory]) do
    Rake::FileList.new('*.tex').each do |f|
      run %(pdflatex #{f})
    end
  end
end

#generateObject



13
14
15
16
17
# File 'lib/letter_generator/runner.rb', line 13

def generate
  enable_debug_mode

  invoke 'letter_generator:generators:tex_file_generator', [LetterTemplate.new.file], output_file: options[:output_file]
end

#initObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/letter_generator/runner.rb', line 35

def init
  enable_debug_mode

  source_paths << File.expand_path('../../../templates', __FILE__)
  letter_template = LetterTemplate.new

  template_path = File.expand_path(File.join('templates', File.basename(letter_template.file)))

  case options[:for].to_s.to_sym
  when :user || :u
    copy_file letter_template.file, File.join(File.dirname(LetterGenerator.config.preferred_configuration_file), 'templates', File.basename(letter_template.file))
  when :'working-directory' || :wd

    template 'data', File.expand_path('data.yaml')
    copy_file letter_template.file, template_path
  else
    fail ArgumentError, "#{options[:for]} is not a valid value for \"for\"."
  end
end