-
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?
Changes from all commits
15760e3
9076ab8
0e80787
1b51c09
864de4f
b19e942
5388a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 textStyles:
file:
key: ...
includedNodes:
- ...
destination: ...
templateOptions:
usingSystemFonts: true |
||
color: {{ colorTypeName }}( | ||
red: {{ style.color.color.red }}, | ||
green: {{ style.color.color.green }}, | ||
|
@@ -253,6 +253,13 @@ import AppKit | |
self.init(string: string, attributes: style.attributes(includingParagraphStyle: includingParagraphStyle)) | ||
} | ||
} | ||
|
||
{{ accessModifier }} extension String{ | ||
func styled(as style: {{ styleTypeName }}) -> NSAttributedString { | ||
return NSAttributedString(string: self, style: style) | ||
} | ||
} | ||
Comment on lines
+257
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
}
} |
||
|
||
{% else %} | ||
// No text style found | ||
{% endif %} |
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?
Usage example: