sugarcube 3.1.1 → 3.2.0

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: e03ee8ded13781481465fce15d246ebe5cf49c63
4
- data.tar.gz: 637174af1e8c26d5b1d8ecd9fccd5cf5591346aa
3
+ metadata.gz: 32effb6255d9b0220098e834105e2fd8f834dac7
4
+ data.tar.gz: 2cf5ff2af3a74665f6ac6504ea6e3e87dc771ab5
5
5
  SHA512:
6
- metadata.gz: 2c4a3d873454213586425aee5ebe4827ecab047462c6b7e591073857b0e5a3fbbe896fb1feca2b6f9b63fa167139e899ce342e333f0ca22605cd53b278e5cc9e
7
- data.tar.gz: 51a6bee7e45b0b98a659ad6472f0d7d96f203881268b950b428a1109b70e07f32dc7bda08bbf99d0ba1ad3038cd60d26789e52559554a505b9617117d8394c69
6
+ metadata.gz: e22726d90c3d3b60032ff9bb6641c6bcd525a9e6501038a62ca3e3f39bbb97090aa7aa1dd92d604309c2240b4d24dffcadc42951440b3b09b52ed7650f74b5e7
7
+ data.tar.gz: 20412c7a032a5ab3a5cdb90e5018214300b4e6d3cb30580ae5c992393cde2267265fb51e67ef17ee45e51ba62c89daaf2cc77c56553684cfcef5f37c4d7b90f7
data/README.md CHANGED
@@ -1268,6 +1268,13 @@ issues with missing constants).
1268
1268
  # And there's where it gets FUN:
1269
1269
  ('This'.italic + ' is going to be ' + 'FUN'.bold).underline
1270
1270
 
1271
+ # and if you need to join a bunch of strings, there's a helper for that!
1272
+ ['This', 'is'.bold, 'handy!'].join_attrd(' ')
1273
+ # or join plain strings with an attributed string:
1274
+ ['a', 'b', 'c'].join_attrd('-'.bold)
1275
+ # join_attrd will *always* return an NSAttributedString
1276
+ ['a', 'b', 'c'].join_attrd(' ') # == NSAttributedString ('a b c')
1277
+
1271
1278
  # You can even generate attributed text from html! This feature uses the
1272
1279
  # NSHTMLTextDocumentType option to convert the html to NSAttributedString
1273
1280
  'Why on <b>earth<b> would you want to do <em>that</em>?'.attributed_html
@@ -148,3 +148,17 @@ class NSMutableAttributedString
148
148
  end
149
149
 
150
150
  end
151
+
152
+ class Array
153
+
154
+ # Detects if any part of an array is an NSAttributedString and joins them
155
+ # Otherwise, just joins the array.
156
+ def join_attrd(connector=nil)
157
+ joining = "".attrd
158
+ each_with_index do |attrd_str, index|
159
+ joining << connector if connector && index > 0
160
+ joining << attrd_str
161
+ end
162
+ joining
163
+ end
164
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '3.1.1'
2
+ Version = '3.2.0'
3
3
  end
@@ -54,7 +54,51 @@ describe 'NSAttributeString' do
54
54
  "test\n ".attrd.strip.should == 'test'.attrd
55
55
  " \n test".attrd.strip.should == 'test'.attrd
56
56
  end
57
+ end
58
+
59
+ describe "should allow joining an array of attributed strings" do
60
+ it "should turn an array of strings into an attributed string" do
61
+ joined = ['a', 'b', 'c'].join_attrd
62
+ joined.is_a?(NSAttributedString).should == true
63
+ joined.is_a?(NSString).should == false
64
+ joined.isEqualToAttributedString('abc'.attrd).should == true
65
+
66
+ joined2 = ['a', 'b', 'c'].join_attrd('-')
67
+ joined2.isEqualToAttributedString('a-b-c'.attrd).should == true
68
+ end
69
+
70
+ it "should join attributed strings" do
71
+ joined = ['a'.attrd, 'b'.attrd, 'c'.attrd].join_attrd
72
+ joined.is_a?(NSAttributedString).should == true
73
+ end
74
+
75
+ it "should create an attributed string even when only one item is attributed" do
76
+ joined = ['a', 'b', 'c'.attrd].join_attrd
77
+ joined.is_a?(NSAttributedString).should == true
78
+
79
+ joined2 = ['a', 'b'.attrd, 'c'].join_attrd
80
+ joined2.is_a?(NSAttributedString).should == true
81
+ end
82
+
83
+ it "should preserve attributes when joining" do
84
+ joined = ['a'.italic, 'b'.bold, 'c'.underline].join_attrd
85
+ joined.isEqualToAttributedString('a'.italic + 'b'.bold + 'c'.underline).should == true
86
+ end
87
+
88
+ it "should join with a string" do
89
+ joined = ['a'.bold, 'b', 'c'].join_attrd('-')
90
+ joined.isEqualToAttributedString('a'.bold + '-' + 'b' + '-' + 'c').should == true
91
+ end
92
+
93
+ it "should join with an attributed string" do
94
+ joined = ['a'.bold, 'b', 'c'].join_attrd('-'.bold)
95
+ joined.isEqualToAttributedString('a'.bold + '-'.bold + 'b' + '-'.bold + 'c').should == true
96
+ end
57
97
 
98
+ it "should join an array of strings with an attributed connector" do
99
+ joined = ['a', 'b', 'c'].join_attrd('-'.bold)
100
+ joined.isEqualToAttributedString('a'.attrd + '-'.bold + 'b' + '-'.bold + 'c').should == true
101
+ end
58
102
  end
59
103
 
60
104
  end
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
8
8
  - Katsuyoshi Ito
9
9
  - Thom Parkin
10
10
  - Michael Erasmus
11
+ - Mark Rickert
11
12
  autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2015-01-25 00:00:00.000000000 Z
15
+ date: 2015-01-30 00:00:00.000000000 Z
15
16
  dependencies: []
16
17
  description: |
17
18
  == Description
@@ -27,6 +28,7 @@ description: |
27
28
  idiomatic: `view << subview`.
28
29
  email:
29
30
  - colin@hipbyte.com
31
+ - mjar81@gmail.com
30
32
  executables: []
31
33
  extensions: []
32
34
  extra_rdoc_files: []