[macruby-changes] [748] MacRuby/trunk/lib/hotcocoa/attributed_string.rb

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 20 11:36:51 PST 2008


Revision: 748
          http://trac.macosforge.org/projects/ruby/changeset/748
Author:   ben at tanjero.com
Date:     2008-11-20 11:36:51 -0800 (Thu, 20 Nov 2008)
Log Message:
-----------
Moved classes into the HotCocoa namespace.

Modified Paths:
--------------
    MacRuby/trunk/lib/hotcocoa/attributed_string.rb

Modified: MacRuby/trunk/lib/hotcocoa/attributed_string.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/attributed_string.rb	2008-11-20 19:36:47 UTC (rev 747)
+++ MacRuby/trunk/lib/hotcocoa/attributed_string.rb	2008-11-20 19:36:51 UTC (rev 748)
@@ -1,49 +1,51 @@
-class String
-    def with_attributes(attributes = {})
-	NSMutableAttributedString.alloc.initWithString(self, :attributes => attributes)
-    end
-end
+module HotCocoa
+    class NSRangedProxyAttributeHash
+	def initialize(proxy)
+	    @proxy = proxy
+	end
 
-class Range
-    def to_NSRange(max = nil)
-	if last == -1 and max
-	    last = max
+	def [](k)
+	    @proxy.string.attribute(k, atIndex:@proxy.range.first, effectiveRange:nil)
 	end
-	NSRange.new(first, last - first + 1)
-    end
-end
 
-class NSRangedProxyAttributeHash < Hash
-    def initialize(proxy)
-	@proxy = proxy
-    end
+	def []=(k,v)
+	    @proxy.string.removeAttribute(k, range:@proxy.range.to_NSRange(@proxy.string.length - 1))
+	    @proxy.string.addAttribute(k, value:v, range:@proxy.range.to_NSRange(@proxy.string.length - 1))
+	end
 
-    def [](k)
-	@proxy.string.attribute(k, atIndex:@proxy.range.first, effectiveRange:nil)
+	def <<(attributes)
+	    attributes.each_pair do |k, v|
+		self[k] = v
+	    end
+	end
+	alias :merge :<<
     end
 
-    def []=(k,v)
-	@proxy.string.removeAttribute(k, range:@proxy.range.to_NSRange(@proxy.string.length - 1))
-	@proxy.string.addAttribute(k, value:v, range:@proxy.range.to_NSRange(@proxy.string.length - 1))
-    end
+    class NSRangedProxyAttributedString
+	attr_reader :string, :range
+	def initialize(string, range)
+	    @string = string
+	    @range = range
+	end
 
-    def <<(attributes)
-	attributes.each_pair do |k, v|
-	    self[k] = v
+	def attributes
+	    NSRangedProxyAttributeHash.new(self)
 	end
     end
-    alias :merge :<<
 end
 
-class NSRangedProxyAttributedString
-    attr_reader :string, :range
-    def initialize(string, range)
-	@string = string
-	@range = range
+class String
+    def with_attributes(attributes = {})
+	NSMutableAttributedString.alloc.initWithString(self, :attributes => attributes)
     end
+end
 
-    def attributes
-	NSRangedProxyAttributeHash.new(self)
+class Range
+    def to_NSRange(max = nil)
+	if last == -1 and max
+	    last = max
+	end
+	NSRange.new(first, last - first + 1)
     end
 end
 
@@ -62,11 +64,11 @@
     end
 
     def attributes
-	NSRangedProxyAttributedString.new(self, 0..-1).attributes
+	HotCocoa::NSRangedProxyAttributedString.new(self, 0..-1).attributes
     end
 
     def [](r)
-	NSRangedProxyAttributedString.new(self, r)
+	HotCocoa::NSRangedProxyAttributedString.new(self, r)
     end
 
     def []=(r, s)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081120/f83c2f7b/attachment.html>


More information about the macruby-changes mailing list