Skip to content

Commit

Permalink
Integrate with Path
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Oct 1, 2024
1 parent f7336a2 commit e5ff507
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 88 deletions.
3 changes: 2 additions & 1 deletion src/url/nettlesome.Authority.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import denominative.*
import anticipation.*
import contextual.*
import spectacular.*
import serpentine.*

object Authority:
given Authority is Showable = auth =>
t"${auth.userInfo.lay(t"")(_+t"@")}${auth.host}${auth.port.let(_.show).lay(t"")(t":"+_)}"

def parse(value: Text)(using Tactic[UrlError]): Authority raises HostnameError =
def parse(value: Text): Authority raises HostnameError raises UrlError =
import UrlError.Expectation.*

safely(value.where(_ == '@')) match
Expand Down
35 changes: 0 additions & 35 deletions src/url/nettlesome.Hyperlink.scala

This file was deleted.

50 changes: 25 additions & 25 deletions src/url/nettlesome.Url.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,46 @@ import rudiments.*
import vacuous.*
import fulminate.*
import contingency.*
import prepositional.*
import denominative.*
import escapade.*
import anticipation.*
import contextual.*
import spectacular.*
import nomenclature.*

case class Url[+SchemeType <: Label]
(scheme: Scheme[SchemeType],
authority: Optional[Authority],
pathText: Text,
query: Optional[Text] = Unset,
fragment: Optional[Text] = Unset):

lazy val path: List[Name[""]] =
// FIXME: This needs to be handled better
import strategies.throwUnsafely
pathText.tail.cut(t"/").reverse.map(_.urlDecode).map(Name(_))
fragment: Optional[Text] = Unset)
extends Root(t"${scheme.name}://${authority.lay(t"")(_.show)}$pathText", t"/", Case.Sensitive):
type Platform = HttpUrl

def requestTarget: Text = pathText+query.lay(t"")(t"?"+_)

object Url:
type Rules = MustMatch["[A-Za-z0-9_.~-]*"]

given (using Tactic[UrlError], Tactic[HostnameError], Tactic[NameError])
=> HttpUrl is Navigable by Name[HttpUrl] from HttpUrl under Rules as navigable = new Navigable:
type Operand = Name[HttpUrl]
type Self = HttpUrl
type Source = HttpUrl
type Constraint = Rules

val separator: Text = t"/"
val parentElement: Text = t".."
val selfText: Text = t"."

def root(path: Text): HttpUrl = Url.parse(path.keep(rootLength(path)))
def element(element: Text): Name[HttpUrl] = Name(element)
def rootLength(path: Text): Int = path.where(_ == '/', Oct).let(_.n0).or(path.length)
def elementText(element: Name[HttpUrl]): Text = element.text
def rootText(url: HttpUrl): Text = url.show
def caseSensitivity: Case = Case.Sensitive

given HttpUrl is GenericUrl = _.show
given (using Tactic[UrlError], Tactic[HostnameError]) => HttpUrl is SpecificUrl = Url.parse(_)

Expand All @@ -59,25 +78,6 @@ object Url:

given [SchemeType <: Label]: Encoder[Url[SchemeType]] = _.show

given [SchemeType <: Label]
=> Url[SchemeType] is Navigable["", (Scheme[SchemeType], Optional[Authority])]:
def separator(url: Url[SchemeType]): Text = t"/"
def descent(url: Url[SchemeType]): List[Name[""]] = url.path

def root(url: Url[SchemeType]): (Scheme[SchemeType], Optional[Authority]) =
(url.scheme, url.authority)

def prefix(root: (Scheme[SchemeType], Optional[Authority])): Text =
t"${root(0).name}:${root(1).let(t"//"+_.show).or(t"")}"

given [SchemeType <: Label]
=> PathCreator[Url[SchemeType], "", (Scheme[SchemeType], Optional[Authority])]:

def path(ascent: (Scheme[SchemeType], Optional[Authority]), descent: List[Name[""]])
: Url[SchemeType] =

Url(ascent(0), ascent(1), descent.reverse.map(_.render).join(t"/"))

given [SchemeType <: Label] => Url[SchemeType] is Teletypeable as teletype =
url => e"$Underline(${Fg(0x00bfff)}(${url.show}))"

Expand Down
23 changes: 0 additions & 23 deletions src/url/serpentine+nettlesome-url.scala

This file was deleted.

5 changes: 1 addition & 4 deletions src/url/soundness+nettlesome-url.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@

package soundness

export nettlesome.{url, email, host, Authority, Hyperlink, Raw, Scheme, Url, UrlError, HttpUrl}

package pathHierarchies:
export serpentine.pathHierarchies.urls
export nettlesome.{url, email, host, Authority, Raw, Scheme, Url, UrlError, HttpUrl}

0 comments on commit e5ff507

Please sign in to comment.