[macruby-changes] [371] MacRuby/trunk/lib
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 10 20:12:46 PDT 2008
Revision: 371
http://trac.macosforge.org/projects/ruby/changeset/371
Author: rich at infoether.com
Date: 2008-07-10 20:12:46 -0700 (Thu, 10 Jul 2008)
Log Message:
-----------
refactored the Mappings to enable mapping classes and instances and use that for Behaviors to add methods to a class (rather that instances)
Modified Paths:
--------------
MacRuby/trunk/lib/hotcocoa/mapper.rb
MacRuby/trunk/lib/hotcocoa/mappings.rb
MacRuby/trunk/lib/hotcocoa.rb
Added Paths:
-----------
MacRuby/trunk/lib/hotcocoa/behaviors.rb
Added: MacRuby/trunk/lib/hotcocoa/behaviors.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/behaviors.rb (rev 0)
+++ MacRuby/trunk/lib/hotcocoa/behaviors.rb 2008-07-11 03:12:46 UTC (rev 371)
@@ -0,0 +1,7 @@
+module HotCocoa
+ module Behaviors
+ def Behaviors.included(klass)
+ Mapper.map_class(klass)
+ end
+ end
+end
\ No newline at end of file
Modified: MacRuby/trunk/lib/hotcocoa/mapper.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-07-11 03:11:46 UTC (rev 370)
+++ MacRuby/trunk/lib/hotcocoa/mapper.rb 2008-07-11 03:12:46 UTC (rev 371)
@@ -4,8 +4,25 @@
attr_reader :control_class, :builder_method, :control_module
- def initialize(builder_method, control_class, &block)
- @control_class = control_class
+ def self.map_class(klass)
+ new(klass).include_in_class
+ end
+
+ def self.map_instances_of(klass, builder_method, &block)
+ new(klass).map_method(builder_method, &block)
+ end
+
+ def initialize(klass)
+ @control_class = klass
+ end
+
+ def include_in_class
+ @extension_method = :include
+ customize(@control_class)
+ end
+
+ def map_method(builder_method, &block)
+ @extension_method = :extend
@builder_method = builder_method
mod = (class << self; self; end)
mod.extend MappingMethods
@@ -17,7 +34,7 @@
guid = args.length == 1 ? nil : args[0]
map = inst.remap_constants(map)
default_empty_rect_used = (map[:frame].__id__ == DefaultEmptyRect.__id__)
- control = inst.respond_to?(:init_with_options) ? inst.init_with_options(control_class.alloc, map) : inst.alloc_with_options(map)
+ control = inst.respond_to?(:init_with_options) ? inst.init_with_options(inst.control_class.alloc, map) : inst.alloc_with_options(map)
Views[guid] = control if guid
inst.customize(control)
map.each do |key, value|
@@ -39,6 +56,7 @@
end
control
end
+ self
end
def inherited_constants
@@ -75,7 +93,7 @@
def customize(control)
inherited_custom_methods.each do |custom_methods|
- control.extend(custom_methods)
+ control.send(@extension_method, custom_methods)
end
decorate_with_delegate_methods(control)
end
@@ -92,7 +110,7 @@
end
}
end
- control.extend(delegate_module)
+ control.send(@extension_method, delegate_module)
end
def remap_constants(tags)
Modified: MacRuby/trunk/lib/hotcocoa/mappings.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/mappings.rb 2008-07-11 03:11:46 UTC (rev 370)
+++ MacRuby/trunk/lib/hotcocoa/mappings.rb 2008-07-11 03:12:46 UTC (rev 371)
@@ -14,11 +14,11 @@
mapped_name = options.keys.first
mapped_value = options.values.first
if framework.nil? || Object.const_defined?(mapped_value)
- m = Mapper.new(mapped_name, Object.const_get(mapped_value), &block)
+ m = Mapper.map_instances_of(Object.const_get(mapped_value), mapped_name, &block)
mappings[m.builder_method] = m
else
on_framework(framework) do
- m = Mapper.new(mapped_name, Object.const_get(mapped_value), &block)
+ m = Mapper.map_instances_of(Object.const_get(mapped_value), mapped_name, &block)
mappings[m.builder_method] = m
end
end
Modified: MacRuby/trunk/lib/hotcocoa.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa.rb 2008-07-11 03:11:46 UTC (rev 370)
+++ MacRuby/trunk/lib/hotcocoa.rb 2008-07-11 03:12:46 UTC (rev 371)
@@ -7,6 +7,7 @@
end
require 'hotcocoa/mappings'
+require 'hotcocoa/behaviors'
require 'hotcocoa/mapping_methods'
require 'hotcocoa/mapper'
require 'hotcocoa/layout_view'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080710/8a94a837/attachment-0001.html
More information about the macruby-changes
mailing list