Skip to content

Commit

Permalink
code cleanup, lil refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
halotukozak committed May 28, 2024
1 parent 41e2b2a commit 4588821
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/typography/Code.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package halotukozak.smark
package typography

import typography.macros.{codeUnsafe, text}
import typography.macros.text
import utils.nameOf

type code <: String
Expand All @@ -13,7 +13,7 @@ type sql <: code
type bash <: code
type html <: code

inline def code[L <: code](inline code: L): String = codeUnsafe(nameOf[L], code)
inline def code[L <: code](inline inner: L): String = "```" + nameOf[L] + "\n" + inner + "\n```"

implicit class ScalaHelper(private val sc: StringContext) extends AnyVal {
def scala(args: Any*): scala = sc.s(args *).asInstanceOf[scala]
Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/typography/Emoji.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package halotukozak.smark
package typography

import utils.nameOf

inline def emoji[E <: Emoji] = s":${nameOf[E]}:"

type Emoji

type grinning <: Emoji
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/typography/Headings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ package typography


private[typography] type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6

inline def heading[N <: HeadingLevel : ValueOf](inline inner: String): String = "#" * valueOf[N] + inner
1 change: 0 additions & 1 deletion src/main/scala/typography/List.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ type Unordered = Asterisk | Plus | Hyphen
type Ordered

private[typography] type ListStyle = Unordered | Ordered

2 changes: 1 addition & 1 deletion src/main/scala/typography/Quote.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ inline def note(inline inner: String*): String = quote[Note](inner *)
inline def tip(inline inner: String*): String = quote[Tip](inner *)
inline def important(inline inner: String*): String = quote[Important](inner *)
inline def warning(inline inner: String*): String = quote[Warning](inner *)
inline def caution(inline inner: String*): String = quote[Caution](inner *)
inline def caution(inline inner: String*): String = quote[Caution](inner *)
2 changes: 1 addition & 1 deletion src/main/scala/typography/Reference.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ inline def link[Title <: String](inline url: String): String = s"[${titleFrom[Ti
inline def link(inline url: String, inline title: String): String = s"[$title]($url)"

inline def image[title <: String](inline url: String): String = s"!${link[title](url)}"
inline def image(inline url: String, inline title: String): String = s"!${link(url, title)}"
inline def image(inline url: String, inline title: String): String = s"!${link(url, title)}"
2 changes: 0 additions & 2 deletions src/main/scala/typography/Text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,3 @@ inline def strikethrough(inner: String): String = text[Strikethrough](inner)
inline def subscript(inner: String): String = text[Subscript](inner)
inline def superscript(inner: String): String = text[Superscript](inner)
inline def quoted(inner: String): String = text[Quote](inner)


7 changes: 0 additions & 7 deletions src/main/scala/typography/macros/Code.scala

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/scala/typography/macros/Emoji.scala

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/scala/typography/macros/Headings.scala

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/scala/typography/other.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package halotukozak.smark
package typography


inline def hr: String = "***"
inline def paragraph(inline inner: String*): String = "\n" + inner.mkString("\n\n")
inline def comment(inline inner: String*): String = s"<!-- $inner -->"
inline def html(inline args: String*): String = "\n" + args.mkString("\n") + "\n"
inline def html(inline args: String*): String = "\n" + args.mkString("\n") + "\n"
8 changes: 4 additions & 4 deletions src/test/scala/typography/CodeTest.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package halotukozak.smark
package typography

import typography.macros.{codeUnsafe, text}
import typography.macros.text

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down Expand Up @@ -84,11 +84,11 @@ final class CodeTest extends AnyWordSpec with Matchers {
|```""".stripMargin
}
"custom" in {
codeUnsafe(
"custom",
type custom <: code
code[custom](
"""
|println("HelloWorld")
|""".stripMargin) shouldBe
|""".stripMargin.asInstanceOf[custom]) shouldBe
"""```custom
|
|println("HelloWorld")
Expand Down
10 changes: 0 additions & 10 deletions src/test/scala/typography/EmojiTest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package halotukozak.smark
package typography

import typography.macros.{emoji, emojiUnsafe}

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

Expand All @@ -14,12 +12,4 @@ class EmojiTest extends AnyWordSpec with Matchers {
emoji[`+1`] shouldBe ":+1:"
}
}

"unsafeEmoji" should {
"be evaluated correctly" in {
emojiUnsafe("smile") shouldBe ":smile:"
emojiUnsafe("+1") shouldBe ":+1:"
}
}

}

0 comments on commit 4588821

Please sign in to comment.