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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 870b646f170334f7679d70d38b1789b261015ebb
4
- data.tar.gz: 283c0fe56dc524fe62cea324e853bf4fa8f0ab0f
3
+ metadata.gz: d99623279065213aca003e13dcc59448c886e7b8
4
+ data.tar.gz: 582bef5540fe232572381f1638740fffdab17e82
5
5
  SHA512:
6
- metadata.gz: c3588d547fc015cde49784ece637def74e9a1d76b0dff4718f6ef9dbd31ebb93c0b8ceecd709213eafb627f3a29b0a6b281e592adc7cd66283c5185c8f95bf8a
7
- data.tar.gz: f8d75ef4393ae0daae5e9abd2ae7d615a6b11ac7dde9534a8153ed8b6f4c90c22da882cb6d9e982c14dc8212986795e371f718c348612db86a3ea195e5d994c1
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
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '2.11.1'
2
+ Version = '2.12.0'
3
3
  end
@@ -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.11.1
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-07 00:00:00.000000000 Z
14
+ date: 2014-11-14 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: |
17
17
  == Description