Permalink
Browse files

First stab at command line interface for creating new projects.

  • Loading branch information...
1 parent 4350390 commit ae73258b0d161742e5425487abd708dbbea63a8b JD Huntington committed Jan 26, 2011
Showing with 92 additions and 1 deletion.
  1. +4 −0 Manifest.txt
  2. +6 −0 Rakefile
  3. +3 −1 bin/pindah
  4. +25 −0 lib/pindah_cli.rb
  5. +8 −0 templates/initial_activity.mirah
  6. +8 −0 test/fixtures/HelloWorld.mirah
  7. +38 −0 test/pindah_cli_test.rb
View
@@ -5,3 +5,7 @@ README.txt
Rakefile
bin/pindah
lib/pindah.rb
+lib/pindah_cli.rb
+templates/initial_activity.mirah
+test/fixtures/HelloWorld.mirah
+test/pindah_cli_test.rb
View
@@ -9,3 +9,9 @@ Hoe.spec 'pindah' do
end
# vim: syntax=ruby
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/**/*.rb']
+ t.verbose = true
+end
View
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby
-abort "TODO: create project skeleton: rakefile, manifest, resources, activity"
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'pindah_cli'))
+PindahCLI.create *ARGV
+abort "TODO: create project skeleton: rakefile, manifest, resources"
View
@@ -0,0 +1,25 @@
+require 'fileutils'
+
+module PindahCLI
+ def self.log(msg)
+ STDERR.puts msg
+ end
+
+ def self.create(namespace, location, activity_name=nil)
+ segments = namespace.split('.')
+ src_dir = File.join(location, 'src', *segments)
+ FileUtils.mkdir_p src_dir
+ log "Created '#{src_dir}'."
+ if activity_name
+ activity_location = File.join(src_dir, "#{activity_name}.mirah")
+ template = File.read(File.join(File.dirname(__FILE__),
+ '..', 'templates',
+ 'initial_activity.mirah'))
+
+ File.open(activity_location, 'w') do |f|
+ f.puts template.gsub(/INITIAL_ACTIVITY/, activity_name)
+ end
+ log "Created Activity '#{activity_name}' in '#{activity_location}'."
+ end
+ end
+end
@@ -0,0 +1,8 @@
+import android.app.Activity
+import android.os.Bundle
+
+class INITIAL_ACTIVITY < Activity
+ def onCreate(savedInstanceState:Bundle)
+ super savedInstanceState
+ end
+end
@@ -0,0 +1,8 @@
+import android.app.Activity
+import android.os.Bundle
+
+class HelloWorld < Activity
+ def onCreate(savedInstanceState:Bundle)
+ super savedInstanceState
+ end
+end
View
@@ -0,0 +1,38 @@
+require 'test/unit'
+require 'tempfile'
+require 'fileutils'
+require 'rubygems'
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'pindah_cli'))
+
+class PindahCLITest < Test::Unit::TestCase
+ def setup
+ $local_pwd ||= File.expand_path(File.dirname(__FILE__))
+ @project_path = File.expand_path(Tempfile.new('pindah').path + ".d")
+ FileUtils.mkdir_p @project_path
+ Dir.chdir @project_path
+ end
+
+ def teardown
+ FileUtils.rm_rf @project_path
+ end
+
+ def test_create_should_create_basic_project_structure
+ PindahCLI.create('tld.pindah.testapp', '.')
+ assert File.directory?(File.join(@project_path, 'src', 'tld', 'pindah', 'testapp'))
+ end
+
+ def test_create_should_create_an_activity_if_desired
+ PindahCLI.create('tld.pindah.testapp', '.', 'HelloWorld')
+
+ expected = File.read(File.join($local_pwd,
+ 'fixtures',
+ 'HelloWorld.mirah'))
+ actual = File.read(File.join(@project_path,
+ 'src',
+ 'tld',
+ 'pindah',
+ 'testapp',
+ 'HelloWorld.mirah'))
+ assert_equal expected, actual
+ end
+end

0 comments on commit ae73258

Please sign in to comment.