sugarcube 3.3.4 → 3.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f67b205769f1f470e8b590eb8b52767cd56a5b8
4
- data.tar.gz: 2f24635340a8c3f5e22c73fe427b4ab6b2dfbe28
3
+ metadata.gz: 4de89aabaaf8a83810ab069bf1a29577102fa482
4
+ data.tar.gz: 725ac56efa88b23dd73d1dd6ea3995d0f0ea6555
5
5
  SHA512:
6
- metadata.gz: b7db2394ee9acfd81c91048a737dcc2e4b2bbcc523979aadb75698f98c998ae6cbe63e2212663175bb5b55b516d7153959299b4cacc3c493e96979a6f8943c67
7
- data.tar.gz: 11a4567ddff9a7c70b0fec35fc85da9e0ff7ea94ab9591b6202433c497b2125673379ccb9e357d4f3a40535f751b6eb78275b7e5fb6caeb8b0773d16b4db7052
6
+ metadata.gz: 957e029dcd2bb1dcb0f95e4f7da3b23ba2c159c8b6d8c2edccd8b54511ef709f23bc5c79ca2db304b697ef8ba0236437c7c0128dac65f6e77039ea5b0208b0bc
7
+ data.tar.gz: 046cec67dfe8b834fa135332b9d12160e0fa4e105def2def608795b5a957793ffb4aa12a96d8f71536267e0118d7f46318daf69e2a78c6dd62fa0cd85eaadc86
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  SugarCube
2
2
  =========
3
3
 
4
+ [![Join the chat at https://gitter.im/rubymotion/sugarcube](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rubymotion/sugarcube?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
+
4
6
  [![Build Status](https://travis-ci.org/rubymotion/sugarcube.svg?branch=master)](https://travis-ci.org/rubymotion/sugarcube)
5
7
  [![Version](https://badge.fury.io/rb/sugarcube.svg)](https://rubygems.org/gems/sugarcube)
6
8
 
@@ -701,7 +703,7 @@ end
701
703
  # a little more complex - the cancel button should be first, and the block will
702
704
  # receive a string and an index
703
705
  UIAlertView.alert('This is happening, OK?',
704
- message: 'Don't worry, it'll be fine.',
706
+ message: 'Don\'t worry, it\'ll be fine.',
705
707
  buttons: ['Nevermind', 'OK'],
706
708
  ) do |button, button_index|
707
709
  if button == 'OK' # or: button_index == 1
@@ -772,9 +774,9 @@ UIActionSheet.alert('This is happening, OK?', buttons: ['Cancel', 'Kill it!', 'U
772
774
  end
773
775
 
774
776
  # skip cancel and destructive buttons:
775
- UIActionSheet.alert('Should I?', buttons: [nil, nil, 'OK', 'Nevermind']) [ |pressed|
777
+ UIActionSheet.alert('Should I?', buttons: [nil, nil, 'OK', 'Nevermind']) { |pressed|
776
778
  self.do_it if pressed == 'OK'
777
- ]
779
+ }
778
780
 
779
781
  UIActionSheet.alert 'I mean, is this cool?', buttons: ['Nah', 'With fire!', 'Sure', 'whatever'],
780
782
  cancel: proc { self.cancel },
@@ -15,10 +15,10 @@ class NSString
15
15
  end
16
16
 
17
17
  def app_support_path
18
- @@sugarcube_app_suppert ||= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true)[0]
19
- return self if self.hasPrefix(@@sugarcube_app_suppert)
18
+ @@sugarcube_app_support ||= NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true)[0]
19
+ return self if self.hasPrefix(@@sugarcube_app_support)
20
20
 
21
- @@sugarcube_app_suppert.stringByAppendingPathComponent(self)
21
+ @@sugarcube_app_support.stringByAppendingPathComponent(self)
22
22
  end
23
23
 
24
24
  def temporary_path
@@ -2,13 +2,8 @@ class NSData
2
2
 
3
3
  # converts NSData into an NSString using any encoding, default is UTF8
4
4
  # @return [NSString]
5
- def nsstring(encoding=nil)
6
- if encoding
7
- return NSString.stringWithCString(self.bytes, encoding: encoding)
8
- else
9
-
10
- return NSString.stringWithUTF8String(self)
11
- end
5
+ def nsstring(encoding=NSUTF8StringEncoding)
6
+ return NSString.alloc.initWithData(self, encoding: encoding)
12
7
  end
13
8
 
14
9
  def write_to(path_or_url, atomically=true)
@@ -43,40 +43,87 @@ class NSDate
43
43
  date_formatter.stringFromDate(self)
44
44
  end
45
45
 
46
- # Pass in a format string or a Symbol. The Symbol must exist in
46
+ # Pass in a format string or a Symbol. If you use a Symbol, it must exist in
47
47
  # NSDate::SugarCubeFormats.
48
48
  #
49
+ # This method accepts some options:
50
+ #
51
+ # timezone: String or NSTimeZone. Strings get converted using NSTimeZone.timeZoneWithName
52
+ # unicode: if true, this method will use Unicode date format (TR35) instead of converting to a locale specific format
53
+ # locale: Strings or NSLocale. Strings get converted using NSLocale.localeWithLocaleIdentifier
54
+ #
49
55
  # See
50
56
  # <https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1>
51
57
  # and
52
58
  # <http://www.unicode.org/reports/tr35/tr35-19.html#Date_Field_Symbol_Table>
53
59
  # for more information about date format strings.
54
60
  def string_with_format(format, options={})
55
- locale = options[:locale] || NSLocale.currentLocale
56
61
  timezone = options[:timezone] || NSTimeZone.defaultTimeZone
62
+ if timezone.is_a?(NSString)
63
+ timezone = NSTimeZone.timeZoneWithName(timezone)
64
+ end
57
65
 
58
66
  if format.is_a?(Symbol)
59
- formatters = SugarCubeFormats[format]
60
- raise "No format found for #{format.inspect}" unless formatters
61
- locale = NSLocale.localeWithLocaleIdentifier "en_US"
62
- retval = ''
63
- formatters.each do |formatter|
64
- case formatter
65
- when Symbol
66
- retval << string_with_format(formatter.to_s, locale:locale, timezone:timezone)
67
- when String
68
- retval << formatter
67
+ return _string_with_sugarcube_format(format, timezone)
68
+ else
69
+ unicode = options[:unicode]
70
+ if unicode
71
+ return _string_with_unicode_format(format, timezone)
72
+ else
73
+ locale = options[:locale] || NSLocale.currentLocale
74
+ if locale.is_a?(NSString)
75
+ locale = NSLocale.localeWithLocaleIdentifier(locale)
69
76
  end
77
+
78
+ return _string_with_nsdate_format(format, timezone, locale)
70
79
  end
71
- return retval
72
- else
73
- format_template = NSDateFormatter.dateFormatFromTemplate(format, options:0,
74
- locale:locale)
80
+ end
81
+ end
82
+
83
+ def _string_with_sugarcube_format(format, timezone)
84
+ formatters = SugarCubeFormats[format]
85
+ raise "No format found for #{format.inspect}" unless formatters
86
+ locale = NSLocale.localeWithLocaleIdentifier('en_US')
87
+ retval = ''
88
+ formatters.each do |formatter|
89
+ case formatter
90
+ when Symbol
91
+ retval << string_with_format(formatter.to_s, locale: locale, timezone: timezone)
92
+ when String
93
+ retval << formatter
94
+ end
95
+ end
96
+ return retval
97
+ end
98
+
99
+ def _string_with_nsdate_format(format, timezone, locale)
100
+ locale_name = locale.localeIdentifier
101
+ @@sugarcube_date_formatters ||= {}
102
+ @@sugarcube_date_formatters[locale_name] ||= {}
103
+ @@sugarcube_date_formatters[locale_name][format] ||= begin
104
+ format_template = NSDateFormatter.dateFormatFromTemplate(format, options: 0,
105
+ locale: locale)
75
106
  date_formatter = NSDateFormatter.new
76
107
  date_formatter.setDateFormat(format_template)
77
- date_formatter.setTimeZone(timezone)
78
- return date_formatter.stringFromDate(self)
108
+ date_formatter
109
+ end
110
+
111
+ date_formatter = @@sugarcube_date_formatters[locale_name][format]
112
+ date_formatter.setTimeZone(timezone)
113
+ return date_formatter.stringFromDate(self)
114
+ end
115
+
116
+ def _string_with_unicode_format(format, timezone)
117
+ @@sugarcube_unicode_formatters ||= {}
118
+ @@sugarcube_unicode_formatters[format] ||= begin
119
+ date_formatter = NSDateFormatter.new
120
+ date_formatter.setDateFormat(format)
121
+ date_formatter
79
122
  end
123
+
124
+ date_formatter = @@sugarcube_unicode_formatters[format]
125
+ date_formatter.setTimeZone(timezone)
126
+ return date_formatter.stringFromDate(self)
80
127
  end
81
128
 
82
129
  def upto(last_date, delta={days: 1}, &block)
@@ -1,6 +1,6 @@
1
1
  class NSArray
2
2
 
3
- # [160, 210, 242].uicolor => 0xA0D2F2.uicolor
3
+ # [160, 210, 242].nscolor => 0xA0D2F2.nscolor
4
4
  def nscolor(alpha=1.0)
5
5
  red = self[0] / 255.0
6
6
  green = self[1] / 255.0
@@ -16,7 +16,7 @@ class NSArray
16
16
  end
17
17
 
18
18
  def skcolor(alpha=nil)
19
- uicolor(alpha)
19
+ nscolor(alpha)
20
20
  end
21
21
 
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '3.3.4'
2
+ Version = '3.3.5'
3
3
  end
@@ -10,7 +10,7 @@ describe "NSData" do
10
10
  NSString.stringWithUTF8String("t\u0113st".nsdata).should == "t\u0113st"
11
11
  end
12
12
 
13
- it "native methods should work - turkey" do
13
+ it "native methods should work - turkish letters" do
14
14
  NSString.stringWithUTF8String("\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb".dataUsingEncoding(NSUTF8StringEncoding)).should == "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb"
15
15
  NSString.stringWithUTF8String("\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb".nsdata).should == "\u00ab\u03c4\u03b1\u0411\u042c\u2113\u03c3\u00bb"
16
16
  end
@@ -90,11 +90,28 @@ describe "NSDate" do
90
90
  end
91
91
 
92
92
  it "should have an NSDate#string_with_format method (1)" do
93
- @date.string_with_format("yyyyMMdd HH:mm:ss").should == '01/02/2013, 12:15:30'
93
+ @date.string_with_format('yyyyMMdd HH:mm:ss').should == '01/02/2013, 12:15:30'
94
94
  end
95
95
 
96
96
  it "should have an NSDate#string_with_format method (2)" do
97
- @date.string_with_format("yyyyMMMMd HH:mm:ss").should == 'January 2, 2013, 12:15:30'
97
+ @date.string_with_format('yyyyMMMMd HH:mm:ss').should == 'January 2, 2013, 12:15:30'
98
+ end
99
+
100
+ it "should have an NSDate#string_with_format(unicode: true) method" do
101
+ @date.string_with_format("yyyy-MM-dd 'at' HH:mm", unicode: true).should == '2013-01-02 at 12:15'
102
+ # these formatters get cached, and it's important to test the cache:
103
+ @date.string_with_format("yyyy-MM-dd 'at' HH:mm", unicode: true).should == '2013-01-02 at 12:15'
104
+ end
105
+
106
+ it "should have an NSDate#string_with_format(locale: (France))" do
107
+ locale = NSLocale.localeWithLocaleIdentifier('fr')
108
+ @date.string_with_format('yyyyMMMMd HH:mm:ss', locale: locale).should == '2 January 2013 12:15:30'
109
+ end
110
+
111
+ it "should have an NSDate#string_with_format(locale: 'fr')" do
112
+ @date.string_with_format('yyyyMMMMd HH:mm:ss', locale: 'fr').should == '2 January 2013 12:15:30'
113
+ # these formatters get cached, and it's important to test the cache:
114
+ @date.string_with_format('yyyyMMMMd HH:mm:ss', locale: 'fr').should == '2 January 2013 12:15:30'
98
115
  end
99
116
 
100
117
  it "should have an NSDate#string_with_format method (:iso8601)" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.4
4
+ version: 3.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-03-18 00:00:00.000000000 Z
15
+ date: 2015-05-01 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: |
18
18
  == Description