sugarcube 2.11.1 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb +7 -0
- data/lib/version.rb +1 -1
- data/spec/ios/nsattributedstring_spec.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d99623279065213aca003e13dcc59448c886e7b8
|
4
|
+
data.tar.gz: 582bef5540fe232572381f1638740fffdab17e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97665c180eb52eb7c7fef919fcf8e3db833703f4d95b6e0bbe41b6a3167987afcf8d6d673794297433f09ff71a54ba226cb951ade265d42658603cf967fb453c
|
7
|
+
data.tar.gz: 2c991dd2d0268167f8b776a5ed7900aa6bf39f48ad4465eb29c12e9fc318bfcd6bcf0b4f55b5a16cd40c4bb488646dd000ce7fb53f673f589277fea92c3ccfc6
|
data/README.md
CHANGED
@@ -1249,6 +1249,10 @@ issues with missing constants).
|
|
1249
1249
|
|
1250
1250
|
# And there's where it gets FUN:
|
1251
1251
|
('This'.italic + ' is going to be ' + 'FUN'.bold).underline
|
1252
|
+
|
1253
|
+
# You can even generate attributed text from html! This feature uses the
|
1254
|
+
# NSHTMLTextDocumentType option to convert the html to NSAttributedString
|
1255
|
+
'Why on <b>earth<b> would you want to do <em>that</em>?".attributed_html
|
1252
1256
|
```
|
1253
1257
|
|
1254
1258
|
And you can easily turn an attributed string into a label, if you include the
|
@@ -8,6 +8,11 @@ class NSString
|
|
8
8
|
self.nsattributedstring(attributes)
|
9
9
|
end
|
10
10
|
|
11
|
+
def attributed_html
|
12
|
+
options = {NSDocumentTypeDocumentAttribute => NSHTMLTextDocumentType}
|
13
|
+
NSAttributedString.alloc.initWithData(self.dataUsingEncoding(NSUTF8StringEncoding), options:options, documentAttributes:nil, error:nil)
|
14
|
+
end
|
15
|
+
|
11
16
|
end
|
12
17
|
|
13
18
|
|
@@ -39,6 +44,8 @@ class NSAttributedString
|
|
39
44
|
# new iOS 7 text effects
|
40
45
|
NSTextEffectAttributeName
|
41
46
|
NSTextEffectLetterpressStyle
|
47
|
+
NSRTFDTextDocumentType
|
48
|
+
NSHTMLTextDocumentType
|
42
49
|
# make sure alignments get compiled
|
43
50
|
NSLeftTextAlignment
|
44
51
|
NSRightTextAlignment
|
data/lib/version.rb
CHANGED
@@ -27,6 +27,21 @@ describe 'NSAttributeString' do
|
|
27
27
|
subject.should.have_string_attributes({NSFontAttributeName => :bold.uifont, NSUnderlineStyleAttributeName => NSUnderlineStyleSingle})
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'should convert html' do
|
31
|
+
bold_subject = '<b>Bold</b>'.attributed_html
|
32
|
+
emphasis_subject = '<em>Emphasis</em>'.attributed_html
|
33
|
+
underline_subject = '<u>Underline</u>'.attributed_html
|
34
|
+
|
35
|
+
bold_subject.should.be.kind_of(NSAttributedString)
|
36
|
+
emphasis_subject.should.be.kind_of(NSAttributedString)
|
37
|
+
underline_subject.should.be.kind_of(NSAttributedString)
|
38
|
+
|
39
|
+
# Commented out tests don't work because :bold.uifont isn't the same font instance as the html converter uses.
|
40
|
+
# bold_subject.attributesAtIndex(0, effectiveRange:nil)['NSFont'].should == :bold.uifont
|
41
|
+
# emphasis_subject.attributesAtIndex(0, effectiveRange:nil)['NSFont'].should == :italic.uifont
|
42
|
+
underline_subject.attributesAtIndex(0, effectiveRange:nil)['NSUnderline'].should == NSUnderlineStyleSingle
|
43
|
+
end
|
44
|
+
|
30
45
|
end
|
31
46
|
|
32
47
|
describe "should support all attribute names" 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: 2.
|
4
|
+
version: 2.12.0
|
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-14 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: |
|
17
17
|
== Description
|