Module: Angus::FileHandler
- Included in:
- Thor::Actions::NewProject, Thor::Actions::Resource
- Defined in:
- lib/angus/generator/thor/file_handler.rb
Instance Method Summary collapse
- #copy_erb_file(file, name, base_path = nil) ⇒ Object
- #filename_resolver(file, app_name) ⇒ Object
- #is_erb?(file) ⇒ Boolean
-
#mapping ⇒ Object
Override if you want a custom file mapping.
Instance Method Details
#copy_erb_file(file, name, base_path = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/angus/generator/thor/file_handler.rb', line 13 def copy_erb_file(file, name, base_path = nil) base_path = name if base_path.nil? tmp_file = Tempfile.new(File.basename(file)) source = File.(base.find_in_source_paths(file.to_s)) content = ERB.new(File.binread(source), nil, '%<>-').result(binding) File.open(tmp_file.path, 'w') { |f| f << content } tmp_file.close base.copy_file(tmp_file.path, File.join(base_path, filename_resolver(file, name))) end |
#filename_resolver(file, app_name) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/angus/generator/thor/file_handler.rb', line 27 def filename_resolver(file, app_name) if mapping[file].nil? file.gsub('.erb', '') else mapping[file].call(self, app_name) end end |
#is_erb?(file) ⇒ Boolean
9 10 11 |
# File 'lib/angus/generator/thor/file_handler.rb', line 9 def is_erb?(file) file.end_with?('.erb') end |
#mapping ⇒ Object
Override if you want a custom file mapping.
5 6 7 |
# File 'lib/angus/generator/thor/file_handler.rb', line 5 def mapping {} end |