Sha256: 5d59af74167fc93dbad32dd4431e7554f9d69061944920f618d61bcf6fd0df1c
Contents?: true
Size: 1.75 KB
Versions: 5
Compression:
Stored size: 1.75 KB
Contents
module Napa module Generators class Scaffold def initialize(app_name, app_path = nil) @app_name = app_name @app_path = app_path.nil? ? app_name : app_path @template_path = File.expand_path(File.join(File.dirname(__FILE__), 'templates/scaffold')) @files = file_list create_files! STDOUT.write "Generator Finished!\n" end def file_list [ 'app/apis/hello_api.rb', 'app/models/.keep', 'config/database.yml', 'config/initializers/active_record.rb', 'config/middleware/honeybadger.rb', 'db/migrate/.keep', 'lib/tasks/.keep', 'log/.keep', 'public/.keep', 'spec/spec_helper.rb', 'spec/apis/hello_api_spec.rb', 'tmp/.keep', '.env', '.env.test', '.rubocop.yml', '.gitignore.tpl', 'app.rb', 'config.ru', 'console', 'Gemfile', 'Rakefile', 'README.md' ] end def create_files! @files.each do |file| create_file_with_template(file) end end def create_file_with_template(file) template_file = [@template_path, file].join('/') new_file = [@app_name, file.gsub(/.tpl$/, '')].join('/') FileUtils.mkdir_p(File.dirname(new_file)) if File.exists?(template_file) file_content = File.read(template_file) # replace template variables file_content.gsub!(/{{app_name}}/, @app_name) File.open(new_file, 'w') { |f| f.write(file_content) } else FileUtils.touch(new_file) end STDOUT.write "Creating File: #{new_file}\n" end end end end
Version data entries
5 entries across 5 versions & 1 rubygems