newcocoa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README for newcocoa
2
+ ===================
3
+
data/Rakefile ADDED
@@ -0,0 +1,86 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ include FileUtils
11
+
12
+ AUTHOR = "cho45"
13
+ EMAIL = "cho45@lowreal.net"
14
+ DESCRIPTION = "Generate new Ruby/Cocoa Application skelton."
15
+ RUBYFORGE_PROJECT = "newcocoa"
16
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
17
+ BIN_FILES = %w( newcocoa )
18
+ #REV = `svn info`[/Revision: (\d+)/, 1]
19
+ #VERS = '0.0.1' + (REV ? ".#{REV}" : '')
20
+ VERS = '0.0.1'
21
+
22
+
23
+
24
+ NAME = "newcocoa"
25
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
26
+ RDOC_OPTS = ['--quiet', '--title', "newcocoa documentation",
27
+ "--opname", "index.html",
28
+ "--line-numbers",
29
+ "--main", "README",
30
+ "--inline-source"]
31
+
32
+ desc "Packages up newcocoa gem."
33
+ task :default => [:test]
34
+ task :package => [:clean]
35
+
36
+ Rake::TestTask.new("test") { |t|
37
+ t.libs << "test"
38
+ t.pattern = "test/**/*_test.rb"
39
+ t.verbose = true
40
+ }
41
+
42
+ spec =
43
+ Gem::Specification.new do |s|
44
+ s.name = NAME
45
+ s.version = VERS
46
+ s.platform = Gem::Platform::RUBY
47
+ s.has_rdoc = true
48
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
49
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
50
+ s.summary = DESCRIPTION
51
+ s.description = DESCRIPTION
52
+ s.author = AUTHOR
53
+ s.email = EMAIL
54
+ s.homepage = HOMEPATH
55
+ s.executables = BIN_FILES
56
+ s.rubyforge_project = RUBYFORGE_PROJECT
57
+ s.bindir = "bin"
58
+ s.require_path = "lib"
59
+ s.autorequire = "newcocoa"
60
+
61
+ #s.add_dependency('activesupport', '>=1.3.1')
62
+ #s.required_ruby_version = '>= 1.8.2'
63
+
64
+ s.files = %w(README CHANGELOG Rakefile) +
65
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
66
+ Dir.glob("ext/**/*.{h,c,rb}") +
67
+ Dir.glob("examples/**/*.rb") +
68
+ Dir.glob("tools/*.rb")
69
+
70
+ # s.extensions = FileList["ext/**/extconf.rb"].to_a
71
+ end
72
+
73
+ Rake::GemPackageTask.new(spec) do |p|
74
+ p.need_tar = true
75
+ p.gem_spec = spec
76
+ end
77
+
78
+ task :install do
79
+ name = "#{NAME}-#{VERS}.gem"
80
+ sh %{rake package}
81
+ sh %{sudo gem install pkg/#{name}}
82
+ end
83
+
84
+ task :uninstall => [:clean] do
85
+ sh %{sudo gem uninstall #{NAME}}
86
+ end
data/bin/newcocoa ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'pathname'
5
+ require 'erb'
6
+ require 'ostruct'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ # get templates directory
11
+ @templates = Pathname.new(File.dirname(__FILE__)).realpath + '../templates'
12
+
13
+ o = OpenStruct.new
14
+ OptionParser.new do |opts|
15
+ opts.on('-c', '--convert [FILE]') {|v|
16
+ o.convert = true
17
+ (o.convert_files ||= []) << v if v
18
+ }
19
+ opts.parse!(ARGV)
20
+ end
21
+ appname = ARGV.shift
22
+
23
+ def convert(header)
24
+ _, class_name, super_class = */@interface ([^\s]+) : ([^\s]+)/.match(header)
25
+
26
+ outlets = header.scan(/IBOutlet id (.*?);/)
27
+ actions = header.scan(/^- \(IBAction\)(.*?):\(id\)sender;/)
28
+
29
+ result = ERB.new((@templates + 'class.erb').read, $SAFE, '-').result(binding)
30
+ end
31
+
32
+
33
+ if o.convert
34
+ if o.convert_files
35
+ # convert specific *.h
36
+ o.convert_files.each do |f|
37
+ f = Pathname.new f
38
+ target = Pathname.new "#{f.basename(".h")}.rb"
39
+ puts "Converting #{f} to #{target}..."
40
+
41
+ result = convert(f.read)
42
+ target.open("w") do |f|
43
+ f.puts result
44
+ end
45
+ end
46
+ else
47
+ # convert all *.h
48
+ Pathname.glob('*.h') do |f|
49
+ target = Pathname.new "#{f.basename(".h")}.rb"
50
+ if target.exist?
51
+ "#{target} is already exists. skip.."
52
+ next
53
+ end
54
+
55
+ puts "Converting #{f} to #{target}..."
56
+
57
+ result = convert(f.read)
58
+ target.open("w") do |f|
59
+ f.puts result
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ if appname
66
+ puts "Creating #{appname} directory..."
67
+ mkdir appname
68
+ puts "Entering #{appname}"
69
+ cd appname do
70
+ appname = appname.capitalize
71
+
72
+ %w(Rakefile README).each do |file|
73
+ puts "Creating #{file} from templates."
74
+ File.open(file, 'w') do |f|
75
+ f.write ERB.new((@templates + 'Rakefile').read).result(binding)
76
+ end
77
+ end
78
+ puts "Copying other templates"
79
+ cp_r %w(Info.plist.erb main.rb main.m English.lproj).map{|f| @templates + f}, '.'
80
+
81
+ mkdir 'html'
82
+ end
83
+ end
data/lib/newcocoa.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ # nothing to do
3
+ #
@@ -0,0 +1,4 @@
1
+ {
2
+ IBClasses = ({CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; });
3
+ IBVersion = 1;
4
+ }
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IBDocumentLocation</key>
6
+ <string>69 10 356 240 0 0 1280 778 </string>
7
+ <key>IBFramework Version</key>
8
+ <string>443.0</string>
9
+ <key>IBSystem Version</key>
10
+ <string>8L2127</string>
11
+ </dict>
12
+ </plist>
@@ -0,0 +1,27 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
3
+ <plist version="0.9">
4
+ <dict>
5
+ <key>CFBundleExecutable</key>
6
+ <string><%=APPNAME%></string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string><%=BUNDLEID%></string>
9
+ <key>CFBundlePackageType</key>
10
+ <string>APPL</string>
11
+ <key>CFBundleSignature</key>
12
+ <string>????</string>
13
+
14
+ <key>CFBundleIconFile</key>
15
+ <string>icon</string>
16
+
17
+ <key>NSMainNibFile</key>
18
+ <string>Main</string>
19
+ <key>NSPrincipalClass</key>
20
+ <string>NSApplication</string>
21
+
22
+ <!-- Not Show in Dock
23
+ <key>LSUIElement</key>
24
+ <string>1</string>
25
+ -->
26
+ </dict>
27
+ </plist>
data/templates/README ADDED
@@ -0,0 +1,9 @@
1
+ =begin rd
2
+
3
+ = <%=appname%>
4
+
5
+
6
+
7
+
8
+ =end
9
+
@@ -0,0 +1,81 @@
1
+ require 'osx/cocoa' # dummy
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/clean'
5
+ require 'rake/testtask'
6
+ require 'erb'
7
+ require 'pathname'
8
+
9
+ # Application own Settings
10
+ APPNAME = "<%=appname%>"
11
+ TARGET = "#{APPNAME}.app"
12
+ VERSION = "rev#{`svn info`[/Revision: (\d+)/, 1]}"
13
+ RESOURCES = ['*.rb', '*.lproj', 'Credits.*', '*.icns']
14
+ PKGINC = [TARGET, 'README', 'html', 'client']
15
+ PUBLISH = 'yourname@yourhost:path'
16
+
17
+ BUNDLEID = "rubyapp.#{APPNAME}"
18
+
19
+ CLEAN.include ['**/.*.sw?', '*.dmg', TARGET, 'image', 'a.out']
20
+
21
+ # Tasks
22
+ task :default => [:test]
23
+
24
+ desc 'Create Application Budle and Run it.'
25
+ task :test => [TARGET] do
26
+ sh %{open #{TARGET}}
27
+ end
28
+
29
+ desc 'Create .dmg file for Publish'
30
+ task :package => [:clean, 'pkg', TARGET] do
31
+ name = "#{APPNAME}.#{VERSION}"
32
+ sh %{
33
+ mkdir image
34
+ cp -r #{PKGINC.join(' ')} image
35
+ ln -s html/index.html image/index.html
36
+ }
37
+ puts 'Creating Image...'
38
+ sh %{
39
+ hdiutil create -volname #{name} -srcfolder image #{name}.dmg
40
+ rm -rf image
41
+ mv #{name}.dmg pkg
42
+ }
43
+ end
44
+
45
+ desc 'Publish .dmg file to specific server.'
46
+ task :publish => [:package] do
47
+ sh %{
48
+ svn log > CHANGES
49
+ }
50
+ _, host, path = */^([^\s]+):(.+)$/.match(PUBLISH)
51
+ path = Pathname.new path
52
+ puts "Publish: Host: %s, Path: %s" % [host, path]
53
+ sh %{
54
+ scp pkg/IIrcv.#{VERSION}.dmg #{PUBLISH}/pkg
55
+ scp CHANGES #{PUBLISH}/pkg
56
+ scp -r html/* #{PUBLISH}
57
+ }
58
+ end
59
+
60
+ # File tasks
61
+ file TARGET => [:clean, APPNAME] do
62
+ sh %{
63
+ mkdir -p "#{APPNAME}.app/Contents/MacOS"
64
+ mkdir "#{APPNAME}.app/Contents/Resources"
65
+ cp -rp #{RESOURCES.join(' ')} "#{APPNAME}.app/Contents/Resources"
66
+ cp #{APPNAME} "#{APPNAME}.app/Contents/MacOS"
67
+ echo -n "APPL????" > "#{APPNAME}.app/Contents/PkgInfo"
68
+ echo -n #{VERSION} > "#{APPNAME}.app/Contents/Resources/VERSION"
69
+ }
70
+ File.open("#{APPNAME}.app/Contents/Info.plist", "w") do |f|
71
+ f.puts ERB.new(File.read("Info.plist.erb")).result
72
+ end
73
+ end
74
+
75
+ file APPNAME => ['main.m'] do
76
+ # Universal Binary
77
+ sh %{gcc -arch ppc -arch i386 -Wall -lobjc -framework RubyCocoa main.m -o #{APPNAME}}
78
+ end
79
+
80
+ directory 'pkg'
81
+
@@ -0,0 +1,18 @@
1
+ require 'osx/cocoa'
2
+ include OSX
3
+
4
+ class <%=class_name%> < <%=super_class%>
5
+ <%- outlets.each do |outlet| -%>
6
+ ib_outlets :<%=outlet%>
7
+ <%- end %>
8
+ <%- actions.each do |action| -%>
9
+
10
+ def <%=action%>(sender)
11
+ end
12
+ <%- end %>
13
+
14
+ def awakeFromNib
15
+ end
16
+ end
17
+
18
+
data/templates/main.m ADDED
@@ -0,0 +1,7 @@
1
+ #import <RubyCocoa/RBRuntime.h>
2
+
3
+ int main(int argc, const char* argv[])
4
+ {
5
+ return RBApplicationMain("main.rb", argc, argv);
6
+ }
7
+
data/templates/main.rb ADDED
@@ -0,0 +1,28 @@
1
+
2
+ begin
3
+ require 'rubygems'
4
+ rescue LoadError
5
+ end
6
+ require 'osx/cocoa'
7
+ require 'osx/hotkey'
8
+ require 'pathname'
9
+
10
+ def log(*args)
11
+ args.each do |m|
12
+ OSX.NSLog m.inspect
13
+ end
14
+ end
15
+
16
+ def _(key)
17
+ NSLocalizedString(key, '').to_s
18
+ end
19
+
20
+ path = Pathname.new OSX::NSBundle.mainBundle.resourcePath.fileSystemRepresentation
21
+ Pathname.glob(path + '*.rb') do |file|
22
+ next if file.to_s == __FILE__
23
+ require(file)
24
+ end
25
+ OSX::NSApplicationWithHotKey.sharedApplication
26
+ OSX.NSApplicationMain(0, nil)
27
+
28
+
data/test/TestHeader.h ADDED
@@ -0,0 +1,19 @@
1
+ /* AppController */
2
+
3
+ #import <Cocoa/Cocoa.h>
4
+
5
+ @interface TestHeader : NSObject
6
+ {
7
+ IBOutlet id configController;
8
+ IBOutlet id menu;
9
+ IBOutlet id menuToggleHide;
10
+ IBOutlet id menuToggleIgnoreMouseEvent;
11
+ IBOutlet id menuToggleTimeout;
12
+ IBOutlet id winConfig;
13
+ }
14
+ - (IBAction)about:(id)sender;
15
+ - (IBAction)quit:(id)sender;
16
+ - (IBAction)toggleHide:(id)sender;
17
+ - (IBAction)toggleIgnoreMouseEvent:(id)sender;
18
+ - (IBAction)toggleTimeout:(id)sender;
19
+ @end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ require 'fileutils'
3
+ require 'pp'
4
+ require 'pathname'
5
+ include FileUtils
6
+
7
+ class NewCocoaTest < Test::Unit::TestCase
8
+ def setup
9
+ @testdir = Pathname.new(File.dirname(__FILE__)).realpath
10
+ @newgem = @testdir + '../bin/newcocoa'
11
+ system(@newgem, 'testcocoa')
12
+ end
13
+
14
+ def teardown
15
+ rm_rf 'testcocoa'
16
+ end
17
+
18
+ def test_load
19
+ assert true
20
+ end
21
+
22
+ def test_create
23
+ cd 'testcocoa' do
24
+ assert_equal(Dir['**/*'], [
25
+ "English.lproj",
26
+ "html",
27
+ "Info.plist.erb",
28
+ "main.m",
29
+ "main.rb",
30
+ "Rakefile",
31
+ "README",
32
+ "English.lproj/Main.nib",
33
+ "English.lproj/Main.nib/classes.nib",
34
+ "English.lproj/Main.nib/info.nib",
35
+ "English.lproj/Main.nib/keyedobjects.nib"
36
+ ])
37
+ end
38
+ end
39
+
40
+ def test_convert
41
+ cd 'testcocoa' do
42
+ cp @testdir + 'TestHeader.h', '.'
43
+ system(@newgem, '-c')
44
+ res = Pathname.new 'TestHeader.rb'
45
+ assert res.exist?, 'Create Converted .rb'
46
+
47
+ time = res.mtime
48
+ system(@newgem, '-c')
49
+ assert_equal time, res.mtime, 'No overwrite existed .rb'
50
+
51
+ res.unlink
52
+
53
+ system(@newgem, '-c', 'TestHeader.h')
54
+ assert res.exist?, 'Create Converted .rb, -c'
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ require 'test/unit'
2
+ #require File.dirname(__FILE__) + '/../lib/osx/hotkey'
3
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: newcocoa
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2006-11-19 00:00:00 +09:00
8
+ summary: Generate new Ruby/Cocoa Application skelton.
9
+ require_paths:
10
+ - lib
11
+ email: cho45@lowreal.net
12
+ homepage: http://newcocoa.rubyforge.org
13
+ rubyforge_project: newcocoa
14
+ description: Generate new Ruby/Cocoa Application skelton.
15
+ autorequire: newcocoa
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - cho45
32
+ files:
33
+ - README
34
+ - CHANGELOG
35
+ - Rakefile
36
+ - bin/newcocoa
37
+ - test/newcocoa_test.rb
38
+ - test/test_helper.rb
39
+ - test/TestHeader.h
40
+ - lib/newcocoa.rb
41
+ - templates/class.erb
42
+ - templates/English.lproj
43
+ - templates/Info.plist.erb
44
+ - templates/main.m
45
+ - templates/main.rb
46
+ - templates/Rakefile
47
+ - templates/README
48
+ - templates/English.lproj/Main.nib
49
+ - templates/English.lproj/Main.nib/classes.nib
50
+ - templates/English.lproj/Main.nib/info.nib
51
+ - templates/English.lproj/Main.nib/keyedobjects.nib
52
+ test_files: []
53
+ rdoc_options:
54
+ - "--quiet"
55
+ - "--title"
56
+ - newcocoa documentation
57
+ - "--opname"
58
+ - index.html
59
+ - "--line-numbers"
60
+ - "--main"
61
+ - README
62
+ - "--inline-source"
63
+ - "--exclude"
64
+ - "^(examples|extras)/"
65
+ extra_rdoc_files:
66
+ - README
67
+ - CHANGELOG
68
+ executables:
69
+ - newcocoa
70
+ extensions: []
71
+ requirements: []
72
+ dependencies: []