hotcocoa 0.5 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,17 +21,12 @@ module HotCocoa
21
21
  @sources = yml["sources"] || []
22
22
  @resources = yml["resources"] || []
23
23
  @overwrite = yml["overwrite"] == true ? true : false
24
- @secure = yml["secure"] == true ? true : false
25
24
  end
26
25
 
27
26
  def overwrite?
28
27
  @overwrite
29
28
  end
30
29
 
31
- def secure?
32
- @secure
33
- end
34
-
35
30
  def icon_exist?
36
31
  @icon ? File.exist?(@icon) : false
37
32
  end
@@ -40,7 +35,7 @@ module HotCocoa
40
35
 
41
36
  ApplicationBundlePackage = "APPL????"
42
37
 
43
- attr_accessor :name, :load_file, :sources, :overwrite, :icon, :version, :info_string, :secure, :resources, :deploy
38
+ attr_accessor :name, :load_file, :sources, :overwrite, :icon, :version, :info_string, :resources, :deploy
44
39
 
45
40
  def self.build(config, options={:deploy => false})
46
41
  if !config.kind_of?(Configuration) || !$LOADED_FEATURES.detect {|f| f.include?("standard_rake_tasks")}
@@ -51,7 +46,6 @@ module HotCocoa
51
46
  end
52
47
  builder = new
53
48
  builder.deploy = options[:deploy] == true ? true : false
54
- builder.secure = config.secure?
55
49
  builder.name = config.name
56
50
  builder.load_file = config.load
57
51
  builder.icon = config.icon if config.icon_exist?
@@ -117,10 +111,6 @@ module HotCocoa
117
111
  end
118
112
  end
119
113
 
120
- def secure?
121
- secure
122
- end
123
-
124
114
  private
125
115
 
126
116
  def check_for_bundle_root
@@ -153,22 +143,11 @@ module HotCocoa
153
143
  end
154
144
 
155
145
  def copy_sources
156
- if secure?
157
- data = {}
158
- data["/"+load_file] = File.open(load_file, "r") {|f| f.read}
159
- sources.each do |source|
160
- data["/"+source] = File.open(source, "r") {|f| f.read}
161
- end
162
- File.open(File.join(resources_root, "vfs.db"), "wb") do |db|
163
- db.write Marshal.dump(data)
164
- end
165
- else
166
- FileUtils.cp_r load_file, resources_root unless sources.include?(load_file)
167
- sources.each do |source|
168
- destination = File.join(resources_root, source)
169
- FileUtils.mkdir_p(File.dirname(destination)) unless File.exist?(File.dirname(destination))
170
- FileUtils.cp_r source, destination
171
- end
146
+ FileUtils.cp_r load_file, resources_root unless sources.include?(load_file)
147
+ sources.each do |source|
148
+ destination = File.join(resources_root, source)
149
+ FileUtils.mkdir_p(File.dirname(destination)) unless File.exist?(File.dirname(destination))
150
+ FileUtils.cp_r source, destination
172
151
  end
173
152
  end
174
153
 
@@ -240,14 +219,9 @@ module HotCocoa
240
219
 
241
220
  def write_ruby_main
242
221
  File.open(main_ruby_source_file, "wb") do |f|
243
- if secure?
244
- require 'hotcocoa/virtual_file_system'
245
- f.puts VirtualFileSystem.code_to_load(load_file)
246
- else
247
- f.puts "$:.map! { |x| x.sub(/^\\/Library\\/Frameworks/, NSBundle.mainBundle.privateFrameworksPath) }" if deploy?
248
- f.puts "$:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation"
249
- f.puts "load '#{load_file}'"
250
- end
222
+ f.puts "$:.map! { |x| x.sub(/^\\/Library\\/Frameworks/, NSBundle.mainBundle.privateFrameworksPath) }" if deploy?
223
+ f.puts "$:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation"
224
+ f.puts "load '#{load_file}'"
251
225
  end
252
226
  end
253
227
 
@@ -196,8 +196,11 @@ module HotCocoa::Graphics
196
196
  ]
197
197
 
198
198
  COLORNAMES.each_key do |name|
199
- (class << self; self; end).define_method(name) do
200
- named(name)
199
+ metaclass = (class << self; self; end)
200
+ metaclass.instance_eval do
201
+ define_method(name) do
202
+ named(name)
203
+ end
201
204
  end
202
205
  end
203
206
 
@@ -57,12 +57,9 @@ module HotCocoa::Graphics
57
57
  # if it's the path to an image file, load as a CGImage
58
58
  @path = img
59
59
  File.exists?(@path) or raise "ERROR: file not found: #{@path}"
60
-
61
- nsimage = NSImage.alloc.initWithContentsOfFile(img)
62
- nsdata = nsimage.TIFFRepresentation
63
- @nsbitmapimage = NSBitmapImageRep.imageRepWithData(nsdata)
64
- # cgimagesource = CGImageSourceCreateWithData(nsdata) # argh, doesn't work
65
- @ciimage = CIImage.alloc.initWithBitmapImageRep(@nsbitmapimage)
60
+ image_source = CGImageSourceCreateWithURL(NSURL.fileURLWithPath(@path), nil)
61
+ @cgimage = CGImageSourceCreateImageAtIndex(image_source, 0, nil)
62
+ @ciimage = CIImage.imageWithCGImage(@cgimage)
66
63
  when Canvas
67
64
  puts "Image.new with canvas" if @verbose
68
65
  @path = 'canvas'
@@ -80,7 +77,7 @@ module HotCocoa::Graphics
80
77
 
81
78
  # reload the bitmap image
82
79
  def reset
83
- @ciimage = CIImage.alloc.initWithBitmapImageRep(@nsbitmapimage)
80
+ @ciimage = CIImage.imageWithCGImage(@cgimage)
84
81
  self
85
82
  end
86
83
 
@@ -51,11 +51,13 @@ HotCocoa::Mappings.map :toolbar => :NSToolbar do
51
51
  def build_custom_items
52
52
  if @allowed && @default
53
53
  ary = @default.select { |x| x.is_a?(NSToolbarItem) }
54
- @default -= ary
54
+
55
+ @default.map! { |x| x.is_a?(NSToolbarItem) ? x.itemIdentifier : x }
56
+ @allowed.map! { |x| x.is_a?(NSToolbarItem) ? x.itemIdentifier : x }
57
+
55
58
  @custom_items = {}
56
- ary.each { |x| @custom_items[x.itemIdentifier] = x }
59
+ ary.each { |x| @custom_items[x.itemIdentifier] = x }
57
60
  @allowed.concat(@custom_items.keys)
58
- @default.concat(@custom_items.keys)
59
61
 
60
62
  [@allowed, @default].each do |a|
61
63
  a.map! do |i|
@@ -81,6 +83,7 @@ HotCocoa::Mappings.map :toolbar => :NSToolbar do
81
83
  end
82
84
  allowed_items { @allowed }
83
85
  default_items { @default }
86
+
84
87
  item_for_identifier { |identifier, will_be_inserted| @custom_items[identifier] }
85
88
  end
86
89
  end
@@ -101,7 +101,13 @@ module HotCocoa
101
101
 
102
102
  # Returns whether or not the framework has been loaded yet.
103
103
  def self.loaded_framework?(name)
104
- NSBundle.allFrameworks.map {|bundle| bundle.bundlePath.split("/").last}.select {|framework| framework.split(".")[1] == 'framework'}.map {|framework| framework.split(".")[0]}.include?(name.to_s)
104
+ NSBundle.allFrameworks.map { |bundle|
105
+ bundle.bundlePath.split("/").last
106
+ }.select { |framework|
107
+ framework.split(".")[1] == 'framework'
108
+ }.map { |framework|
109
+ framework.split(".")[0]
110
+ }.include?(name.to_s)
105
111
  end
106
112
 
107
113
  end
@@ -1,17 +1,21 @@
1
1
  AppConfig = HotCocoa::ApplicationBuilder::Configuration.new("config/build.yml")
2
2
 
3
+ desc "Build a deployable version of the application"
3
4
  task :deploy => [:clean] do
4
5
  HotCocoa::ApplicationBuilder.build(AppConfig, :deploy => true)
5
6
  end
6
7
 
8
+ desc "Build the application"
7
9
  task :build do
8
10
  HotCocoa::ApplicationBuilder.build(AppConfig)
9
11
  end
10
12
 
13
+ desc "Build and execute the application"
11
14
  task :run => [:build] do
12
15
  `"./#{AppConfig.name}.app/Contents/MacOS/#{AppConfig.name.gsub(/ /, '')}"`
13
16
  end
14
17
 
18
+ desc "Cleanup build files"
15
19
  task :clean do
16
20
  `/bin/rm -rf "#{AppConfig.name}.app"`
17
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotcocoa
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.5"
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Kilmer
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-20 00:00:00 -05:00
12
+ date: 2010-01-25 00:00:00 -05:00
13
13
  default_executable: hotcocoa
14
14
  dependencies: []
15
15
 
16
- description: HotCocoa is a Cococa mapping library for MacRuby. It simplifies the use of complex Cocoa classes using DSL techniques.
16
+ description: HotCocoa is a Cocoa mapping library for MacRuby. It simplifies the use of complex Cocoa classes using DSL techniques.
17
17
  email: rich@infoether.com
18
18
  executables:
19
19
  - hotcocoa
@@ -94,7 +94,6 @@ files:
94
94
  - lib/hotcocoa/plist.rb
95
95
  - lib/hotcocoa/standard_rake_tasks.rb
96
96
  - lib/hotcocoa/template.rb
97
- - lib/hotcocoa/virtual_file_system.rb
98
97
  - lib/hotcocoa.rb
99
98
  - template/config/build.yml
100
99
  - template/lib/application.rb
@@ -1,172 +0,0 @@
1
- class VirtualFileSystem
2
-
3
- def self.code_to_load(main_file, password = "\320\302\354\024\215\360P\235\2244\261\214\276:'\274%\270<\350t\212\003\340\t'\004\345\334\256\315\277")
4
- <<-VFS
5
- module DatabaseRuntime
6
-
7
- class VirtualFilesystem
8
-
9
- attr_reader :password, :encryption_method
10
-
11
- def initialize(password, encryption_method="aes256")
12
- @password = password
13
- @encryption_method = encryption_method
14
- end
15
-
16
- def open_database(main_database)
17
- @main_database = main_database
18
- begin
19
- @db = Marshal.load(File.open(main_database, "rb") {|f| f.read})
20
- rescue
21
- puts $!
22
- puts $!.backtrace.join("\\n")
23
- end
24
- end
25
-
26
- def read_file_and_key(filename)
27
- data, key = read_file_using_path(filename)
28
- if data.nil? && filename[0,1] != "/"
29
- $:.each do |loadpath|
30
- data, key = read_file_using_path(filename, expand_path(loadpath))
31
- break if data
32
- end
33
- end
34
- [data, key]
35
- end
36
-
37
- def read_file_using_path(filename, pathname="/")
38
- path = expand_path(File.join(pathname, filename))
39
- rb_ext = false
40
- if has_key?(path)
41
- key = filename
42
- elsif self.has_key?(path+".rb")
43
- key = filename+".rb"
44
- rb_ext = true
45
- end
46
- if key
47
- result = rb_ext ? self[path+".rb"] : self[path]
48
- if result
49
- result.gsub!(/__FILE__/, "'\#{path + (rb_ext ? ".rb" : '')}'")
50
- return result, key
51
- end
52
- end
53
- nil
54
- end
55
-
56
- def has_key?(key)
57
- @db.has_key?(key)
58
- end
59
-
60
- def delete(key)
61
- end
62
-
63
- def [](key)
64
- read(@db, key)
65
- end
66
-
67
- def close
68
- end
69
-
70
- def keys
71
- @db.keys
72
- end
73
-
74
- def []=(key, value)
75
- end
76
-
77
- def normalize(filename)
78
- f = filename.split(File::Separator)
79
- f.delete(".")
80
- while f.include?("..")
81
- f[f.index("..")-1,2] = []
82
- end
83
- f.join(File::Separator)
84
- end
85
-
86
- private
87
-
88
- def expand_path(filename, dirstring=nil)
89
- filename = File.join(dirstring, filename) if dirstring
90
- f = filename.split(File::Separator)
91
- f.delete(".")
92
- f.delete("")
93
- while f.include?("..")
94
- f[f.index("..")-1,2] = []
95
- end
96
- "/"+f.join(File::Separator)
97
- end
98
-
99
-
100
- def read(db, key)
101
- if db.has_key?(key)
102
- #decrypt = OpenSSL::Cipher::Cipher.new(encryption_method)
103
- #decrypt.decrypt
104
- #decrypt.key = password
105
- #data = decrypt.update(db[key])
106
- #data << decrypt.final
107
- #::Zlib::Inflate.inflate(data)
108
- db[key]
109
- else
110
- nil
111
- end
112
- end
113
-
114
- end
115
-
116
- end
117
-
118
- $ROOT_BINDING = binding
119
-
120
- module Kernel
121
-
122
- def virtual_filesystems(options)
123
- vfs = DatabaseRuntime::VirtualFilesystem.new(options["password"])
124
- vfs.open_database(options["database"])
125
- Kernel.const_set("VIRTUAL_FILESYSTEM", vfs)
126
- vfs
127
- end
128
-
129
- alias_method :original_require, :require
130
-
131
- def require(path)
132
- path = VIRTUAL_FILESYSTEM.normalize(path)
133
- path_loaded = $".include?(path) || $".include?(path+".rb") || $".include?(path+".so")
134
- unless path_loaded
135
- data, key = VIRTUAL_FILESYSTEM.read_file_and_key(path)
136
- if data
137
- $" << key
138
- eval(data, $ROOT_BINDING, key, 0)
139
- return true
140
- else
141
- original_require(path)
142
- end
143
- else
144
- return false
145
- end
146
- end
147
-
148
- alias_method :original_load, :load
149
-
150
- def load(path)
151
- path = VIRTUAL_FILESYSTEM.normalize(path)
152
- data, key = VIRTUAL_FILESYSTEM.read_file_and_key(path)
153
- if data
154
- eval(data, $ROOT_BINDING, key, 0)
155
- return true
156
- else
157
- begin
158
- original_load(path)
159
- rescue LoadError => e
160
- raise e
161
- end
162
- end
163
- end
164
-
165
- end
166
-
167
- virtual_filesystems("database"=>File.join(NSBundle.mainBundle.resourcePath.fileSystemRepresentation, 'vfs.db'), "password"=>#{password.inspect})
168
- $:.unshift "/lib"
169
- load '#{main_file}'
170
- VFS
171
- end
172
- end