Last active
May 20, 2016 00:41
-
-
Save MosheBerman/c9092eddb11bd384c38790d5552652d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textForToday() -> NSAttributedString | |
{ | |
let sefira = Sefira() | |
let day = sefira.dayToUseForDisplay() | |
let prayers : KCSefiraPrayerAddition = self.flagsForPrayerComponentsEnabledByUser() | |
let storedCustom = SettingsManager.sharedManager.custom() | |
if let custom = KCSefiraCustom(rawValue: storedCustom) { | |
sefiraFormatter.custom = custom | |
} | |
var text : NSMutableAttributedString = NSMutableAttributedString() | |
if let countTextWithPrayers = self.sefiraFormatter.countStringFromInteger(day, withPrayers: prayers) | |
{ | |
text = NSMutableAttributedString(string:countTextWithPrayers) | |
} | |
else | |
{ | |
text = NSMutableAttributedString(string: "No count.") | |
} | |
let headerFont = self.headerFont() | |
let bodyFont = self.bodyFont() | |
let abbreviationFont = self.abbreviationFont() | |
let bodyParagraphStyle = self.bodyParagraphStyle() | |
let kabbalisticParagraphStyle = self.kabbalisticParagraphStyle() | |
let centeredParagraphStyle = self.centeredParagraphStyle() | |
let bodyAttributes : [String : AnyObject] = [ | |
NSParagraphStyleAttributeName : bodyParagraphStyle, | |
NSFontAttributeName : bodyFont | |
] | |
let headerAttributes : [String : AnyObject] = [ | |
NSFontAttributeName : headerFont | |
] | |
let abbreviationAttributes : [String : AnyObject] = [ | |
NSFontAttributeName : abbreviationFont, | |
NSParagraphStyleAttributeName : kabbalisticParagraphStyle | |
] | |
let countAttributes : [String : AnyObject] = [ | |
NSFontAttributeName : headerFont, | |
NSParagraphStyleAttributeName : centeredParagraphStyle | |
] | |
let centerAttributes : [String : AnyObject] = [ | |
NSParagraphStyleAttributeName : centeredParagraphStyle | |
] | |
guard let countText = self.sefiraFormatter.countStringFromInteger(day) else | |
{ | |
text.applyAttributes(countAttributes, toOccurrencesOfSubstrings: [text.string]) | |
return text | |
} | |
let kabbalisticAbbreviations = ["אב\"ג ית\"ץ", "קר\"ע שט\"ן", "נג\"ד יכ\"ש","בט\"ר צת\"ג", "חק\"ב טנ\"ע", "יג\"ל פז\"ק", "שק\"ו צי\"ת"]; | |
let paragraphHeaders = ["לְשֵׁם", "בָּרוּךְ", "הָרַחֲמָן", "לַמְנַצֵּֽחַ", "אָנָּא", "רִבּוֹנוֹ שֶׁל עוֹלָם", "עָלֵינוּ", "וְעַל כֵּן"] | |
let centeredText = [sefiraFormatter.blessing(), "בָּרוּךְ שֵׁם כְּבוֹד מַלְכוּתוֹ לְעוֹלָם וָעֶד."] | |
text.setAttributes(bodyAttributes, range: NSMakeRange(0, text.length-1)) | |
text.applyAttributes(headerAttributes, toOccurrencesOfSubstrings: paragraphHeaders) | |
text.applyAttributes(abbreviationAttributes, toOccurrencesOfSubstrings: kabbalisticAbbreviations) | |
text.applyAttributes(countAttributes, toOccurrencesOfSubstrings: [countText]) | |
text.applyAttributes(centerAttributes, toOccurrencesOfSubstrings: centeredText) | |
return text | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment