sugarcube 2.11.0 → 2.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb +30 -88
- data/lib/ios/sugarcube-attributedstring/nsattributedstring.rb +96 -0
- data/lib/ios/sugarcube-uikit/nsattributedstring.rb +1 -0
- data/lib/osx/sugarcube-appkit/nsfont.rb +5 -0
- data/lib/osx/sugarcube-appkit/symbol.rb +66 -0
- data/lib/osx/sugarcube-attributedstring/nsattributedstring.rb +72 -0
- data/lib/sugarcube-attributedstring.rb +3 -0
- data/lib/version.rb +1 -1
- data/spec/cocoa/nsattributedstring_spec.rb +42 -0
- data/spec/helpers/attributed_string.rb +6 -0
- data/spec/ios/nsattributedstring_spec.rb +32 -51
- data/spec/osx/nsattributedstring_spec.rb +84 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870b646f170334f7679d70d38b1789b261015ebb
|
4
|
+
data.tar.gz: 283c0fe56dc524fe62cea324e853bf4fa8f0ab0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3588d547fc015cde49784ece637def74e9a1d76b0dff4718f6ef9dbd31ebb93c0b8ceecd709213eafb627f3a29b0a6b281e592adc7cd66283c5185c8f95bf8a
|
7
|
+
data.tar.gz: f8d75ef4393ae0daae5e9abd2ae7d615a6b11ac7dde9534a8153ed8b6f4c90c22da882cb6d9e982c14dc8212986795e371f718c348612db86a3ea195e5d994c1
|
data/README.md
CHANGED
@@ -129,7 +129,7 @@ REPL ([wiki][REPL Wiki])
|
|
129
129
|
----
|
130
130
|
|
131
131
|
If you install SugarCube and *only* use the REPL package, you will benefit from
|
132
|
-
some of
|
132
|
+
some of SugarCube's greatest tricks!
|
133
133
|
|
134
134
|
> `require 'sugarcube-repl'`
|
135
135
|
|
@@ -137,9 +137,12 @@ This package is useful during development because it adds methods to the REPL
|
|
137
137
|
that make adjusting and introspecting views much easier. You'll get a lot more
|
138
138
|
done in the REPL with these additions.
|
139
139
|
|
140
|
+
You should NEVER use these methods in your application, because this package is
|
141
|
+
only included in 'development' mode. That means if you hard-code a call to
|
142
|
+
'tree' in your code, that will crash when you go to release your app. YIKES.
|
143
|
+
|
140
144
|
To keep this document lean-and-mean, I've put most of the REPL documentation [in
|
141
|
-
the wiki][REPL Wiki], but a
|
142
|
-
quick overview:
|
145
|
+
the wiki][REPL Wiki], but here's a quick overview:
|
143
146
|
|
144
147
|
* Use the `tree` commands to output your view hierarchy. It can accept a UIView,
|
145
148
|
`UIViewController`, or `CALayer` object as the root object, or it defaults to
|
@@ -1,25 +1,5 @@
|
|
1
1
|
class NSString
|
2
2
|
|
3
|
-
def bold(size=nil)
|
4
|
-
font = :bold.uifont(size)
|
5
|
-
nsattributedstring({NSFontAttributeName => font})
|
6
|
-
end
|
7
|
-
|
8
|
-
def italic(size=nil)
|
9
|
-
font = :italic.uifont(size)
|
10
|
-
nsattributedstring({NSFontAttributeName => font})
|
11
|
-
end
|
12
|
-
|
13
|
-
def monospace(size=nil)
|
14
|
-
font = :monospace.uifont(size)
|
15
|
-
nsattributedstring({NSFontAttributeName => font})
|
16
|
-
end
|
17
|
-
|
18
|
-
def underline(underline_style=nil)
|
19
|
-
underline_style ||= NSUnderlineStyleSingle
|
20
|
-
nsattributedstring({NSUnderlineStyleAttributeName => underline_style})
|
21
|
-
end
|
22
|
-
|
23
3
|
def nsattributedstring(attributes={})
|
24
4
|
NSAttributedString.alloc.initWithString(self, attributes: attributes)
|
25
5
|
end
|
@@ -44,27 +24,27 @@ class NSAttributedString
|
|
44
24
|
|
45
25
|
def sugarcube_nsattributedstring_dummy_method
|
46
26
|
# make sure NSAttributedString constants get compiled
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
27
|
+
NSFontAttributeName
|
28
|
+
NSParagraphStyleAttributeName
|
29
|
+
NSForegroundColorAttributeName
|
30
|
+
NSBackgroundColorAttributeName
|
31
|
+
NSLigatureAttributeName
|
32
|
+
NSKernAttributeName
|
33
|
+
NSStrikethroughStyleAttributeName
|
34
|
+
NSUnderlineStyleAttributeName
|
35
|
+
NSStrokeColorAttributeName
|
36
|
+
NSStrokeWidthAttributeName
|
37
|
+
NSShadowAttributeName
|
38
|
+
NSVerticalGlyphFormAttributeName
|
59
39
|
# new iOS 7 text effects
|
60
|
-
|
61
|
-
|
40
|
+
NSTextEffectAttributeName
|
41
|
+
NSTextEffectLetterpressStyle
|
62
42
|
# make sure alignments get compiled
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
43
|
+
NSLeftTextAlignment
|
44
|
+
NSRightTextAlignment
|
45
|
+
NSCenterTextAlignment
|
46
|
+
NSJustifiedTextAlignment
|
47
|
+
NSNaturalTextAlignment
|
68
48
|
nil
|
69
49
|
end
|
70
50
|
|
@@ -72,72 +52,32 @@ class NSAttributedString
|
|
72
52
|
string # this is the name of the Cocoa method to return an NSString
|
73
53
|
end
|
74
54
|
|
75
|
-
def bold(size=nil)
|
76
|
-
font = :bold.uifont(size)
|
77
|
-
self.font(font)
|
78
|
-
end
|
79
|
-
|
80
|
-
def italic(size=nil)
|
81
|
-
font = :italic.uifont(size)
|
82
|
-
self.font(font)
|
83
|
-
end
|
84
|
-
|
85
|
-
def underline
|
86
|
-
underline_style(NSUnderlineStyleSingle)
|
87
|
-
end
|
88
|
-
|
89
|
-
def font(value)
|
90
|
-
with_attributes({NSFontAttributeName => value.uifont})
|
91
|
-
end
|
92
|
-
|
93
55
|
def paragraph_style(value)
|
94
|
-
with_attributes({NSParagraphStyleAttributeName => value})
|
95
|
-
end
|
96
|
-
|
97
|
-
def foreground_color(value)
|
98
|
-
with_attributes({NSForegroundColorAttributeName => value.uicolor})
|
56
|
+
with_attributes({ NSParagraphStyleAttributeName => value })
|
99
57
|
end
|
100
|
-
alias color foreground_color
|
101
|
-
|
102
|
-
def underline_style(value)
|
103
|
-
with_attributes({NSUnderlineStyleAttributeName => value})
|
104
|
-
end
|
105
|
-
|
106
|
-
def background_color(value)
|
107
|
-
with_attributes({NSBackgroundColorAttributeName => value.uicolor})
|
108
|
-
end
|
109
|
-
alias bg_color background_color
|
110
58
|
|
111
59
|
def ligature(value)
|
112
|
-
with_attributes({NSLigatureAttributeName => value})
|
60
|
+
with_attributes({ NSLigatureAttributeName => value })
|
113
61
|
end
|
114
62
|
|
115
63
|
def kern(value)
|
116
|
-
with_attributes({NSKernAttributeName => value})
|
64
|
+
with_attributes({ NSKernAttributeName => value })
|
117
65
|
end
|
118
66
|
|
119
67
|
def stroke_width(value)
|
120
|
-
with_attributes({NSStrokeWidthAttributeName => value})
|
121
|
-
end
|
122
|
-
|
123
|
-
def stroke_color(value)
|
124
|
-
with_attributes({NSStrokeColorAttributeName => value.uicolor})
|
68
|
+
with_attributes({ NSStrokeWidthAttributeName => value })
|
125
69
|
end
|
126
70
|
|
127
71
|
def strikethrough_style(value)
|
128
|
-
with_attributes({NSStrikethroughStyleAttributeName => value})
|
72
|
+
with_attributes({ NSStrikethroughStyleAttributeName => value })
|
129
73
|
end
|
130
74
|
|
131
75
|
def shadow(value)
|
132
|
-
with_attributes({NSShadowAttributeName => value})
|
76
|
+
with_attributes({ NSShadowAttributeName => value })
|
133
77
|
end
|
134
78
|
|
135
79
|
def vertical_glyph_form(value)
|
136
|
-
with_attributes({NSVerticalGlyphFormAttributeName => value})
|
137
|
-
end
|
138
|
-
|
139
|
-
def letterpress
|
140
|
-
with_attributes({NSTextEffectAttributeName => NSTextEffectLetterpressStyle})
|
80
|
+
with_attributes({ NSVerticalGlyphFormAttributeName => value })
|
141
81
|
end
|
142
82
|
|
143
83
|
def with_attributes(attributes)
|
@@ -159,7 +99,9 @@ class NSAttributedString
|
|
159
99
|
end
|
160
100
|
|
161
101
|
def +(attributedstring)
|
162
|
-
NSMutableAttributedString.alloc.initWithAttributedString(self)
|
102
|
+
string = NSMutableAttributedString.alloc.initWithAttributedString(self)
|
103
|
+
string.appendAttributedString(attributedstring.nsattributedstring)
|
104
|
+
string
|
163
105
|
end
|
164
106
|
|
165
107
|
end
|
@@ -172,7 +114,7 @@ class NSMutableAttributedString
|
|
172
114
|
self
|
173
115
|
end
|
174
116
|
|
175
|
-
def
|
117
|
+
def <<(attributedstring)
|
176
118
|
self.appendAttributedString(attributedstring.nsattributedstring)
|
177
119
|
end
|
178
120
|
|
@@ -0,0 +1,96 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
def bold(size=nil)
|
4
|
+
font = :bold.uifont(size)
|
5
|
+
nsattributedstring({ NSFontAttributeName => font })
|
6
|
+
end
|
7
|
+
|
8
|
+
def italic(size=nil)
|
9
|
+
font = :italic.uifont(size)
|
10
|
+
nsattributedstring({ NSFontAttributeName => font })
|
11
|
+
end
|
12
|
+
|
13
|
+
def monospace(size=nil)
|
14
|
+
font = :monospace.uifont(size)
|
15
|
+
nsattributedstring({ NSFontAttributeName => font })
|
16
|
+
end
|
17
|
+
|
18
|
+
def underline(underline_style=nil)
|
19
|
+
underline_style ||= NSUnderlineStyleSingle
|
20
|
+
nsattributedstring({ NSUnderlineStyleAttributeName => underline_style })
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
class NSAttributedString
|
27
|
+
|
28
|
+
def sugarcube_nsattributedstring_dummy_method
|
29
|
+
KCTCharacterShapeAttributeName
|
30
|
+
KCTFontAttributeName
|
31
|
+
KCTKernAttributeName
|
32
|
+
KCTLigatureAttributeName
|
33
|
+
KCTForegroundColorAttributeName
|
34
|
+
KCTForegroundColorFromContextAttributeName
|
35
|
+
KCTParagraphStyleAttributeName
|
36
|
+
KCTStrokeWidthAttributeName
|
37
|
+
KCTStrokeColorAttributeName
|
38
|
+
KCTSuperscriptAttributeName
|
39
|
+
KCTUnderlineColorAttributeName
|
40
|
+
KCTUnderlineStyleAttributeName
|
41
|
+
KCTVerticalFormsAttributeName
|
42
|
+
KCTGlyphInfoAttributeName
|
43
|
+
KCTRunDelegateAttributeName
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def bold(size=nil)
|
48
|
+
font = :bold.uifont(size)
|
49
|
+
self.font(font)
|
50
|
+
end
|
51
|
+
|
52
|
+
def italic(size=nil)
|
53
|
+
font = :italic.uifont(size)
|
54
|
+
self.font(font)
|
55
|
+
end
|
56
|
+
|
57
|
+
def font(value)
|
58
|
+
with_attributes({ NSFontAttributeName => value.uifont })
|
59
|
+
end
|
60
|
+
|
61
|
+
def underline
|
62
|
+
underline_style(NSUnderlineStyleSingle)
|
63
|
+
end
|
64
|
+
|
65
|
+
def underline_style(value)
|
66
|
+
with_attributes({NSUnderlineStyleAttributeName => value})
|
67
|
+
end
|
68
|
+
|
69
|
+
def foreground_color(value)
|
70
|
+
with_attributes({ NSForegroundColorAttributeName => value.uicolor })
|
71
|
+
end
|
72
|
+
alias color foreground_color
|
73
|
+
|
74
|
+
def background_color(value)
|
75
|
+
with_attributes({ NSBackgroundColorAttributeName => value.uicolor })
|
76
|
+
end
|
77
|
+
alias bg_color background_color
|
78
|
+
|
79
|
+
def stroke_color(value)
|
80
|
+
with_attributes({ NSStrokeColorAttributeName => value.uicolor })
|
81
|
+
end
|
82
|
+
|
83
|
+
def superscript(amount=nil)
|
84
|
+
amount ||= 1
|
85
|
+
with_attributes({ KCTSuperscriptAttributeName => amount })
|
86
|
+
end
|
87
|
+
|
88
|
+
def subscript
|
89
|
+
superscript(-1)
|
90
|
+
end
|
91
|
+
|
92
|
+
def letterpress
|
93
|
+
with_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle })
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
=begin
|
2
|
+
Example:
|
3
|
+
|
4
|
+
# fonts
|
5
|
+
:system.nsfont => NSFont.systemFontOfSize(NSFont.systemFontSize)
|
6
|
+
:label.nsfont => NSFont.systemFontOfSize(NSFont.labelFontSize)
|
7
|
+
|
8
|
+
You can extend the defaults by adding entries:
|
9
|
+
|
10
|
+
Symbol.nsfontsize[:big] = 40
|
11
|
+
|
12
|
+
:big.nsfont => NSFont
|
13
|
+
|
14
|
+
=end
|
15
|
+
class Symbol
|
16
|
+
|
17
|
+
def nsfont(size=nil)
|
18
|
+
size ||= NSFont.systemFontSize
|
19
|
+
# system fonts
|
20
|
+
if Symbol.nsfont.has_key? self
|
21
|
+
font = SugarCube.look_in(self, Symbol.nsfont)
|
22
|
+
if size.is_a?(Symbol)
|
23
|
+
size = size.nsfontsize
|
24
|
+
end
|
25
|
+
|
26
|
+
if font.is_a?(Symbol)
|
27
|
+
return NSFont.send(font, size)
|
28
|
+
else
|
29
|
+
return font.nsfont(size)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
if size.is_a?(Symbol)
|
33
|
+
size = size.nsfontsize
|
34
|
+
end
|
35
|
+
return NSFont.systemFontOfSize(size)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def nsfontsize
|
40
|
+
size = SugarCube.look_in(self, Symbol.nsfontsize)
|
41
|
+
if size.is_a?(Symbol)
|
42
|
+
return NSFont.send(size)
|
43
|
+
end
|
44
|
+
return size.to_f
|
45
|
+
end
|
46
|
+
|
47
|
+
class << self
|
48
|
+
attr :nsfont
|
49
|
+
attr :nsfontsize
|
50
|
+
end
|
51
|
+
|
52
|
+
@nsfont = {
|
53
|
+
system: :"systemFontOfSize:",
|
54
|
+
bold: :"boldSystemFontOfSize:",
|
55
|
+
monospace: 'Courier New',
|
56
|
+
}
|
57
|
+
|
58
|
+
@nsfontsize = {
|
59
|
+
label: :labelFontSize,
|
60
|
+
button: :buttonFontSize,
|
61
|
+
small: :smallSystemFontSize,
|
62
|
+
system: :systemFontSize,
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class NSString
|
2
|
+
|
3
|
+
def bold(size=nil)
|
4
|
+
font = :bold.nsfont(size)
|
5
|
+
nsattributedstring({ NSFontAttributeName => font })
|
6
|
+
end
|
7
|
+
|
8
|
+
def monospace(size=nil)
|
9
|
+
font = :monospace.nsfont(size)
|
10
|
+
nsattributedstring({ NSFontAttributeName => font })
|
11
|
+
end
|
12
|
+
|
13
|
+
def underline(underline_style=nil)
|
14
|
+
underline_style ||= NSSingleUnderlineStyle
|
15
|
+
nsattributedstring({ NSUnderlineStyleAttributeName => underline_style })
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
class NSAttributedString
|
22
|
+
|
23
|
+
def sugarcube_nsattributedstring_dummy_method
|
24
|
+
NSSuperscriptAttributeName
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def bold(size=nil)
|
29
|
+
font = :bold.nsfont(size)
|
30
|
+
self.font(font)
|
31
|
+
end
|
32
|
+
|
33
|
+
def font(value)
|
34
|
+
with_attributes({ NSFontAttributeName => value.nsfont })
|
35
|
+
end
|
36
|
+
|
37
|
+
def underline
|
38
|
+
underline_style(NSSingleUnderlineStyle)
|
39
|
+
end
|
40
|
+
|
41
|
+
def underline_style(value)
|
42
|
+
with_attributes({NSUnderlineStyleAttributeName => value})
|
43
|
+
end
|
44
|
+
|
45
|
+
def foreground_color(value)
|
46
|
+
with_attributes({ NSForegroundColorAttributeName => value.nscolor })
|
47
|
+
end
|
48
|
+
alias color foreground_color
|
49
|
+
|
50
|
+
def background_color(value)
|
51
|
+
with_attributes({ NSBackgroundColorAttributeName => value.nscolor })
|
52
|
+
end
|
53
|
+
alias bg_color background_color
|
54
|
+
|
55
|
+
def stroke_color(value)
|
56
|
+
with_attributes({ NSStrokeColorAttributeName => value.nscolor })
|
57
|
+
end
|
58
|
+
|
59
|
+
def superscript(amount=nil)
|
60
|
+
amount ||= 1
|
61
|
+
with_attributes({ NSSuperscriptAttributeName => amount })
|
62
|
+
end
|
63
|
+
|
64
|
+
def subscript
|
65
|
+
superscript(-1)
|
66
|
+
end
|
67
|
+
|
68
|
+
def letterpress
|
69
|
+
with_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle })
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -11,6 +11,9 @@ Motion::Project::App.setup do |app|
|
|
11
11
|
# the end of the list
|
12
12
|
insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
13
13
|
|
14
|
+
Dir.glob(File.join(File.dirname(__FILE__), SugarCube.platform, 'sugarcube-attributedstring/**/*.rb')).reverse.each do |file|
|
15
|
+
app.files.insert(insert_point, file)
|
16
|
+
end
|
14
17
|
Dir.glob(File.join(File.dirname(__FILE__), 'cocoa/sugarcube-attributedstring/**/*.rb')).reverse.each do |file|
|
15
18
|
app.files.insert(insert_point, file)
|
16
19
|
end
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
describe 'NSAttributeString' do
|
2
|
+
describe "should support all attribute names" do
|
3
|
+
before do
|
4
|
+
@subject = 'test'.attrd
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should be sane" do
|
8
|
+
@subject.isEqualToAttributedString('test'.attrd).should == true
|
9
|
+
end
|
10
|
+
|
11
|
+
# don't care about:
|
12
|
+
# it 'should have `attachment`' do
|
13
|
+
# @subject.isEqualToAttributedString('test'.attrd.attachment()).should != true
|
14
|
+
# end
|
15
|
+
|
16
|
+
it 'should have `ligature`' do
|
17
|
+
'test'.attrd.ligature(2).should.have_string_attributes({ NSLigatureAttributeName => 2 })
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have `kern`' do
|
21
|
+
'test'.attrd.kern(1).should.have_string_attributes({ NSKernAttributeName => 1 })
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have `stroke_width`' do
|
25
|
+
'test'.attrd.stroke_width(1).should.have_string_attributes({ NSStrokeWidthAttributeName => 1 })
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have `strikethrough_style`' do
|
29
|
+
'test'.attrd.strikethrough_style(NSUnderlineStyleSingle).should.have_string_attributes({ NSStrikethroughStyleAttributeName => NSUnderlineStyleSingle })
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have `shadow`' do
|
33
|
+
'test'.attrd.shadow(NSShadow.alloc.init.tap{|s|s.shadowOffset = [1,1]}).should.have_string_attributes({ NSShadowAttributeName => NSShadow.alloc.init.tap{|s|s.shadowOffset = [1,1]} })
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have `vertical_glyph_form`' do
|
37
|
+
'test'.attrd.vertical_glyph_form(1).should.have_string_attributes({ NSVerticalGlyphFormAttributeName => 1 })
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -4,32 +4,27 @@ describe 'NSAttributeString' do
|
|
4
4
|
|
5
5
|
it 'should have #bold' do
|
6
6
|
subject = 'test'.bold
|
7
|
-
subject.should.
|
8
|
-
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :bold.uifont}
|
7
|
+
subject.should.have_string_attributes({NSFontAttributeName => :bold.uifont})
|
9
8
|
end
|
10
9
|
|
11
10
|
it 'should have #italic' do
|
12
11
|
subject = 'test'.italic
|
13
|
-
subject.should.
|
14
|
-
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :italic.uifont}
|
12
|
+
subject.should.have_string_attributes({NSFontAttributeName => :italic.uifont})
|
15
13
|
end
|
16
14
|
|
17
15
|
it 'should have #monospace' do
|
18
16
|
subject = 'test'.monospace
|
19
|
-
subject.should.
|
20
|
-
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :monospace.uifont}
|
17
|
+
subject.should.have_string_attributes({NSFontAttributeName => :monospace.uifont})
|
21
18
|
end
|
22
19
|
|
23
20
|
it 'should have #underline' do
|
24
21
|
subject = 'test'.underline
|
25
|
-
subject.should.
|
26
|
-
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSUnderline' => NSUnderlineStyleSingle}
|
22
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
27
23
|
end
|
28
24
|
|
29
25
|
it 'should be chainable' do
|
30
26
|
subject = 'test'.bold.underline
|
31
|
-
subject.should.
|
32
|
-
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :bold.uifont, 'NSUnderline' => NSUnderlineStyleSingle}
|
27
|
+
subject.should.have_string_attributes({NSFontAttributeName => :bold.uifont, NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
33
28
|
end
|
34
29
|
|
35
30
|
end
|
@@ -39,70 +34,56 @@ describe 'NSAttributeString' do
|
|
39
34
|
@subject = 'test'.attrd
|
40
35
|
end
|
41
36
|
|
42
|
-
it
|
43
|
-
|
37
|
+
it 'should have `paragraph_style`' do
|
38
|
+
par_style = NSMutableParagraphStyle.alloc.init
|
39
|
+
par_style.alignment = NSTextAlignmentRight
|
40
|
+
'test'.attrd.paragraph_style(par_style).should.have_string_attributes({ NSParagraphStyleAttributeName => par_style })
|
44
41
|
end
|
45
42
|
|
46
43
|
it 'should have `font`' do
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should have `paragraph_style`' do
|
52
|
-
@subject.isEqualToAttributedString('test'.attrd.paragraph_style(NSMutableParagraphStyle.alloc.init.tap{|s| s.alignment = UITextAlignmentRight })).should != true
|
44
|
+
'test'.attrd.font(:bold.uifont).should.have_string_attributes({ NSFontAttributeName => :bold.uifont })
|
45
|
+
'test'.attrd.font('Helvetica').should.have_string_attributes({ NSFontAttributeName => 'Helvetica'.uifont })
|
53
46
|
end
|
54
47
|
|
55
48
|
it 'should have `foreground_color`' do
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should have `underline_style`' do
|
61
|
-
@subject.isEqualToAttributedString('test'.attrd.underline_style(NSUnderlineStyleSingle)).should != true
|
49
|
+
'test'.attrd.foreground_color(UIColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => UIColor.redColor })
|
50
|
+
'test'.attrd.color(UIColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => UIColor.redColor })
|
62
51
|
end
|
63
52
|
|
64
53
|
it 'should have `background_color`' do
|
65
|
-
|
66
|
-
|
54
|
+
'test'.attrd.background_color(UIColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => UIColor.redColor })
|
55
|
+
'test'.attrd.bg_color(UIColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => UIColor.redColor })
|
67
56
|
end
|
68
57
|
|
69
|
-
|
70
|
-
|
71
|
-
# @subject.isEqualToAttributedString('test'.attrd.attachment()).should != true
|
72
|
-
# end
|
73
|
-
|
74
|
-
it 'should have `ligature`' do
|
75
|
-
@subject.isEqualToAttributedString('test'.attrd.ligature(2)).should != true
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'should have `kern`' do
|
79
|
-
@subject.isEqualToAttributedString('test'.attrd.kern(1)).should != true
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should have `stroke_width`' do
|
83
|
-
@subject.isEqualToAttributedString('test'.attrd.stroke_width(1)).should != true
|
58
|
+
it 'should have `stroke_color`' do
|
59
|
+
'test'.attrd.stroke_color(UIColor.redColor).should.have_string_attributes({ NSStrokeColorAttributeName => UIColor.redColor })
|
84
60
|
end
|
85
61
|
|
86
|
-
it 'should have `
|
87
|
-
|
62
|
+
it 'should have `underline_style`' do
|
63
|
+
subject = 'test'.attrd.underline_style(NSUnderlineStyleSingle)
|
64
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
88
65
|
end
|
89
66
|
|
90
|
-
it 'should have `
|
91
|
-
|
67
|
+
it 'should have `underline_style`' do
|
68
|
+
subject = 'test'.attrd.underline
|
69
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
92
70
|
end
|
93
71
|
|
94
|
-
it 'should have `
|
95
|
-
|
72
|
+
it 'should have `superscript`' do
|
73
|
+
subject = 'test'.attrd.superscript
|
74
|
+
subject.should.have_string_attributes({KCTSuperscriptAttributeName => 1})
|
75
|
+
subject = 'test'.attrd.superscript(2)
|
76
|
+
subject.should.have_string_attributes({KCTSuperscriptAttributeName => 2})
|
96
77
|
end
|
97
78
|
|
98
|
-
it 'should have `
|
99
|
-
|
79
|
+
it 'should have `subscript`' do
|
80
|
+
subject = 'test'.attrd.subscript
|
81
|
+
subject.should.have_string_attributes({KCTSuperscriptAttributeName => -1})
|
100
82
|
end
|
101
83
|
|
102
84
|
it 'should have `letterpress`' do
|
103
|
-
|
85
|
+
'test'.attrd.letterpress.should.have_string_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle })
|
104
86
|
end
|
105
|
-
|
106
87
|
end
|
107
88
|
|
108
89
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
describe 'NSAttributeString' do
|
2
|
+
|
3
|
+
describe 'NSString attribute string methods' do
|
4
|
+
|
5
|
+
it 'should have #bold' do
|
6
|
+
subject = 'test'.bold
|
7
|
+
subject.should.have_string_attributes({NSFontAttributeName => :bold.nsfont})
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have #monospace' do
|
11
|
+
subject = 'test'.monospace
|
12
|
+
subject.should.have_string_attributes({NSFontAttributeName => :monospace.nsfont})
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have #underline' do
|
16
|
+
subject = 'test'.underline
|
17
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should be chainable' do
|
21
|
+
subject = 'test'.bold.underline
|
22
|
+
subject.should.have_string_attributes({NSFontAttributeName => :bold.nsfont, NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "should support all attribute names" do
|
28
|
+
before do
|
29
|
+
@subject = 'test'.attrd
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have `paragraph_style`' do
|
33
|
+
par_style = NSMutableParagraphStyle.alloc.init
|
34
|
+
par_style.alignment = NSRightTextAlignment
|
35
|
+
'test'.attrd.paragraph_style(par_style).should.have_string_attributes({ NSParagraphStyleAttributeName => par_style })
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should have `font`' do
|
39
|
+
'test'.attrd.font(:bold.nsfont).should.have_string_attributes({ NSFontAttributeName => :bold.nsfont })
|
40
|
+
'test'.attrd.font('Helvetica').should.have_string_attributes({ NSFontAttributeName => 'Helvetica'.nsfont })
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should have `foreground_color`' do
|
44
|
+
'test'.attrd.foreground_color(NSColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => NSColor.redColor })
|
45
|
+
'test'.attrd.color(NSColor.redColor).should.have_string_attributes({ NSForegroundColorAttributeName => NSColor.redColor })
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should have `background_color`' do
|
49
|
+
'test'.attrd.background_color(NSColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => NSColor.redColor })
|
50
|
+
'test'.attrd.bg_color(NSColor.redColor).should.have_string_attributes({ NSBackgroundColorAttributeName => NSColor.redColor })
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should have `stroke_color`' do
|
54
|
+
'test'.attrd.stroke_color(NSColor.redColor).should.have_string_attributes({ NSStrokeColorAttributeName => NSColor.redColor })
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should have `underline_style`' do
|
58
|
+
subject = 'test'.attrd.underline_style(NSUnderlineStyleSingle)
|
59
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should have `underline_style`' do
|
63
|
+
subject = 'test'.attrd.underline
|
64
|
+
subject.should.have_string_attributes({NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should have `superscript`' do
|
68
|
+
subject = 'test'.attrd.superscript
|
69
|
+
subject.should.have_string_attributes({NSSuperscriptAttributeName => 1})
|
70
|
+
subject = 'test'.attrd.superscript(2)
|
71
|
+
subject.should.have_string_attributes({NSSuperscriptAttributeName => 2})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should have `subscript`' do
|
75
|
+
subject = 'test'.attrd.subscript
|
76
|
+
subject.should.have_string_attributes({NSSuperscriptAttributeName => -1})
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should have `letterpress`' do
|
80
|
+
'test'.attrd.letterpress.should.have_string_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle })
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
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: 2.11.
|
4
|
+
version: 2.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin T.A. Gray
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-11-
|
14
|
+
date: 2014-11-07 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: |
|
17
17
|
== Description
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/ios/sugarcube-568/uiimage.rb
|
94
94
|
- lib/ios/sugarcube-animations/animation_chain.rb
|
95
95
|
- lib/ios/sugarcube-animations/uiview.rb
|
96
|
+
- lib/ios/sugarcube-attributedstring/nsattributedstring.rb
|
96
97
|
- lib/ios/sugarcube-color/fixnum.rb
|
97
98
|
- lib/ios/sugarcube-color/nsarray.rb
|
98
99
|
- lib/ios/sugarcube-color/nsstring.rb
|
@@ -150,8 +151,11 @@ files:
|
|
150
151
|
- lib/ios/sugarcube-uikit/uiwebview.rb
|
151
152
|
- lib/osx/sugarcube-animations/nsview.rb
|
152
153
|
- lib/osx/sugarcube-appkit/frameable.rb
|
154
|
+
- lib/osx/sugarcube-appkit/nsfont.rb
|
153
155
|
- lib/osx/sugarcube-appkit/nsstring.rb
|
154
156
|
- lib/osx/sugarcube-appkit/nsview.rb
|
157
|
+
- lib/osx/sugarcube-appkit/symbol.rb
|
158
|
+
- lib/osx/sugarcube-attributedstring/nsattributedstring.rb
|
155
159
|
- lib/osx/sugarcube-color/fixnum.rb
|
156
160
|
- lib/osx/sugarcube-color/nsarray.rb
|
157
161
|
- lib/osx/sugarcube-color/nscolor.rb
|
@@ -212,12 +216,14 @@ files:
|
|
212
216
|
- spec/cocoa/caanimation_spec.rb
|
213
217
|
- spec/cocoa/calayer_spec.rb
|
214
218
|
- spec/cocoa/nsarray_files_spec.rb
|
219
|
+
- spec/cocoa/nsattributedstring_spec.rb
|
215
220
|
- spec/cocoa/nscoder_spec.rb
|
216
221
|
- spec/cocoa/nsdata_files_spec.rb
|
217
222
|
- spec/cocoa/nsdictionary_files_spec.rb
|
218
223
|
- spec/cocoa/numeric_time_spec.rb
|
219
224
|
- spec/cocoa/spritekit_spec.rb
|
220
225
|
- spec/cocoa/timer_spec.rb
|
226
|
+
- spec/helpers/attributed_string.rb
|
221
227
|
- spec/ios/568_spec.rb
|
222
228
|
- spec/ios/animation_chain_spec.rb
|
223
229
|
- spec/ios/color_components_spec.rb
|
@@ -274,6 +280,7 @@ files:
|
|
274
280
|
- spec/osx/color_components_spec.rb
|
275
281
|
- spec/osx/color_other_representations_spec.rb
|
276
282
|
- spec/osx/color_spec.rb
|
283
|
+
- spec/osx/nsattributedstring_spec.rb
|
277
284
|
- spec/osx/nsview_spec.rb
|
278
285
|
- spec/osx/symbol_constants_spec.rb
|
279
286
|
homepage: https://github.com/rubymotion/sugarcube
|
@@ -306,12 +313,14 @@ test_files:
|
|
306
313
|
- spec/cocoa/caanimation_spec.rb
|
307
314
|
- spec/cocoa/calayer_spec.rb
|
308
315
|
- spec/cocoa/nsarray_files_spec.rb
|
316
|
+
- spec/cocoa/nsattributedstring_spec.rb
|
309
317
|
- spec/cocoa/nscoder_spec.rb
|
310
318
|
- spec/cocoa/nsdata_files_spec.rb
|
311
319
|
- spec/cocoa/nsdictionary_files_spec.rb
|
312
320
|
- spec/cocoa/numeric_time_spec.rb
|
313
321
|
- spec/cocoa/spritekit_spec.rb
|
314
322
|
- spec/cocoa/timer_spec.rb
|
323
|
+
- spec/helpers/attributed_string.rb
|
315
324
|
- spec/ios/568_spec.rb
|
316
325
|
- spec/ios/animation_chain_spec.rb
|
317
326
|
- spec/ios/color_components_spec.rb
|
@@ -368,5 +377,6 @@ test_files:
|
|
368
377
|
- spec/osx/color_components_spec.rb
|
369
378
|
- spec/osx/color_other_representations_spec.rb
|
370
379
|
- spec/osx/color_spec.rb
|
380
|
+
- spec/osx/nsattributedstring_spec.rb
|
371
381
|
- spec/osx/nsview_spec.rb
|
372
382
|
- spec/osx/symbol_constants_spec.rb
|