Class: TouchErb::CLI
- Inherits:
-
Thor
- Object
- Thor
- TouchErb::CLI
- Defined in:
- lib/touch_erb/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #__version ⇒ Object
- #add(source) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #touch(template_name, output_name = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
12 13 14 15 16 17 18 19 20 |
# File 'lib/touch_erb/cli.rb', line 12 def initialize(*args) super @template_dir = TouchErb::TemplateDir.new @local_template_dir = TouchErb::TemplateDir.new( File.join(Dir.pwd, '.touch_erb'), false ) end |
Class Method Details
.exit_on_failure? ⇒ Boolean
63 64 65 |
# File 'lib/touch_erb/cli.rb', line 63 def self.exit_on_failure? true end |
Instance Method Details
#__version ⇒ Object
68 69 70 |
# File 'lib/touch_erb/cli.rb', line 68 def __version puts "0.4.3" end |
#add(source) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/touch_erb/cli.rb', line 25 def add(source) target_dir = @template_dir target_dir = @local_template_dir if [:local] path = target_dir.add(source) system((ENV['EDITOR']).to_s, path) end |
#list ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/touch_erb/cli.rb', line 53 def list if [:local] @local_template_dir.list.each { |name| puts name } else g (@template_dir.list + @local_template_dir.list).each { |name| puts name } end end |
#touch(template_name, output_name = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/touch_erb/cli.rb', line 35 def touch(template_name, output_name = nil) if template_name.start_with?("--") invoke :help return end write_file_name = output_name || template_name file_name = File.basename(write_file_name, '.*') if FileTest.exist?(file_name) FileUtils.touch(file_name) else File.open(write_file_name, 'w') do |f| f.write(ERB.new(@local_template_dir.find(template_name) || @template_dir.find(template_name) || '', trim_mode: '%<>').result(binding)) end end end |
#version ⇒ Object
73 74 75 |
# File 'lib/touch_erb/cli.rb', line 73 def version __version end |