Skip to content

Commit

Permalink
Fix new HN Markup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Feb 10, 2015
1 parent fc96db1 commit de8c903
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions Hacker Swifter/Hacker Swifter/Models/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import Foundation
case replyURLString = "replyURLString"
case upvoteURLAddition = "upvoteURLAddition"
case downvoteURLAddition = "downvoteURLAddition"

static let values = [text, username, depth, commentId, parentId, prettyTime, links,
replyURLString, upvoteURLAddition, downvoteURLAddition]
replyURLString, upvoteURLAddition, downvoteURLAddition]
}

public override init(){
Expand All @@ -52,10 +52,10 @@ import Foundation
super.init()
self.parseHTML(html, withType: type)
}

public required init(coder aDecoder: NSCoder) {
super.init()

for key in serialization.values {
setValue(aDecoder.decodeObjectForKey(key.rawValue), forKey: key.rawValue)
}
Expand Down Expand Up @@ -162,8 +162,8 @@ internal extension Comment {

var username = scanner.scanTag("<a href=\"user?id=", endTag: "\">")
self.username = username.utf16Count > 0 ? username : "[deleted]"

self.prettyTime = scanner.scanTag("</a> ", endTag: " |")
self.commentId = scanner.scanTag("<a href=\"item?id=", endTag: "\">")
self.prettyTime = scanner.scanTag(">", endTag: "</a>")

if (html.rangeOfString("[deleted]")?.startIndex != nil) {
self.text = "[deleted]"
Expand All @@ -179,7 +179,6 @@ internal extension Comment {

//LOL, it whould always work, as I strip a Hex color, which is always the same length

self.commentId = scanner.scanTag("reply?id=", endTag: "&")
self.replyURLString = scanner.scanTag("<font size=1><u><a href=\"", endTag: "\">reply")
self.type = CommentFilter.Default
}
Expand Down
12 changes: 6 additions & 6 deletions Hacker Swifter/Hacker Swifter/Models/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Foundation
case postId = "postId"
case prettyTime = "prettyTime"
case upvoteURL = "upvoteURL"

static let values = [title, username, url, points, commentsCount, postId, prettyTime, upvoteURL]
}

Expand All @@ -67,20 +67,20 @@ import Foundation

required public init(coder aDecoder: NSCoder) {
super.init()

for key in serialization.values {
setValue(aDecoder.decodeObjectForKey(key.rawValue), forKey: key.rawValue)
}
}

public func encodeWithCoder(aCoder: NSCoder) {
for key in serialization.values {
if let value: AnyObject = self.valueForKey(key.rawValue) {
aCoder.encodeObject(value, forKey: key.rawValue)
}
}
}

private func encode(object: AnyObject!, key: String, coder: NSCoder) {
if let value: AnyObject = object {
coder.encodeObject(object, forKey: key)
Expand Down Expand Up @@ -203,13 +203,13 @@ internal extension Post {
}
else {
self.points = 0
}
}
self.username = scanner.scanTag("<a href=\"user?id=", endTag: "\"")
if self.username == nil {
self.username = "HN"
}
self.prettyTime = scanner.scanTag("</a> ", endTag: "ago") + "ago"
self.postId = scanner.scanTag("<a href=\"item?id=", endTag: "\">")
self.prettyTime = scanner.scanTag(">", endTag: "</a>")

temp = scanner.scanTag("\">", endTag: "</a>")
if (temp == "discuss") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>https://github.com/Dimillian/HackerSwifter.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Hacker Swifter/HackerSwifter.xcodeproj/project.xcworkspace</string>
<string>Hacker Swifter/HackerSwifter.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>E0D52B920DCA102ACF12EC644CE806103E82A316</key>
Expand Down

0 comments on commit de8c903

Please sign in to comment.