-
Notifications
You must be signed in to change notification settings - Fork 196
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
New XMLStyleRule variants for dynamic styling #391
Conversation
@kosyak wow, this is a great addition! Thanks so much for contributing back your work so that others can benefit ❤️ I'd love to see some unit tests to make sure it keeps working as advertised. Is that something you'd be willing to add? I can help if you run into trouble. |
@kosyak This is great, thank you! I would also love to see the docs updated, with maybe an advanced/dynamic XML section explaining usage of this new functionality (similar to your PR description): https://github.com/Rightpoint/BonMot/blob/master/README.md#styling-parts-of-strings-with-xml |
Thanks for your support! I totally understand the need of tests and docs for this, will come up with those, won’t hesitate to ask for help :) |
@ZevEisenberg I've added unit tests (they're based on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a quick look and left a few comments. I think they'll make the code a bit tidier 😄. Once you've done that, I'll give it a more thorough look. I'm wondering if we can come up with better names for the new cases?
@@ -555,6 +555,134 @@ class StringStyleTests: XCTestCase { | |||
XCTAssertFalse(stillHasAltSixDict) | |||
} | |||
|
|||
func testStyleBlockRules() { | |||
let string = "0<one attr1=\"11\">1<two attr2=\"12\">2</two></one>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Raw strings make this a lot nicer:
let string = "0<one attr1=\"11\">1<two attr2=\"12\">2</two></one>" | |
let string = #"0<one attr1="11">1<two attr2="12">2</two></one>"# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I find the use of "11" and "12" in the mix to be confusing. I'd love longer and/or less ambiguous names, just to make it easier to read this code 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test, I've tried not only to extract and assert attribute values but also to have them included in the styling work.
So I've chosen one NSAttributeString parameter (baselineOffset
) and tried to produce a style with a baselineOffset
parsed from attribute's value in each of styleBlock
s. Because of that, values of these attributes are numbers.
It doesn't matter for me what NSAttributedString style to use in the test, maybe there is a better fit instead of baselineOffset
. E.g. we can have font names as attribute values and try to construct and return .font()
style within blocks...
return StringStyle() | ||
} | ||
|
||
tagAttr1Value = val1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may be able to simplify this test. Rather than asserting things inside the closure, do some work in the closure, and afterward, assert that the result is as expected. Does that work for you, or would it miss some aspect of the way the closers work that you want to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed another commit where all guard
s are removed. A bit better, I think. Still, lots of typecasts and ??
...
@ZevEisenberg I've pushed fixes that hopefully will resolve some of your concerns.
I'm looking at some Kotlin code right now, and there's |
Yeah, the Kotlin naming doesn't seem to fit too well here. What about |
I'm fine with |
Damn. I forgot about those. I'd be fine with |
I'm not sure where to put it - should it be near Also, won't there be a confusion between our freshly renamed Here's one more naming option: |
Wow, I'm glad one of the two of us is paying attention! 😅 I haven't worked on this code in a while, so I'm a little rusty. You make excellent points. I'll have a think about it when I've got some time, and I definitely hope to get this in soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kosyak Thanks so much! I think where you landed on the naming makes sense to me. To avoid having this sit open any longer I'm going to merge it as-is, but it would be great if you could follow up with a docs update PR to the README!
Thanks for the merge, will work on readme/docs this week. |
Hello and thank you for this fine library!
I propose addition of several
XMLStyleRule
s to dynamically generate and apply styles, enter- and exit-insertions of elements.With these changes, you can use them like this:
We have a BonMot patched with these changes for quite some time, they are very convenient for us :)