Sha256: 0f84be83b5743b6d9cd0e19b4abf403f5ca282d7c4277c03e6ee19cf1fde74fb

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

#!/usr/bin/ruby

require 'optparse'
require 'pathname'
require 'erb'
require 'ostruct'
require 'fileutils'
include FileUtils

# get templates directory
@templates = Pathname.new(File.dirname(__FILE__)).realpath + '../templates'

o = OpenStruct.new
OptionParser.new do |opts|
	opts.on('-c', '--convert [FILE]') {|v|
		o.convert = true
		(o.convert_files ||= []) << v if v
	}
	opts.parse!(ARGV)
end
appname = ARGV.shift

def convert(header)
	_, class_name, super_class = */@interface ([^\s]+) : ([^\s]+)/.match(header)

	outlets = header.scan(/IBOutlet id (.*?);/)
	actions = header.scan(/^- \(IBAction\)(.*?):\(id\)sender;/)

	result =  ERB.new((@templates + 'class.erb').read, $SAFE, '-').result(binding)
end


if o.convert
	if o.convert_files
		# convert specific *.h
		o.convert_files.each do |f|
			f = Pathname.new f
			target = Pathname.new "#{f.basename(".h")}.rb"
			puts "Converting #{f} to #{target}..."

			result = convert(f.read)
			target.open("w") do |f|
				f.puts result
			end
		end
	else
		# convert all *.h
		Pathname.glob('*.h') do |f|
			target = Pathname.new "#{f.basename(".h")}.rb"
			if target.exist?
				"#{target} is already exists. skip.."
				next
			end

			puts "Converting #{f} to #{target}..."

			result = convert(f.read)
			target.open("w") do |f|
				f.puts result
			end
		end
	end
end

if appname
	puts "Creating #{appname} directory..."
	mkdir appname
	puts "Entering #{appname}"
	cd appname do
		appname = appname.capitalize

		%w(Rakefile README).each do |file|
			puts "Creating #{file} from templates."
			File.open(file, 'w') do |f|
				f.write ERB.new((@templates + 'Rakefile').read).result(binding)
			end
		end
		puts "Copying other templates"
		cp_r %w(Info.plist.erb main.rb main.m English.lproj).map{|f| @templates + f}, '.'

		mkdir 'html'
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newcocoa-0.0.1 bin/newcocoa