-
Notifications
You must be signed in to change notification settings - Fork 9
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
Extensions for text and color styles template #75
base: master
Are you sure you want to change the base?
Conversation
Better, if I update demo prj?
Пт, 13 нояб. 2020 г. в 20:00, Almaz Ibragimov <[email protected]>:
***@***.**** commented on this pull request.
------------------------------
In Templates/ColorStyles.stencil
<#75 (comment)>:
> @@ -35,7 +35,7 @@ import AppKit
green: {{ style.color.green }},
blue: {{ style.color.blue }},
alpha: {{ style.color.alpha }}
- )
+ ).color
This change seems to break the demo project:
https://github.com/almazrafi/Fugen/pull/75/checks?check_run_id=1237672063
Can we merge PR without this change?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#75 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKUJEOWJEPIFTCQA5CKBHTSPVCZLANCNFSM4SLTU3UQ>
.
--
С уважением, Максим.
|
This will still break backward compatibility. It looks like we need to add a separate |
@almazrafi ok I did work by remarks, check it pls. |
Isn't Apple Way ^_^ |
@@ -63,7 +63,7 @@ import AppKit | |||
/// Line height: {{ style.lineHeight|default:"default" }} | |||
/// Letter spacing: {{ style.letterSpacing|default:"default" }} | |||
{{ accessModifier }} static let {% call propertyName style.name %} = {{ styleTypeName }}( | |||
font: {{ fontTypeName }}(name: "{{ style.font.name }}", size: {{ style.font.size }}), | |||
font: {{ fontTypeName }}(name: "{{ style.font.name }}", size: {{ style.font.size }}) ?? {{ fontTypeName }}.systemFont(ofSize: {{ style.font.size }}), |
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, we should not use default system font, if font not found. You should validate all text styles on application start, for example:
do {
try TextStyle.validate()
} catch {
assertionFailure("\(error)")
}
Also, you can generate TextStyles using system font by specifying in templateOptions
(will be available in next release):
textStyles:
file:
key: ...
includedNodes:
- ...
destination: ...
templateOptions:
usingSystemFonts: true
#if os(OSX) | ||
import AppKit.NSColor | ||
internal typealias {{ colorTypeNameExtension }} = NSColor | ||
#elseif os(iOS) || os(tvOS) || os(watchOS) | ||
import UIKit.UIColor | ||
internal typealias {{ colorTypeNameExtension }} = UIColor | ||
#endif | ||
|
||
extension {{ colorTypeNameExtension }}{ | ||
{% for style in colorStyles %} | ||
static let {% call propertyName style.name %} = {{ colorTypeNameExtension }}( | ||
red: {{ style.color.red }}, | ||
green: {{ style.color.green }}, | ||
blue: {{ style.color.blue }}, | ||
alpha: {{ style.color.alpha }}) | ||
{% endfor %} | ||
} | ||
|
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.
Could we write another extension instead of this to the bottom of file?
{{ accessModifier }} extension {{ colorTypeName }} {
// MARK: - Type Methods
static func style(_ colorStyle: {{ styleTypeName }}) -> {{ colorTypeName }} {
colorStyle.color
}
}
Usage example:
view.backgroundColor = .style(.uiBackground)
{{ accessModifier }} extension String{ | ||
func styled(as style: {{ styleTypeName }}) -> NSAttributedString { | ||
return NSAttributedString(string: self, style: style) | ||
} | ||
} |
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.
Need to align template code:
{{ accessModifier }} extension String {
func styled(as style: {{ styleTypeName }}) -> NSAttributedString {
NSAttributedString(string: self, style: style)
}
}
Extended templates:
@almazrafi please check before merge. I make changes in blind mode. No time for check in on my side. #74