Module: Dindi::FileHelper
- Defined in:
- lib/dindi/file_helper.rb
Class Method Summary collapse
- .copy_file_templates(options) ⇒ Object
- .create_default_directories(options) ⇒ Object
- .template_file_copy_location(filename, options) ⇒ Object
Class Method Details
.copy_file_templates(options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dindi/file_helper.rb', line 15 def self.copy_file_templates() project_absolute_dir = .project_absolute_dir ruby_version = .ruby_version # version specific file templates and shared template together [ruby_version, "shared"].each do |dir_name| Dir.glob(File.join(File.dirname(__FILE__), 'file_templates', dir_name, '*')).each do |file| filename = File.basename(file, ".*") # read file as ERB templates content = File.open(file, "r").read template = ERB.new content # file copy location file_location = template_file_copy_location(filename, ) # write the contents of each file to the project directory File.open(file_location, "w") do |file| # write file after running the templates file.puts template.result(binding) end end end end |
.create_default_directories(options) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/dindi/file_helper.rb', line 8 def self.create_default_directories() project_absolute_dir = .project_absolute_dir %w(tmp log public push configs views routes extlibs models helpers tests scripts).each do |dir| FileUtils.mkdir_p(File.join(project_absolute_dir, dir)) end end |
.template_file_copy_location(filename, options) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/dindi/file_helper.rb', line 44 def self.template_file_copy_location(filename, ) project_absolute_dir = .project_absolute_dir # copy location for not common template files special_location_hash = {"debug_on.rb" => File.join(project_absolute_dir, 'helpers', 'debug_on.rb'), "deploy_setting.rb" => File.join(project_absolute_dir, 'configs', 'deploy_setting.rb'), "database.yml" => File.join(project_absolute_dir, 'configs', 'database.yml'), "active_record_setting.rb" => File.join(project_absolute_dir, 'configs', 'active_record_setting.rb'), "initializer.rb" => File.join(project_absolute_dir, 'configs', 'initializer.rb'), "docs.haml" => File.join(project_absolute_dir, 'views', 'docs.haml'), "docs_controller.rb" => File.join(project_absolute_dir, 'routes', 'docs_controller.rb'), "main_controller.rb" => File.join(project_absolute_dir, 'routes', 'main_controller.rb') } if special_location_hash[filename] return special_location_hash[filename] else return File.join(project_absolute_dir, filename) end end |