Skip to content

Commit

Permalink
Documentation added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Krupko committed Mar 6, 2019
1 parent 58d6d4c commit 53dd7b1
Show file tree
Hide file tree
Showing 50 changed files with 4,093 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
xcodebuild_arguments:
- "-workspace"
- "Example/Prestyler.xcworkspace"
- "-scheme"
- "Prestyler-Example"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Example/Prestyler.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

/* Begin PBXFileReference section */
0E9523E31BA9C86DFD69F0B8 /* Pods_Prestyler_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Prestyler_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2E170C0F7A2C6C8F9B8FA46D /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
2FEBCAE621E0B43E51E76D67 /* Pods_Prestyler_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Prestyler_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
55290938B9D8C1DDA2325DCD /* Pods-Prestyler_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Prestyler_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Prestyler_Example/Pods-Prestyler_Example.debug.xcconfig"; sourceTree = "<group>"; };
5D115F174A36A6364FF2B7F9 /* Pods-Prestyler_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Prestyler_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Prestyler_Tests/Pods-Prestyler_Tests.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -143,7 +142,6 @@
children = (
EBA7A5B7D7BB1838F41FB47B /* Prestyler.podspec */,
FB7B15A898B61D56E7B80F39 /* README.md */,
2E170C0F7A2C6C8F9B8FA46D /* LICENSE */,
);
name = "Podspec Metadata";
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
25 changes: 0 additions & 25 deletions Example/Prestyler/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

6 changes: 3 additions & 3 deletions Prestyler.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

Pod::Spec.new do |s|
s.name = 'Prestyler'
s.version = '1.0.0'
s.version = '1.0.1'
s.summary = 'Elegant text formatting tool in Swift'
s.homepage = 'https://github.com/kruil/Prestyler'
s.swift_version = '4.2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Ilia Krupko' => '' }
s.license = 'MIT'
s.author = 'Ilia Krupko'
s.source = { :git => 'https://github.com/kruil/Prestyler.git', :tag => s.version.to_s }
s.ios.deployment_target = '9.0'
s.source_files = 'Prestyler/Classes/*.swift'
Expand Down
14 changes: 14 additions & 0 deletions Prestyler/Classes/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

import Foundation


/// Prestyler uses a public extension to provide access to string formatting. Next methods can be used for every string.
public extension String {

/// Convert string to attributed string by looking for embeded tag and find sutable patterns.
///
/// - Returns: Attributed string
func prestyled() -> NSAttributedString {
var textToStyle = self
let appliedRules = Prestyler.findTextRules(&textToStyle)
Expand All @@ -16,10 +22,18 @@ public extension String {
return resultedText
}

/// Convert string to attributed string by using provided rule pattern.
///
/// - Parameter rule: pattern rule to apply
/// - Returns: attributed string
func prestyledBy(rule: String) -> NSAttributedString {
return (rule + self + rule).prestyled()
}

/// Convert string to attributed string by using provided styles.
///
/// - Parameter styles: styles to apply
/// - Returns: attributed string
func prestyledBy(styles: Any...) -> NSAttributedString {
let rule = TextRule(styles: styles, positions: [0, self.count-1])
var resultedText = NSMutableAttributedString(string: self)
Expand Down
6 changes: 6 additions & 0 deletions Prestyler/Classes/Precolor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation


/// Precolor helps to manage color information for Rule styles. By using precolor you can define background and foreground text colors, and also make some interesting effects.
public class Precolor {
private let color: UIColor
var isForeground = true
Expand All @@ -22,24 +23,29 @@ public class Precolor {

//MARK: - Public methods

/// Initialize new Precolor with random color
public init() {
color = UIColor.red
random = 100
}

/// Initialize new Precolor with provided color
public init(_ color: UIColor) {
self.color = color
}

/// Initialize new Precolor with provided string color in hex format. For example "#234" or "#5463ff"
public init(_ hexString: String) {
self.color = hexString.hexToUIColor() ?? Constants.errorColor
}

/// Precolor will effect to background text color instead of foreground.
public func forBackgound() -> Precolor {
isForeground = false
return self
}

/// Set percent which defines how much random color should effect original color.
public func random(_ percent: Int = 100) -> Precolor {
self.random = percent
return self
Expand Down
12 changes: 12 additions & 0 deletions Prestyler/Classes/Prestyler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
import Foundation


/// This enumeration can be used to describe Rule styles.
public enum Prestyle {
/// Bold text
case bold
/// Italic text
case italic
/// Strikethrough text
case strikethrough
/// Underline text
case underline
}


/// Prestyler provides static methods to manage rules.
public class Prestyler {
struct Rule {
let pattern: String
Expand All @@ -33,11 +39,17 @@ public class Prestyler {

// MARK: - Public methods

/// Defines new rule using patters and styles to apply.
///
/// - Parameters:
/// - pattern: pattern, for example "<red>"
/// - styles: can be objects of sdifferent types, including Int, UIColor, Prestyle etc.
static public func defineRule(_ pattern: String, _ styles: Any...) {
rules.removeAll(where: { $0.pattern == pattern })
rules.append(Rule(pattern: pattern, styles: styles))
}

///
static public func removeAllRules() {
rules.removeAll()
}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
![Prestyler: Swift text styler](https://github.com/kruil/Prestyler/blob/master/logo.png?raw=true)
[![CI Status](https://img.shields.io/travis/kruil/Prestyler.svg?style=flat)](https://travis-ci.org/kruil/Prestyler)
[![Swift Version](https://img.shields.io/badge/language-swift%204.2-brightgreen.svg)](https://developer.apple.com/swift)
[![Documentation](https://github.com/kruil/Prestyler/blob/master/docs/badge.svg)](https://kruil.github.io/Prestyler)
[![Version](https://img.shields.io/cocoapods/v/Prestyler.svg?style=flat)](https://cocoapods.org/pods/Prestyler)
[![License](https://img.shields.io/cocoapods/l/Prestyler.svg?style=flat)](https://cocoapods.org/pods/Prestyler)
[![Platform](https://img.shields.io/cocoapods/p/Prestyler.svg?style=flat)](https://cocoapods.org/pods/Prestyler)

Prestyler is a text formatting library which is based on original NSAttributedString class. It simplifies and extends original workflow, giving you clean and short syntax.
Prestyler is a text styling library which is based on original NSAttributedString class. It simplifies and extends original workflow, giving you more clean and short syntax. You can find full [documentation](https://kruil.github.io/Prestyler) here. Please check it out and leave your feedback!

---

Expand All @@ -27,6 +28,8 @@ Prestyler.defineRule("$", Prestyle.bold, Prestyle.underline, UIColor.red)
label.attributedText = "Prestyler do $everything$ instead of you.".prestyled()
```

---

### Requirements and installation

- iOS 9.0+
Expand Down
140 changes: 140 additions & 0 deletions docs/Classes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Classes Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>

</head>
<body>
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">Prestyler Docs</a> (100% documented)</p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">Prestyler Reference</a>
<img id="carat" src="img/carat.png" />
Classes Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/Precolor.html">Precolor</a>
</li>
<li class="nav-group-task">
<a href="Classes/Prestyler.html">Prestyler</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Enums/Prestyle.html">Prestyle</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Extensions/String.html">String</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1>Classes</h1>
<p>The following classes are available globally.</p>

</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:9PrestylerAAC"></a>
<a name="//apple_ref/swift/Class/Prestyler" class="dashAnchor"></a>
<a class="token" href="#/s:9PrestylerAAC">Prestyler</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Prestyler provides static methods to manage rules.</p>

<a href="Classes/Prestyler.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Prestyler</span></code></pre>

</div>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:9Prestyler8PrecolorC"></a>
<a name="//apple_ref/swift/Class/Precolor" class="dashAnchor"></a>
<a class="token" href="#/s:9Prestyler8PrecolorC">Precolor</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Precolor helps to manage color information for Rule styles. By using precolor you can define background and foreground text colors, and also make some interesting effects.</p>

<a href="Classes/Precolor.html" class="slightly-smaller">See more</a>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Precolor</span></code></pre>

</div>
</div>
</section>
</div>
</li>
</ul>
</div>
</section>
</section>
<section id="footer">
<p>&copy; 2019 <a class="link" href="https://github.com/kruil/Prestyler" target="_blank" rel="external">Ilia Krupko</a>. All rights reserved. (Last updated: 2019-03-06)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.1</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>
Loading

0 comments on commit 53dd7b1

Please sign in to comment.