Class: CappRuby::AppGenerator
- Inherits:
-
Object
- Object
- CappRuby::AppGenerator
- Defined in:
- lib/cappruby/app_generator.rb
Instance Method Summary collapse
-
#gen! ⇒ Object
do generate.
-
#gen_capp_frameworks ⇒ Object
capp frameworks.
-
#initialize(args) ⇒ AppGenerator
constructor
A new instance of AppGenerator.
-
#source_files ⇒ Object
all source files.
Constructor Details
#initialize(args) ⇒ AppGenerator
Returns a new instance of AppGenerator.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cappruby/app_generator.rb', line 31 def initialize(args) @app_name = args[0] @app_title = (@app_name.split('_').collect { |p| p.capitalize }).join ' ' @app_root = File.join(Dir.getwd, @app_name) if File.exists? @app_root puts "#{@app_name} already exists. Choose a different path" exit end end |
Instance Method Details
#gen! ⇒ Object
do generate
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cappruby/app_generator.rb', line 48 def gen! puts "Generating project: '#{@app_title}' in '#{@app_name}'" FileUtils.mkdir_p @app_root Dir.glob(File.join(source_files, '**', '*')) do |f| relative = f[source_files.length..-1] if File.directory? f FileUtils.mkdir_p File.join(@app_root, relative) else File.open(File.join(@app_root, relative), 'w') do |o| t = File.read f t.gsub!(/__APPLICATION_NAME__/, @app_name) t.gsub!(/__APPLICATION_TITLE__/, @app_title) o.write t end end end puts "Generating capp frameworks (might take a few secs)" gen_capp_frameworks end |
#gen_capp_frameworks ⇒ Object
capp frameworks
71 72 73 74 75 76 77 |
# File 'lib/cappruby/app_generator.rb', line 71 def gen_capp_frameworks if %x{which capp} == "" puts "Capp is not installed. Required for frameworks. Generating anyway." else %x{capp gen #{@app_name} -f} end end |