hotcocoa 0.5.1 → 0.6.0pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +14 -0
- data/History.txt +21 -0
- data/README.markdown +84 -0
- data/Rakefile +47 -0
- data/bin/hotcocoa +20 -10
- data/docs/Contributors.markdown +25 -0
- data/docs/Mappings.markdown +352 -0
- data/docs/MappingsExplained.markdown +22 -0
- data/docs/Overview.markdown +58 -0
- data/docs/Resources.markdown +25 -0
- data/docs/Tutorial.markdown +3 -0
- data/lib/hotcocoa/application/builder.rb +237 -0
- data/lib/hotcocoa/application/specification.rb +373 -0
- data/lib/hotcocoa/application_builder.rb +338 -242
- data/lib/hotcocoa/attributed_string_helpers.rb +128 -0
- data/lib/hotcocoa/behaviors.rb +39 -6
- data/lib/hotcocoa/core_extensions/kernel.rb +67 -0
- data/lib/hotcocoa/core_extensions/nsarray.rb +15 -0
- data/lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb +74 -0
- data/lib/hotcocoa/core_extensions/nsstring.rb +36 -0
- data/lib/hotcocoa/core_extensions/nsurl.rb +6 -0
- data/lib/hotcocoa/core_extensions/numeric.rb +9 -0
- data/lib/hotcocoa/core_extensions/object.rb +36 -0
- data/lib/hotcocoa/core_extensions/range.rb +30 -0
- data/lib/hotcocoa/core_extensions.rb +8 -0
- data/lib/hotcocoa/data_sources/combo_box_data_source.rb +38 -38
- data/lib/hotcocoa/data_sources/outline_view_data_source.rb +33 -0
- data/lib/hotcocoa/data_sources/table_data_source.rb +12 -13
- data/lib/hotcocoa/data_sources.rb +3 -0
- data/lib/hotcocoa/delegate_builder.rb +114 -79
- data/lib/hotcocoa/graphics/canvas.rb +211 -214
- data/lib/hotcocoa/graphics/color.rb +89 -91
- data/lib/hotcocoa/graphics/elements/particle.rb +16 -19
- data/lib/hotcocoa/graphics/elements/rope.rb +12 -14
- data/lib/hotcocoa/graphics/elements/sandpainter.rb +11 -13
- data/lib/hotcocoa/graphics/gradient.rb +13 -14
- data/lib/hotcocoa/graphics/image.rb +110 -83
- data/lib/hotcocoa/graphics/path.rb +44 -50
- data/lib/hotcocoa/graphics/pdf.rb +17 -19
- data/lib/hotcocoa/graphics.rb +21 -20
- data/lib/hotcocoa/kvo_accessors.rb +10 -11
- data/lib/hotcocoa/layout_view.rb +394 -379
- data/lib/hotcocoa/mapper.rb +346 -207
- data/lib/hotcocoa/mapping_methods.rb +107 -37
- data/lib/hotcocoa/mappings/appkit/alert.rb +25 -0
- data/lib/hotcocoa/mappings/appkit/application.rb +112 -0
- data/lib/hotcocoa/mappings/{array_controller.rb → appkit/array_controller.rb} +33 -35
- data/lib/hotcocoa/mappings/appkit/box.rb +37 -0
- data/lib/hotcocoa/mappings/appkit/button.rb +88 -0
- data/lib/hotcocoa/mappings/appkit/collection_view.rb +42 -0
- data/lib/hotcocoa/mappings/appkit/color.rb +40 -0
- data/lib/hotcocoa/mappings/appkit/column.rb +19 -0
- data/lib/hotcocoa/mappings/appkit/combo_box.rb +22 -0
- data/lib/hotcocoa/mappings/appkit/control.rb +31 -0
- data/lib/hotcocoa/mappings/appkit/font.rb +58 -0
- data/lib/hotcocoa/mappings/appkit/gradient.rb +19 -0
- data/lib/hotcocoa/mappings/appkit/image.rb +15 -0
- data/lib/hotcocoa/mappings/appkit/image_view.rb +41 -0
- data/lib/hotcocoa/mappings/appkit/label.rb +23 -0
- data/lib/hotcocoa/mappings/appkit/layout_view.rb +9 -0
- data/lib/hotcocoa/mappings/appkit/line.rb +16 -0
- data/lib/hotcocoa/mappings/appkit/menu.rb +78 -0
- data/lib/hotcocoa/mappings/appkit/menu_item.rb +47 -0
- data/lib/hotcocoa/mappings/appkit/outline_view.rb +62 -0
- data/lib/hotcocoa/mappings/appkit/popup.rb +106 -0
- data/lib/hotcocoa/mappings/appkit/progress_indicator.rb +61 -0
- data/lib/hotcocoa/mappings/appkit/scroll_view.rb +28 -0
- data/lib/hotcocoa/mappings/appkit/search_field.rb +9 -0
- data/lib/hotcocoa/mappings/appkit/secure_text_field.rb +15 -0
- data/lib/hotcocoa/mappings/appkit/segmented_control.rb +103 -0
- data/lib/hotcocoa/mappings/appkit/slider.rb +23 -0
- data/lib/hotcocoa/mappings/appkit/sound.rb +9 -0
- data/lib/hotcocoa/mappings/appkit/speech_synthesizer.rb +22 -0
- data/lib/hotcocoa/mappings/appkit/split_view.rb +19 -0
- data/lib/hotcocoa/mappings/appkit/status_bar.rb +7 -0
- data/lib/hotcocoa/mappings/appkit/status_item.rb +9 -0
- data/lib/hotcocoa/mappings/appkit/table_view.rb +108 -0
- data/lib/hotcocoa/mappings/appkit/text_field.rb +36 -0
- data/lib/hotcocoa/mappings/appkit/text_view.rb +13 -0
- data/lib/hotcocoa/mappings/appkit/toolbar.rb +99 -0
- data/lib/hotcocoa/mappings/appkit/toolbar_item.rb +36 -0
- data/lib/hotcocoa/mappings/appkit/tracking_area.rb +24 -0
- data/lib/hotcocoa/mappings/appkit/view.rb +65 -0
- data/lib/hotcocoa/mappings/appkit/window.rb +124 -0
- data/lib/hotcocoa/mappings/foundation/net_service.rb +65 -0
- data/lib/hotcocoa/mappings/foundation/net_service_browser.rb +27 -0
- data/lib/hotcocoa/mappings/foundation/notification.rb +24 -0
- data/lib/hotcocoa/mappings/foundation/sort_descriptor.rb +17 -0
- data/lib/hotcocoa/mappings/foundation/timer.rb +38 -0
- data/lib/hotcocoa/mappings/foundation/user_defaults.rb +43 -0
- data/lib/hotcocoa/mappings/foundation/xml_parser.rb +44 -0
- data/lib/hotcocoa/mappings/qtkit/movie.rb +15 -0
- data/lib/hotcocoa/mappings/qtkit/movie_view.rb +28 -0
- data/lib/hotcocoa/mappings/webkit/web_view.rb +20 -0
- data/lib/hotcocoa/mappings.rb +57 -111
- data/lib/hotcocoa/mvc.rb +90 -81
- data/lib/hotcocoa/notification_listener.rb +135 -58
- data/lib/hotcocoa/standard_rake_tasks.rb +17 -9
- data/lib/hotcocoa/target_action_convenience.rb +39 -0
- data/lib/hotcocoa/template.rb +90 -21
- data/lib/hotcocoa/version.rb +3 -0
- data/lib/hotcocoa.rb +12 -14
- data/template/Rakefile +31 -3
- data/template/__APPLICATION_NAME__.appspec +8 -0
- data/template/lib/application.rb +14 -17
- data/template/lib/menu.rb +11 -11
- data/test/application/test_builder.rb +28 -0
- data/test/application/test_specification.rb +280 -0
- data/test/core_extensions/test_kernel.rb +66 -0
- data/test/core_extensions/test_nsarray.rb +9 -0
- data/test/core_extensions/test_nsmutable_attributed_string.rb +86 -0
- data/test/core_extensions/test_nsstring.rb +20 -0
- data/test/core_extensions/test_nsurl.rb +9 -0
- data/test/core_extensions/test_numeric.rb +10 -0
- data/test/core_extensions/test_object.rb +37 -0
- data/test/core_extensions/test_range.rb +28 -0
- data/test/helper.rb +30 -0
- data/test/mappings/test_bonjour.rb +79 -0
- data/test/mappings/test_color.rb +16 -0
- data/test/mappings/test_font.rb +21 -0
- data/test/mappings/test_tracking_area.rb +18 -0
- data/test/test_application_builder.rb +95 -0
- data/test/test_attributed_string_helpers.rb +63 -0
- data/test/test_behaviours.rb +26 -0
- data/test/test_bin.rb +75 -0
- data/test/test_mapper.rb +100 -0
- data/test/test_mapping_methods.rb +67 -0
- data/test/test_mappings.rb +68 -0
- data/test/test_notification_listener.rb +19 -0
- data/test/test_template.rb +65 -0
- metadata +217 -90
- data/lib/hotcocoa/attributed_string.rb +0 -143
- data/lib/hotcocoa/kernel_ext.rb +0 -14
- data/lib/hotcocoa/mappings/alert.rb +0 -25
- data/lib/hotcocoa/mappings/application.rb +0 -112
- data/lib/hotcocoa/mappings/box.rb +0 -39
- data/lib/hotcocoa/mappings/button.rb +0 -92
- data/lib/hotcocoa/mappings/collection_view.rb +0 -44
- data/lib/hotcocoa/mappings/color.rb +0 -28
- data/lib/hotcocoa/mappings/column.rb +0 -21
- data/lib/hotcocoa/mappings/combo_box.rb +0 -24
- data/lib/hotcocoa/mappings/control.rb +0 -33
- data/lib/hotcocoa/mappings/font.rb +0 -44
- data/lib/hotcocoa/mappings/gradient.rb +0 -15
- data/lib/hotcocoa/mappings/image.rb +0 -15
- data/lib/hotcocoa/mappings/image_view.rb +0 -43
- data/lib/hotcocoa/mappings/label.rb +0 -25
- data/lib/hotcocoa/mappings/layout_view.rb +0 -9
- data/lib/hotcocoa/mappings/menu.rb +0 -71
- data/lib/hotcocoa/mappings/menu_item.rb +0 -47
- data/lib/hotcocoa/mappings/movie.rb +0 -13
- data/lib/hotcocoa/mappings/movie_view.rb +0 -27
- data/lib/hotcocoa/mappings/notification.rb +0 -17
- data/lib/hotcocoa/mappings/popup.rb +0 -110
- data/lib/hotcocoa/mappings/progress_indicator.rb +0 -68
- data/lib/hotcocoa/mappings/scroll_view.rb +0 -29
- data/lib/hotcocoa/mappings/search_field.rb +0 -9
- data/lib/hotcocoa/mappings/secure_text_field.rb +0 -17
- data/lib/hotcocoa/mappings/segmented_control.rb +0 -97
- data/lib/hotcocoa/mappings/slider.rb +0 -25
- data/lib/hotcocoa/mappings/sort_descriptor.rb +0 -13
- data/lib/hotcocoa/mappings/sound.rb +0 -9
- data/lib/hotcocoa/mappings/speech_synthesizer.rb +0 -25
- data/lib/hotcocoa/mappings/split_view.rb +0 -21
- data/lib/hotcocoa/mappings/status_bar.rb +0 -7
- data/lib/hotcocoa/mappings/status_item.rb +0 -9
- data/lib/hotcocoa/mappings/table_view.rb +0 -110
- data/lib/hotcocoa/mappings/text_field.rb +0 -41
- data/lib/hotcocoa/mappings/text_view.rb +0 -13
- data/lib/hotcocoa/mappings/timer.rb +0 -25
- data/lib/hotcocoa/mappings/toolbar.rb +0 -100
- data/lib/hotcocoa/mappings/toolbar_item.rb +0 -36
- data/lib/hotcocoa/mappings/view.rb +0 -67
- data/lib/hotcocoa/mappings/web_view.rb +0 -22
- data/lib/hotcocoa/mappings/window.rb +0 -118
- data/lib/hotcocoa/mappings/xml_parser.rb +0 -41
- data/lib/hotcocoa/object_ext.rb +0 -22
- data/lib/hotcocoa/plist.rb +0 -45
- data/template/config/build.yml +0 -8
- data/test/test_helper.rb +0 -3
- data/test/test_hotcocoa.rb +0 -11
@@ -0,0 +1,27 @@
|
|
1
|
+
HotCocoa::Mappings.map bonjour_browser: NSNetServiceBrowser do
|
2
|
+
|
3
|
+
##
|
4
|
+
# There are no values that need to be set at initialization
|
5
|
+
def init_with_options browser, opts
|
6
|
+
browser.init
|
7
|
+
end
|
8
|
+
|
9
|
+
custom_methods do
|
10
|
+
def search_for_services type, domain = ''
|
11
|
+
searchForServicesOfType type, inDomain: domain
|
12
|
+
end
|
13
|
+
|
14
|
+
def search_for_domains
|
15
|
+
searchForBrowsableDomains
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
delegating 'netServiceBrowser:didFindDomain:moreComing:', to: 'did_find_domain', parameters: ['didFindDomain', 'moreComing']
|
20
|
+
delegating 'netServiceBrowser:didRemoveDomain:moreComing:', to: 'did_remove_domain', parameters: ['didRemoveDomain', 'moreComing']
|
21
|
+
delegating 'netServiceBrowser:didFindService:moreComing:', to: 'did_find_service', parameters: ['didFindService', 'moreComing']
|
22
|
+
delegating 'netServiceBrowser:didRemoveService:moreComing:', to: 'did_remove_service', parameters: ['didRemoveService', 'moreComing']
|
23
|
+
delegating 'netServiceBrowserWillSearch:', to: 'will_search'
|
24
|
+
delegating 'netServiceBrowser:didNotSearch:', to: 'did_not_search', parameters: ['didNotSearch']
|
25
|
+
delegating 'netServiceBrowserDidStopSearch:', to: 'did_stop_search'
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
HotCocoa::Mappings.map notification: NSNotification do
|
2
|
+
|
3
|
+
defaults post: true, distributed: false
|
4
|
+
|
5
|
+
def alloc_with_options options
|
6
|
+
if options.delete :post
|
7
|
+
if options.delete :distributed
|
8
|
+
NSDistributedNotificationCenter.defaultCenter.postNotificationName options.delete(:name),
|
9
|
+
object: options.delete(:object),
|
10
|
+
userInfo: options.delete(:info),
|
11
|
+
deliverImmediately: (options.delete(:immediately) == true)
|
12
|
+
else
|
13
|
+
NSNotificationCenter.defaultCenter.postNotificationName options.delete(:name),
|
14
|
+
object: options.delete(:object),
|
15
|
+
userInfo: options.delete(:info)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
NSNotification.notificationName options.delete(:name),
|
19
|
+
object: options.delete(:object),
|
20
|
+
userInfo: options.delete(:info)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
HotCocoa::Mappings.map sort_descriptor: NSSortDescriptor do
|
2
|
+
|
3
|
+
defaults ascending: true
|
4
|
+
|
5
|
+
def init_with_options sort_descriptor, opts
|
6
|
+
if opts.has_key? :selector
|
7
|
+
sort_descriptor.initWithKey opts.delete(:key),
|
8
|
+
ascending: opts.delete(:ascending)
|
9
|
+
|
10
|
+
else
|
11
|
+
sort_descriptor.initWithKey opts.delete(:key),
|
12
|
+
ascending: opts.delete(:ascending),
|
13
|
+
selector: opts.delete(:selector)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
HotCocoa::Mappings.map timer: NSTimer do
|
2
|
+
|
3
|
+
defaults scheduled: true, repeats: false
|
4
|
+
|
5
|
+
def alloc_with_options options
|
6
|
+
raise ArgumentError, 'timer requires :interval' unless options.has_key? :interval
|
7
|
+
|
8
|
+
target = options.delete :target
|
9
|
+
selector = options.delete :selector
|
10
|
+
unless target && selector
|
11
|
+
raise ArgumentError, 'timer requires either :target and :selector or :on_action' unless options.has_key? :on_action
|
12
|
+
|
13
|
+
target = Object.new
|
14
|
+
target.instance_variable_set(:@block, options.delete(:on_action))
|
15
|
+
|
16
|
+
def target.fire timer
|
17
|
+
@block.call(timer)
|
18
|
+
end
|
19
|
+
|
20
|
+
selector = 'fire:'
|
21
|
+
end
|
22
|
+
|
23
|
+
if options.delete :scheduled
|
24
|
+
NSTimer.scheduledTimerWithTimeInterval options.delete(:interval),
|
25
|
+
target: target,
|
26
|
+
selector: selector,
|
27
|
+
userInfo: options.delete(:info),
|
28
|
+
repeats: options.delete(:repeats)
|
29
|
+
else
|
30
|
+
NSTimer.timerWithTimeInterval options.delete(:interval),
|
31
|
+
target: target,
|
32
|
+
selector: selector,
|
33
|
+
userInfo: options.delete(:info),
|
34
|
+
repeats: options.delete(:repeats)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
HotCocoa::Mappings.map user_defaults: NSUserDefaults do
|
2
|
+
|
3
|
+
defaults defaults: {}
|
4
|
+
|
5
|
+
def alloc_with_options options
|
6
|
+
user_defaults = NSUserDefaults.standardUserDefaults
|
7
|
+
|
8
|
+
unless options[:defaults].nil?
|
9
|
+
defs = {}
|
10
|
+
# force all keys to be strings, doesn't seem to like symbols
|
11
|
+
options.delete(:defaults).each_pair { |key, value| defs[key.to_s] = value }
|
12
|
+
user_defaults.registerDefaults(defs)
|
13
|
+
end
|
14
|
+
|
15
|
+
user_defaults
|
16
|
+
end
|
17
|
+
|
18
|
+
custom_methods do
|
19
|
+
def []= key, value
|
20
|
+
if value.nil?
|
21
|
+
delete key.to_s
|
22
|
+
else
|
23
|
+
setObject value, forKey: key.to_s
|
24
|
+
end
|
25
|
+
sync
|
26
|
+
end
|
27
|
+
|
28
|
+
def [] key
|
29
|
+
objectForKey key.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def delete key
|
33
|
+
removeObjectForKey key.to_s
|
34
|
+
sync
|
35
|
+
end
|
36
|
+
|
37
|
+
# @todo Perhaps we should be making a an alert instead of printing to the log?
|
38
|
+
def sync
|
39
|
+
puts 'Failed to synchronize' unless synchronize
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
HotCocoa::Mappings.map xml_parser: NSXMLParser do
|
2
|
+
|
3
|
+
def alloc_with_options options
|
4
|
+
if options[:url]
|
5
|
+
url = options.delete :url
|
6
|
+
url = NSURL.URLWithString url if url.is_a? String
|
7
|
+
NSXMLParser.alloc.initWithContentsOfURL url
|
8
|
+
|
9
|
+
elsif options[:file]
|
10
|
+
NSXMLParser.alloc.initWithData NSData.dataWithContentsOfFile options.delete :file
|
11
|
+
|
12
|
+
elsif options[:data]
|
13
|
+
NSXMLParser.alloc.initWithData options.delete :data
|
14
|
+
|
15
|
+
else
|
16
|
+
raise 'Must provide either :url, :file, or :data when constructing an NSXMLParser'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
delegating 'parserDidStartDocument:', to: :on_start_document
|
21
|
+
delegating 'parserDidEndDocument:', to: :on_end_document
|
22
|
+
delegating 'parser:didStartElement:namespaceURI:qualifiedName:attributes:', to: :on_start_element, parameters: [:didStartElement, :namespaceURI, :qualifiedName, :attributes]
|
23
|
+
delegating 'parser:didEndElement:namespaceURI:qualifiedName:', to: :on_end_element, parameters: [:didEndElement, :namespaceURI, :qualifiedName]
|
24
|
+
delegating 'parser:didStartMappingPrefix:toURI:', to: :on_start_mapping_prefix, parameters: [:didStartMappingPrefix, :toURI]
|
25
|
+
delegating 'parser:didEndMappingPrefix:', to: :on_end_mapping_prefix, parameters: [:didEndMappingPrefix]
|
26
|
+
|
27
|
+
delegating 'parser:foundAttributeDeclarationWithName:forElement:type:defaultValue:', to: :on_attribute_declaration, parameters: [:foundAttributeDeclarationWithName, :forElement, :type, :defaultValue]
|
28
|
+
delegating 'parser:foundCDATA:', to: :on_cdata, parameters: [:foundCDATA]
|
29
|
+
delegating 'parser:foundCharacters:', to: :on_characters, parameters: [:foundCharacters]
|
30
|
+
delegating 'parser:foundComment:', to: :on_comment, parameters: [:foundComment]
|
31
|
+
delegating 'parser:foundElementDeclarationWithName:model:', to: :on_element_declaration, parameters: [:foundElementDeclarationWithName, :model]
|
32
|
+
delegating 'parser:foundExternalEntityDeclarationWithName:publicID:systemID:', to: :on_external_entity_declaration, parameters: [:foundExternalEntityDeclarationWithName, :publicID, :systemID]
|
33
|
+
delegating 'parser:foundIgnorableWhitespace:', to: :on_ignorable_whitespace, parameters: [:foundIgnorableWhitespace]
|
34
|
+
delegating 'parser:foundInternalEntityDeclarationWithName:value:', to: :on_internal_entity_declaration, parameters: [:foundInternalEntityDeclarationWithName, :value]
|
35
|
+
delegating 'parser:foundNotationDeclarationWithName:publicID:systemID:', to: :on_notation_declaration, parameters: [:foundNotationDeclarationWithName, :data]
|
36
|
+
delegating 'parser:foundProcessingInstructionWithTarget:data:', to: :on_processing_instruction, parameters: [:foundProcessingInstructionWithTarget, :data]
|
37
|
+
delegating 'parser:foundUnparsedEntityDeclarationWithName:publicID:systemID:notationName:', to: :on_unparsed_entity_declaration, parameters: [:foundUnparsedEntityDeclarationWithName, :publicID, :systemID, :notationName]
|
38
|
+
|
39
|
+
delegating 'parser:resolveExternalEntityName:systemID:', to: :resolve_external_entity_name, parameters: [:resolveExternalEntityName, :systemID]
|
40
|
+
|
41
|
+
delegating 'parser:parseErrorOccurred:', to: :on_parse_error, parameters: [:parseErrorOccurred]
|
42
|
+
delegating 'parser:validationErrorOccurred:', to: :on_validation_error, parameters: [:validationErrorOccurred]
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
HotCocoa::Mappings.map movie: QTMovie do
|
2
|
+
|
3
|
+
def alloc_with_options options
|
4
|
+
if options.has_key? :file
|
5
|
+
QTMovie.movieWithFile options.delete(:file), error:options.delete(:error)
|
6
|
+
|
7
|
+
elsif options.has_key? :url
|
8
|
+
QTMovie.movieWithURL NSURL.URLWithString(options.delete :url), error:options.delete(:error)
|
9
|
+
|
10
|
+
else
|
11
|
+
raise 'Can only allocate a movie from a file or a url'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
HotCocoa::Mappings.map movie_view: QTMovieView do
|
2
|
+
|
3
|
+
defaults layout: {}, frame: CGRectZero
|
4
|
+
|
5
|
+
def init_with_options movie_view, options
|
6
|
+
movie_view.initWithFrame(options.delete :frame)
|
7
|
+
end
|
8
|
+
|
9
|
+
custom_methods do
|
10
|
+
def controller_visible= value
|
11
|
+
setControllerVisible value
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# @todo Change this method to use varargs in the future when we
|
16
|
+
# start deprecating things
|
17
|
+
def controller_buttons= buttons
|
18
|
+
setBackButtonVisible buttons.include? :back
|
19
|
+
setCustomButtonVisible buttons.include? :custom
|
20
|
+
setHotSpotButtonVisible buttons.include? :hot_spot
|
21
|
+
setStepButtonsVisible buttons.include? :step
|
22
|
+
setTranslateButtonVisible buttons.include? :translate
|
23
|
+
setVolumeButtonVisible buttons.include? :volume
|
24
|
+
setZoomButtonsVisible buttons.include? :zoom
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
HotCocoa::Mappings.map web_view: WebView do
|
2
|
+
|
3
|
+
defaults layout: {}, frame: CGRectZero
|
4
|
+
|
5
|
+
def init_with_options web_view, options
|
6
|
+
web_view.initWithFrame options.delete :frame
|
7
|
+
end
|
8
|
+
|
9
|
+
custom_methods do
|
10
|
+
def url= url
|
11
|
+
url = NSURL.URLWithString(url) if url.kind_of? String
|
12
|
+
mainFrame.loadRequest NSURLRequest.requestWithURL url
|
13
|
+
end
|
14
|
+
|
15
|
+
def auto_size
|
16
|
+
setAutoresizingMask(NSViewHeightSizable|NSViewWidthSizable)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/hotcocoa/mappings.rb
CHANGED
@@ -1,115 +1,61 @@
|
|
1
|
-
module HotCocoa
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
mapped_name = options.keys.first
|
40
|
-
mapped_value = options.values.first
|
41
|
-
args = [mapped_name, mapped_value]
|
42
|
-
|
43
|
-
if mapped_value.kind_of?(Class)
|
44
|
-
add_mapping(*args, &block)
|
45
|
-
else
|
46
|
-
if framework.nil? || loaded_framework?(framework)
|
47
|
-
add_constant_mapping(*args, &block)
|
48
|
-
else
|
49
|
-
on_framework(framework) do
|
50
|
-
add_constant_mapping(*args, &block)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Registers +mapped_name+ as a Mapper#builder_method for the given
|
57
|
-
# +mapped_value+. The +block+ is used as the Mapper#builder_method's body.
|
58
|
-
def self.add_mapping(mapped_name, mapped_value, &block)
|
59
|
-
m = Mapper.map_instances_of(mapped_value, mapped_name, &block)
|
60
|
-
mappings[m.builder_method] = m
|
61
|
-
end
|
62
|
-
|
63
|
-
# Registers +mapped_name+ as a Mapper#builder_method for the given
|
64
|
-
# +constant+ string which will be looked up. The +block+ is used as the
|
65
|
-
# Mapper#builder_method's body.
|
66
|
-
def self.add_constant_mapping(mapped_name, constant, &block)
|
67
|
-
add_mapping(mapped_name, Object.full_const_get(constant), &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Returns the Hash of mappings.
|
71
|
-
def self.mappings
|
72
|
-
@mappings ||= {}
|
73
|
-
end
|
74
|
-
|
75
|
-
# Registers a callback for after the specified framework has been loaded.
|
76
|
-
def self.on_framework(name, &block)
|
77
|
-
(frameworks[name.to_s] ||= []) << block
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns the Hash of mapped frameworks.
|
81
|
-
def self.frameworks
|
82
|
-
@frameworks ||= {}
|
83
|
-
end
|
84
|
-
|
85
|
-
# Returns the Set of loaded frameworks.
|
86
|
-
def self.loaded_frameworks
|
87
|
-
@loaded_frameworks ||= Set.new
|
88
|
-
end
|
89
|
-
|
90
|
-
# Registers a given framework as being loaded.
|
91
|
-
def self.framework_loaded
|
92
|
-
frameworks.keys.each do |key|
|
93
|
-
if loaded_framework?(key)
|
94
|
-
frameworks[key].each do |mapper|
|
95
|
-
mapper.call
|
96
|
-
end
|
97
|
-
frameworks.delete(key)
|
98
|
-
end
|
1
|
+
module HotCocoa::Mappings
|
2
|
+
# needs to be initialized
|
3
|
+
@mappings = {}
|
4
|
+
|
5
|
+
##
|
6
|
+
# This is a hack to work around a MacRuby issue with compiled files.
|
7
|
+
#
|
8
|
+
# Return the absolute path to `lib/hotcocoa`.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
file = $LOADED_FEATURES.find { |file| file.match /hotcocoa\/mappings\.rbo?$/ }
|
12
|
+
@path = File.expand_path(File.join(File.dirname(file), 'mappings'))
|
13
|
+
end
|
14
|
+
|
15
|
+
class << HotCocoa::Mappings
|
16
|
+
|
17
|
+
##
|
18
|
+
# The cache of mappers for available mappings.
|
19
|
+
#
|
20
|
+
# @return [Hash{Symbol=>HotCocoa::Mappings::Mapper}]
|
21
|
+
attr_reader :mappings
|
22
|
+
|
23
|
+
##
|
24
|
+
# Load mappings for every loaded framework.
|
25
|
+
def reload
|
26
|
+
$LOADED_FRAMEWORKS.each do |framework| load framework end
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Load mappings for a given framework.
|
31
|
+
#
|
32
|
+
# @param [String] framework
|
33
|
+
def load framework
|
34
|
+
framework = framework.downcase
|
35
|
+
dir = File.join(@path, framework)
|
36
|
+
if Dir.exists? dir
|
37
|
+
Dir.glob(File.join(dir, '**/*.rb')).each do |mapping|
|
38
|
+
require mapping.chomp! '.rb'
|
99
39
|
end
|
100
40
|
end
|
101
|
-
|
102
|
-
# Returns whether or not the framework has been loaded yet.
|
103
|
-
def self.loaded_framework?(name)
|
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)
|
111
|
-
end
|
112
|
-
|
113
41
|
end
|
114
|
-
|
42
|
+
|
43
|
+
##
|
44
|
+
# Create a new mapping by registering `mapped_name` as a builder
|
45
|
+
# method for `mapped_class`.
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
#
|
49
|
+
# HotCocoa::Mappings.map( window: NSWindow ) do
|
50
|
+
# # define your mapping
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# @param [Symbol] mapped_name
|
54
|
+
# @param [Class] mapped_class
|
55
|
+
def map name, &block
|
56
|
+
mapped_name, mapped_class = name.first
|
57
|
+
mappings[mapped_name] =
|
58
|
+
HotCocoa::Mappings::Mapper.map_instances_of mapped_class, mapped_name, &block
|
59
|
+
end
|
60
|
+
|
115
61
|
end
|