Skip to content

Commit

Permalink
Merge pull request #5 from hanneskaeufler/hk-tip-source
Browse files Browse the repository at this point in the history
feat(mentor): Tips can now have a source
  • Loading branch information
hanneskaeufler authored Jan 28, 2018
2 parents b764208 + 0ada84a commit 5f3c809
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"danger-plugin",
"learning mentor trivia"
],
"version": "0.0.0-development",
"version": "0.1.0",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export declare function markdown(message: string): void
* Level up your programming skills by getting bite-sized tips and tricks in your pull requests.
*/
export default function mentor() {
message(RandomTip().text)
message(RandomTip().toMarkdown())
}
15 changes: 15 additions & 0 deletions src/tip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Tip from "./tip"

describe("Tip", () => {
describe("#toMarkdown", () => {
it("concats the text and the source", () => {
expect(new Tip("A tip with a source.", new URL("http://example.com")).toMarkdown()).toEqual(
"A tip with a source. Source: [http://example.com/](http://example.com/)"
)
})

it("leaves out the source if not present", () => {
expect(new Tip("A tip with a source.").toMarkdown()).toEqual("A tip with a source.")
})
})
})
14 changes: 12 additions & 2 deletions src/tip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
export default class Tip {
text: string
private text: string
private source?: URL

constructor(text: string) {
constructor(text: string, source?: URL) {
this.text = text
this.source = source
}

toMarkdown(): string {
if (this.source) {
return `${this.text} Source: [${this.source}](${this.source})`
}

return this.text
}
}

0 comments on commit 5f3c809

Please sign in to comment.