Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support manual application of StringStyle transforms via attributes dictionary #298

Open
wants to merge 8 commits into
base: master
from

Conversation

@jvisenti
Copy link
Contributor

jvisenti commented Aug 9, 2017

Addresses #297

@ZevEisenberg
Copy link
Collaborator

ZevEisenberg commented Sep 22, 2017

@jvisenti have you been using this in production code? Think it's up to snuff for merging?

@jvisenti
Copy link
Contributor Author

jvisenti commented Sep 22, 2017

@ZevEisenberg We ended up being able to get by without these changes, so I leave it up to you whether you think these changes should be included. I still think the attributes dict should have everything you need to create the attributed string manually, but you may want to hold off until at least one other person requests it.

@ZevEisenberg
Copy link
Collaborator

ZevEisenberg commented Oct 1, 2017

Sounds reasonable. We should rebase this at some point, or port the changes over, now that #296 has landed. Rebase looks a little hairy, so a by-hand port might make more sense.

@@ -25,7 +25,7 @@ public enum Transform {
case capitalizedWithLocale(Locale)
case custom(TransformFunction)

var transformer: TransformFunction {
public var transformer: TransformFunction {

This comment has been minimized.

@cjamie

cjamie Jun 2, 2019

this change shouldn't be necessary


internal var name: Name {
switch self {
case .lowercase, .lowercaseWithLocale: return Name.lowercase

This comment has been minimized.

@cjamie

cjamie Jun 2, 2019

would like to take advantage of swift's type inference:

Suggested change
case .lowercase, .lowercaseWithLocale: return Name.lowercase
case .lowercase, .lowercaseWithLocale: return .lowercase
@@ -37,7 +37,7 @@ class StringStyleTests: XCTestCase {
#if os(iOS) || os(tvOS)
func testTextStyle() {
let style = StringStyle(.textStyle(titleTextStyle))
for (style, fullStyle) in additiviePermutations(for: style) {
for (style, fullStyle) in additivePermutations(for: style) {

This comment has been minimized.

@cjamie

cjamie Jun 2, 2019

while we're here, why don't we prefer forEach instead?

Suggested change
for (style, fullStyle) in additivePermutations(for: style) {
additivePermutations(for: style).forEach { (style, fullStyle) in
@@ -60,7 +60,7 @@ internal enum EmbeddedTransformationHelpers {
let representations = styleAttributes[BonMotTransformationsAttributeName] as? [StyleAttributes] ?? []
let results: [T?] = representations.map { representation in
for type in embeddedTransformationTypes {
if let transformation = type.from(dictionary: representation) as? T {
if let transformation = type.init(dictionary: representation) as? T {

This comment has been minimized.

@cjamie

cjamie Jun 2, 2019

for line 61, we can change this to a compactMap so we don't need to go through the collection again, and with flattop

Suggested change
if let transformation = type.init(dictionary: representation) as? T {
let results: [T] = representations.compactMap { representation in
let transform = (attributes[BonMotTransformationsAttributeName] as? StyleAttributes).flatMap(Transform.init)
XCTAssertNotNil(transform)

if let transformer = transform?.transformer {

This comment has been minimized.

@cjamie

cjamie Jun 2, 2019

in tests, I think its ok to force unwrap, so we can just get a failing test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.