hotcocoa 0.6.0pre2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,19 +1,23 @@
1
- === 0.6.0 2011-10-xx
1
+ === 0.6.0 2011-10-14
2
2
 
3
- * 8 enhancements:
3
+ * 10 enhancements:
4
4
  * New application builder to work with MacRuby 0.11
5
- * Application templates now use an appspec, similar to a gemspec
6
- * Truer lazy loading for mappings (may break custom mappings!)
7
- * API documention (67% coverage so far)
5
+ * Old application builder is deprecated
6
+ * New application templates now use an appspec, similar to a gemspec
7
+ * config.yml is now deprecated
8
+ * Lazier loading for mappings (may break custom mappings!)
9
+ * API documention (~67% coverage so far)
8
10
  * Regression tests (< 67% coverage so far)
9
11
  * Updating and porting of the tutorial documentation (~40% complete)
10
- * HotCocoa now works when compiled
11
- * HotCocoa is now leaner and meaner
12
+ * HotCocoa now works when compiled (HotCocoa will boot ~2.5 faster)
13
+ * HotCocoa is now leaner
14
+ * Various bug fixes
12
15
 
13
- * 3 new mappings:
14
- * NSNetService => bonjour_service
15
- * NSNetServiceBrowser => bonjour_browser
16
- * NSBezierPath => line
16
+ * 4 new mappings:
17
+ * bonjour_service => NSNetService
18
+ * bonjour_browser => NSNetServiceBrowser
19
+ * line => NSBezierPath
20
+ * tracking_area => NSTrackingArea
17
21
 
18
22
  * 2 graphics improvements:
19
23
  * Image class works with more image types
@@ -186,6 +186,7 @@ module Application
186
186
  LSMinimumSystemVersion: '10.6.7', # @todo should match MacRuby
187
187
  }
188
188
  info[:CFBundleIconFile] = File.basename(spec.icon) if spec.icon_exists?
189
+ info[:CFBundleDocumentTypes] = spec.doc_types.map(&:info_plist_representation) unless spec.doc_types.empty?
189
190
  info.merge! spec.plist # should always be done last
190
191
  info.to_plist
191
192
  end
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##
4
+ # Application is a namespace for the classes that are used to specify
5
+ # and build application bundles.
6
+ module Application
7
+
8
+ ##
9
+ # This class represents the configuration for a document type, used by document-based applications.
10
+ # It is used to generate the Info.plist file
11
+ #
12
+ # See http://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html for details.
13
+ #
14
+ class DocumentTypeSpecification
15
+ VALID_ROLES = {:editor => "Editor", :viewer => "Viewer", :none => "None"}
16
+
17
+ attr_writer :extensions
18
+ attr_writer :icon
19
+ attr_writer :name
20
+ attr_writer :role
21
+ attr_writer :class
22
+
23
+ def initialize
24
+ unless block_given?
25
+ msg = 'You must pass a block at initialization to declare the new document type'
26
+ raise ArgumentError, msg
27
+ end
28
+ yield self
29
+
30
+ verify!
31
+ end
32
+
33
+ # @todo CFBundleTypeMIMETypes
34
+ # @todo LSTypeIsPackage
35
+ # @todo CFBundleTypeOSTypes
36
+ def info_plist_representation
37
+ {
38
+ CFBundleTypeExtensions: @extensions,
39
+ CFBundleTypeIconFile: @icon,
40
+ CFBundleTypeName: @name,
41
+ CFBundleTypeRole: VALID_ROLES[@role],
42
+ NSDocumentClass: @class
43
+ }
44
+ end
45
+
46
+ protected
47
+ def verify!
48
+ verify_name
49
+ verify_extensions
50
+ verify_role
51
+ end
52
+
53
+ def verify_name
54
+ raise ArgumentError, "doc type name must not be empty" if @name.nil? or @name.empty?
55
+ end
56
+
57
+ def verify_extensions
58
+ raise ArgumentError, "doc type extensions must be an array" unless @extensions.is_a?(Array)
59
+ end
60
+
61
+ def verify_role
62
+ raise ArgumentError, "#{@role} is not a valid role. A doc type role must be one of [:editor, :viewer, :none]" unless VALID_ROLES.keys.include?(@role)
63
+ end
64
+ end
65
+ end
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'rubygems'
4
+ require 'hotcocoa/application/document_type_specification'
4
5
 
5
6
  ##
6
7
  # Application is a namespace for the classes that are used to specify
@@ -114,9 +115,11 @@ module Application
114
115
  # @return [Boolean]
115
116
  attr_accessor :agent
116
117
 
117
- # @todo CFBundleDocumentTypes
118
+ ##
119
+ # The list of document types supported by the application (for document-based applications only). Optional
120
+ #
118
121
  # @return [Array<Hash>]
119
- # attr_accessor :doc_types
122
+ attr_accessor :doc_types
120
123
 
121
124
  ##
122
125
  # Any additional plist values that an application could have.
@@ -232,6 +235,23 @@ module Application
232
235
  end
233
236
  alias_method :add_dependency, :add_runtime_dependency
234
237
 
238
+ ##
239
+ # Declares a document type for your document-driven application.
240
+ # (see http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Tasks/ImplementingDocApp.html)
241
+ #
242
+ # @example
243
+ #
244
+ # spec.declare_doc_type do |doc_type|
245
+ # doc_type.extensions = ["ext"]
246
+ # doc_type.icon = "MyIcon.icns"
247
+ # doc_type.name = "MyProjectDocument"
248
+ # doc_type.role = :editor
249
+ # doc_type.class = "MyDocument"
250
+ # end
251
+ def declare_doc_type(&block)
252
+ @doc_types << DocumentTypeSpecification.new(&block)
253
+ end
254
+
235
255
  ##
236
256
  # Whether or not to embed BridgeSupport files when embedding the
237
257
  # MacRuby framework during deployment.
@@ -254,24 +274,8 @@ module Application
254
274
 
255
275
  # @endgroup
256
276
 
257
- DEFAULT_ATTRIBUTES = {
258
- plist: {},
259
- sources: [],
260
- resources: [],
261
- data_models: [],
262
- gems: [],
263
- type: 'APPL',
264
- signature: '????',
265
- version: '1.0',
266
- stdlib: true,
267
- agent: false,
268
- compile: true,
269
- overwrite: false,
270
- embed_bs: false
271
- }
272
-
273
277
  def initialize
274
- DEFAULT_ATTRIBUTES.each { |key, value| send "#{key}=", value }
278
+ default_attributes.each { |key, value| send "#{key}=", value }
275
279
 
276
280
  unless block_given?
277
281
  msg = 'You must pass a block at initialization to setup the specification'
@@ -305,6 +309,24 @@ module Application
305
309
 
306
310
 
307
311
  private
312
+ def default_attributes
313
+ {
314
+ plist: {},
315
+ sources: [],
316
+ resources: [],
317
+ data_models: [],
318
+ gems: [],
319
+ doc_types: [],
320
+ type: 'APPL',
321
+ signature: '????',
322
+ version: '1.0',
323
+ stdlib: true,
324
+ agent: false,
325
+ compile: true,
326
+ overwrite: false,
327
+ embed_bs: false
328
+ }
329
+ end
308
330
 
309
331
  def verify_name
310
332
  raise Error, 'a name is required for an appspec' unless @name
@@ -1,12 +1,12 @@
1
1
  $stderr.puts <<EOM
2
- The old build system, which uses standard_rake_tasks.rb is deprecated in favour
2
+ The old build system, which uses standard_rake_tasks.rb, is deprecated in favour
3
3
  of a more easily configurable build system as of HotCocoa 0.6. The old build
4
4
  system will be removed in HotCocoa 0.7.
5
5
 
6
6
  You can update your existing project by looking at the new project template, which
7
7
  can be found on Github:
8
8
 
9
- https://github.com/ferrous26/hotcocoa/blob/master/template
9
+ https://github.com/ferrous26/hotcocoa/blob/master/template
10
10
 
11
11
  EOM
12
12
 
@@ -1,3 +1,3 @@
1
1
  module HotCocoa
2
- VERSION = '0.6.0pre2'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -38,5 +38,15 @@ Application::Specification.new do |s|
38
38
  # You can use this flag to hide the dock icon for the app; the
39
39
  # default value is false so that apps will have a dock icon
40
40
  # s.agent = true
41
+
42
+ # uncomment the block below to declare document types for your document-based application
43
+ # you can declare multiple document types by specifying several declare_doc_type blocks
44
+ # s.declare_doc_type do |doc_type|
45
+ # doc_type.extensions = ["ext"]
46
+ # doc_type.icon = "MyIcon.icns"
47
+ # doc_type.name = "MyProjectDocument"
48
+ # doc_type.role = :viewer # one of [:editor, :viewer, :none]
49
+ # doc_type.class = "MyDocument"
50
+ # end
41
51
  end
42
52
 
@@ -68,4 +68,17 @@ class TestApplicationBuilder < TestApplicationModule
68
68
  assert_equal spec.identifier, plist[:CFBundleIdentifier]
69
69
  end
70
70
 
71
+ def test_plist_doctype_generated_if_present
72
+ spec = minimal_spec do |s|
73
+ s.declare_doc_type do |doc_type|
74
+ doc_type.extensions = ["ext"]
75
+ doc_type.icon = "MyIcon.icns"
76
+ doc_type.name = "MyProjectDocument"
77
+ doc_type.role = :viewer
78
+ doc_type.class = "MyDocument"
79
+ end
80
+ end
81
+ plist = load_plist(Builder.new(spec).send(:info_plist))
82
+ assert_equal 1, plist[:CFBundleDocumentTypes].size
83
+ end
71
84
  end
@@ -0,0 +1,66 @@
1
+ require 'test/application/helper'
2
+
3
+ class TestApplicationDocumentTypeSpecification < TestApplicationModule
4
+ def rescue_spec_error_for
5
+ begin
6
+ yield
7
+ rescue ArgumentError => e
8
+ return e
9
+ end
10
+ flunk "no error thrown!"
11
+ end
12
+
13
+ def minimal_doc_type_spec
14
+ DocumentTypeSpecification.new do |s|
15
+ s.extensions = ["ext"]
16
+ s.name = "MyProjectDocument"
17
+ s.role = :editor
18
+ yield s if block_given?
19
+ end
20
+ end
21
+
22
+ def test_definition_of_a_valid_specification
23
+ type = DocumentTypeSpecification.new do |doc_type|
24
+ doc_type.extensions = ["ext"]
25
+ doc_type.icon = "MyIcon.icns"
26
+ doc_type.name = "MyProjectDocument"
27
+ doc_type.role = :editor
28
+ doc_type.class = "MyDocument"
29
+ end
30
+ assert_equal ["ext"], type.info_plist_representation[:CFBundleTypeExtensions]
31
+ assert_equal "MyIcon.icns", type.info_plist_representation[:CFBundleTypeIconFile]
32
+ assert_equal "MyProjectDocument", type.info_plist_representation[:CFBundleTypeName]
33
+ assert_equal "Editor", type.info_plist_representation[:CFBundleTypeRole]
34
+ assert_equal "MyDocument", type.info_plist_representation[:NSDocumentClass]
35
+ end
36
+
37
+ def test_extensions_are_an_array
38
+ exception = rescue_spec_error_for do
39
+ minimal_doc_type_spec {|s| s.extensions = 123}
40
+ end
41
+ assert_match /must be an array/, exception.message
42
+ end
43
+
44
+ def test_role_is_valid
45
+ [:editor, :viewer, :none].each do |role|
46
+ minimal_doc_type_spec {|s| s.role = role}
47
+ end
48
+
49
+ exception = rescue_spec_error_for do
50
+ minimal_doc_type_spec {|s| s.role = "xxx"}
51
+ end
52
+ assert_match /not a valid role/, exception.message
53
+ end
54
+
55
+ def test_name_is_not_empty
56
+ exception = rescue_spec_error_for do
57
+ minimal_doc_type_spec {|s| s.name = ""}
58
+ end
59
+ assert_match /must not be empty/, exception.message
60
+
61
+ exception = rescue_spec_error_for do
62
+ minimal_doc_type_spec {|s| s.name = nil}
63
+ end
64
+ assert_match /must not be empty/, exception.message
65
+ end
66
+ end
@@ -8,6 +8,7 @@ class TestApplicationSpecification < TestApplicationModule
8
8
  rescue Specification::Error => e
9
9
  return e
10
10
  end
11
+ flunk "no error thrown!"
11
12
  end
12
13
 
13
14
  def test_spec_requires_a_block
@@ -224,7 +225,7 @@ class TestApplicationSpecification < TestApplicationModule
224
225
  assert_equal true, spec.embed_bs
225
226
  end
226
227
 
227
- def test_overwirte_attribute_is_false_by_default
228
+ def test_overwrite_attribute_is_false_by_default
228
229
  spec = minimal_spec
229
230
  refute spec.overwrite?
230
231
 
@@ -232,6 +233,30 @@ class TestApplicationSpecification < TestApplicationModule
232
233
  assert spec.overwrite?
233
234
  end
234
235
 
236
+ def test_doc_types_is_empty_by_default
237
+ assert_equal [], minimal_spec.doc_types
238
+ end
239
+
240
+ def test_doc_types_can_be_added
241
+ spec = minimal_spec do |s|
242
+ s.declare_doc_type do |doc_type|
243
+ doc_type.extensions = ["ext"]
244
+ doc_type.icon = "MyIcon.icns"
245
+ doc_type.name = "MyProjectDocument"
246
+ doc_type.role = :viewer
247
+ doc_type.class = "MyDocument"
248
+ end
249
+ end
250
+ assert 1, spec.doc_types.size
251
+ end
252
+
253
+ def test_doc_type_declaration_requires_a_block
254
+ exception = assert_raises ArgumentError do
255
+ minimal_spec {|s| s.declare_doc_type}
256
+ end
257
+ assert_match /must pass a block/, exception.message
258
+ end
259
+
235
260
  def test_icon_exists?
236
261
  refute minimal_spec.icon_exists?
237
262
 
@@ -244,6 +269,13 @@ class TestApplicationSpecification < TestApplicationModule
244
269
  assert spec.icon_exists?
245
270
  end
246
271
 
272
+ def test_defaults_are_immutable
273
+ first_spec = minimal_spec {|s| s.sources << ["/path/to/source"]}
274
+
275
+ second_spec = minimal_spec
276
+ assert_empty second_spec.sources
277
+ end
278
+
247
279
  # doubles as an integration test
248
280
  def test_load_evaluates_files_properly
249
281
  spec = hotconsole_spec
@@ -263,5 +295,4 @@ class TestApplicationSpecification < TestApplicationModule
263
295
  assert_equal true, spec.overwrite
264
296
  assert_equal false, spec.stdlib
265
297
  end
266
-
267
298
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotcocoa
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 5
5
- version: 0.6.0pre2
4
+ prerelease:
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Richard Kilmer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-08 00:00:00 -04:00
13
+ date: 2011-10-14 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -83,6 +83,7 @@ files:
83
83
  - .yardopts
84
84
  - bin/hotcocoa
85
85
  - lib/hotcocoa/application/builder.rb
86
+ - lib/hotcocoa/application/document_type_specification.rb
86
87
  - lib/hotcocoa/application/specification.rb
87
88
  - lib/hotcocoa/application_builder.rb
88
89
  - lib/hotcocoa/attributed_string_helpers.rb
@@ -181,6 +182,7 @@ files:
181
182
  - template/resources/HotCocoa.icns
182
183
  - test/application/helper.rb
183
184
  - test/application/test_builder.rb
185
+ - test/application/test_document_type_specification.rb
184
186
  - test/application/test_specification.rb
185
187
  - test/core_extensions/test_kernel.rb
186
188
  - test/core_extensions/test_nsarray.rb
@@ -229,9 +231,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
231
  required_rubygems_version: !ruby/object:Gem::Requirement
230
232
  none: false
231
233
  requirements:
232
- - - '>'
234
+ - - '>='
233
235
  - !ruby/object:Gem::Version
234
- version: 1.3.1
236
+ version: "0"
235
237
  requirements: []
236
238
  rubyforge_project:
237
239
  rubygems_version: 1.4.2
@@ -241,6 +243,7 @@ summary: Cocoa mapping library for MacRuby
241
243
  test_files:
242
244
  - test/application/helper.rb
243
245
  - test/application/test_builder.rb
246
+ - test/application/test_document_type_specification.rb
244
247
  - test/application/test_specification.rb
245
248
  - test/core_extensions/test_kernel.rb
246
249
  - test/core_extensions/test_nsarray.rb