Skip to content

Commit 3fc7869

Browse files
committed
Global functions return AttributeFunction.
This allows these to be composed with join, etc.
1 parent dca0006 commit 3fc7869

12 files changed

+24
-26
lines changed

Attributed/ColorType+Attributes.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public extension ColorType
2727
*/
2828
public func foregroundAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSForegroundColorAttributeName, self, string)
30+
return Attributed.attribute(NSForegroundColorAttributeName, withValue: self)(string)
3131
}
3232

3333
// MARK: - Background Color
@@ -41,7 +41,7 @@ public extension ColorType
4141
*/
4242
public func backgroundAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
4343
{
44-
return Attributed.attribute(NSBackgroundColorAttributeName, self, string)
44+
return Attributed.attribute(NSBackgroundColorAttributeName, withValue: self)(string)
4545
}
4646

4747
// MARK: - Underline Color
@@ -55,7 +55,7 @@ public extension ColorType
5555
*/
5656
public func underlineAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
5757
{
58-
return Attributed.attribute(NSUnderlineColorAttributeName, self, string)
58+
return Attributed.attribute(NSUnderlineColorAttributeName, withValue: self)(string)
5959
}
6060

6161
// MARK: - Strikethrough Color
@@ -69,6 +69,6 @@ public extension ColorType
6969
*/
7070
public func strikethroughAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
7171
{
72-
return Attributed.attribute(NSStrikethroughColorAttributeName, self, string)
72+
return Attributed.attribute(NSStrikethroughColorAttributeName, withValue: self)(string)
7373
}
7474
}

Attributed/FontType+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension FontType
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSFontAttributeName, self, string)
30+
return Attributed.attribute(NSFontAttributeName, withValue: self)(string)
3131
}
3232
}

Attributed/Functions.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,28 @@
99
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1010

1111
/**
12-
Returns an attributed string convertible with the specified attributes applied at the root level.
12+
Returns an attribute function to apply the specified attributes.
1313

1414
The attributes will not override matching attributes deeper in the hierarchy.
1515

1616
- parameter attributes: The attributes to apply.
17-
- parameter strings: The convertible strings.
1817
*/
19-
public func attributes(attributes: [String:AnyObject?], _ string: AttributedStringConvertible)
20-
-> AttributedStringConvertible
18+
public func attributesWithValues(attributes: [String:AnyObject?]) -> AttributeFunction
2119
{
22-
return NestedAttributedString(attributes: attributes, children: [string])
20+
return { string in
21+
return NestedAttributedString(attributes: attributes, children: [string])
22+
}
2323
}
2424

2525
/**
26-
Returns an attributed string convertible with the specified attribute applied at the root level.
26+
Returns an attribute function to apply the specified attribute.
2727

2828
The attribute value will not override a matching attribute deeper in the hierarchy.
2929

3030
- parameter attribute: The attribute name to apply.
3131
- parameter value: The attribute value to apply.
32-
- parameter strings: The convertible strings.
3332
*/
34-
public func attribute(attribute: String, _ value: AnyObject?, _ string: AttributedStringConvertible)
35-
-> AttributedStringConvertible
33+
public func attribute(attribute: String, withValue value: AnyObject?) -> AttributeFunction
3634
{
37-
return Attributed.attributes([attribute: value], string)
35+
return attributesWithValues([attribute: value])
3836
}

Attributed/Ligature+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension Ligature
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSLigatureAttributeName, self.rawValue, string)
30+
return Attributed.attribute(NSLigatureAttributeName, withValue: self.rawValue)(string)
3131
}
3232
}

Attributed/NSCursor+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension NSCursor
2525
*/
2626
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2727
{
28-
return Attributed.attribute(NSCursorAttributeName, self, string)
28+
return Attributed.attribute(NSCursorAttributeName, withValue: self)(string)
2929
}
3030
}
3131

Attributed/NSNumberConvertible+Attributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public extension NSNumberConvertible
2727
*/
2828
public func baselineOffsetAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSBaselineOffsetAttributeName, self.NSNumberValue, string)
30+
return Attributed.attribute(NSBaselineOffsetAttributeName, withValue: self.NSNumberValue)(string)
3131
}
3232

3333
// MARK: - Kern
@@ -41,6 +41,6 @@ public extension NSNumberConvertible
4141
*/
4242
func kernAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
4343
{
44-
return Attributed.attribute(NSKernAttributeName, self.NSNumberValue, string)
44+
return Attributed.attribute(NSKernAttributeName, withValue: self.NSNumberValue)(string)
4545
}
4646
}

Attributed/NSParagraphStyle+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension NSParagraphStyle
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSParagraphStyleAttributeName, self, string)
30+
return Attributed.attribute(NSParagraphStyleAttributeName, withValue: self)(string)
3131
}
3232
}

Attributed/NSShadow+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension NSShadow
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSShadowAttributeName, self, string)
30+
return Attributed.attribute(NSShadowAttributeName, withValue: self)(string)
3131
}
3232
}

Attributed/NSTextAttachment+Attributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public extension NSTextAttachment
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSAttachmentAttributeName, self, string)
30+
return Attributed.attribute(NSAttachmentAttributeName, withValue: self)(string)
3131
}
3232
}

Attributed/NSUnderlineStyle+Attributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public extension NSUnderlineStyle
2727
*/
2828
public func attribute(string: AttributedStringConvertible) -> AttributedStringConvertible
2929
{
30-
return Attributed.attribute(NSUnderlineStyleAttributeName, self.rawValue, string)
30+
return Attributed.attribute(NSUnderlineStyleAttributeName, withValue: self.rawValue)(string)
3131
}
3232

3333
// MARK: - Strikethrough
@@ -41,6 +41,6 @@ public extension NSUnderlineStyle
4141
*/
4242
public func strikethroughAttribute(string: AttributedStringConvertible) -> AttributedStringConvertible
4343
{
44-
return Attributed.attribute(NSStrikethroughStyleAttributeName, self.rawValue, string)
44+
return Attributed.attribute(NSStrikethroughStyleAttributeName, withValue: self.rawValue)(string)
4545
}
4646
}

0 commit comments

Comments
 (0)