Skip to content

Commit

Permalink
rename package from zio.http.html to zio.http.template to avoid ambig…
Browse files Browse the repository at this point in the history
…uity (#2405)

* rename package from zio.http.html to zio.http.template to avoid ambiguity

* fix import
  • Loading branch information
TomTriple authored Aug 29, 2023
1 parent 25bc720 commit ac3e544
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/dsl/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Response.json("""{"greetings": "Hello World!"}""")

`html` creates a response with data as html, content-type header set to text/html and status code 200
```scala mdoc
import zio.http.html._
import zio.http.template._

Response.html(Html.fromString("html text"))
```
Expand Down
14 changes: 7 additions & 7 deletions docs/dsl/html.md → docs/dsl/template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
id: html
title: Html
id: template
title: Template
---

The package `zio.http.html._` contains lightweight helpers for generating statically typed, safe html similiar in spirit to `scalatags`.
The package `zio.http.template._` contains lightweight helpers for generating statically typed, safe html similiar in spirit to `scalatags`.

## Html and DOM

Expand All @@ -13,7 +13,7 @@ One possible way is to create an instance of `Html` directly from a `String` val
from the compiler:

```scala mdoc:silent
import zio.http.html._
import zio.http.template._

val divHtml1: Html = Html.fromString("""<div class="container1 container2"><a href="http://zio.dev">ZIO Homepage</a></div>""")
```
Expand All @@ -24,7 +24,7 @@ In order to improve on type safety one could use `Html` with `Dom` constructor f
code is much more verbose:

```scala mdoc:silent
import zio.http.html._
import zio.http.template._

val divHtml2: Html = Html.fromDomElement(
Dom.element(
Expand All @@ -48,7 +48,7 @@ elements like `div` or `a` but also html attributes like `hrefAttr` or `styleAtt
are suffixed `attr` to easily distinguish those from html elements:

```scala mdoc:silent
import zio.http.html._
import zio.http.template._

val divHtml3: Html = div(
classAttr := "container1" :: "container2" :: Nil,
Expand All @@ -68,7 +68,7 @@ of `a(hrefAttr := "http://zio.dev", "ZIO Homepage")` one can use `a(hrefAttr("ht
One can compose values of `Html` sequentially using the operator `++` to produce a larger `Html`:

```scala mdoc:silent
import zio.http.html._
import zio.http.template._

val fullHtml: Html = divHtml1 ++ divHtml2 ++ divHtml3
```
Expand Down
2 changes: 1 addition & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const sidebars = {
"dsl/socket/websocketframe"
]
},
"dsl/html"
"dsl/template"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.http._

object HtmlTemplating extends ZIOAppDefault {
// Importing everything from `zio.html`
import zio.http.html._
import zio.http.template._

def app: HttpApp[Any] = {
// Html response takes in a `Html` instance.
Expand Down
2 changes: 1 addition & 1 deletion zio-http-example/src/main/scala/example/StaticServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zio.ZIOAppDefault

import zio.http._
import zio.http.codec.PathCodec.trailing
import zio.http.html._
import zio.http.template._

object StaticServer extends ZIOAppDefault {

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package zio.http

import zio._
import zio.http.html.{Html, Template}
import zio.http.template.{Html, Template}
import zio.http.Header.HeaderType
import zio.http.internal.HeaderModifier
import zio.stream.ZStream
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/HandlerAspect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.nio.charset._
import zio._
import zio.metrics._

import zio.http.html._
import zio.http.template._

/**
* A [[zio.http.HandlerAspect]] is a kind of [[zio.http.ProtocolStack]] that is
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zio/http/Response.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import zio.{Cause, Task, Trace, ZIO}

import zio.stream.ZStream

import zio.http.html.Html
import zio.http.internal.HeaderOps
import zio.http.template.Html

final case class Response(
status: Status = Status.Ok,
Expand Down
10 changes: 5 additions & 5 deletions zio-http/src/main/scala/zio/http/codec/Doc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package zio.http.codec

import zio.stacktracer.TracingImplicits.disableAutoTrace

import zio.http.html
import zio.http.template

/**
* A `Doc` models documentation for an endpoint or input.
Expand Down Expand Up @@ -117,8 +117,8 @@ sealed trait Doc { self =>
writer.toString()
}

def toHtml: html.Html = {
import html._
def toHtml: template.Html = {
import template._

self match {
case Doc.Empty =>
Expand Down Expand Up @@ -347,8 +347,8 @@ object Doc {
case Span.Sequence(left, right) => left.size + right.size
}

def toHtml: html.Html = {
import html._
def toHtml: template.Html = {
import template._

self match {
case Span.Text(value) => value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import zio.http.html.Attributes.PartialAttribute
import zio.http.template.Attributes.PartialAttribute

trait Attributes {
final def acceptAttr: PartialAttribute[String] = PartialAttribute("accept")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

/**
* Light weight DOM implementation that can be rendered as a html string.
Expand All @@ -32,7 +32,7 @@ sealed trait Dom { self =>
def encode(spaces: Int): CharSequence =
encode(EncodingState.Indentation(0, spaces))

private[html] def encode(state: EncodingState): CharSequence = self match {
private[template] def encode(state: EncodingState): CharSequence = self match {
case Dom.Element(name, children) =>
val attributes = children.collect { case self: Dom.Attribute => self.encode }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import zio.http.html.Element.PartialElement
import zio.http.template.Element.PartialElement

trait Elements {
final def a: PartialElement = PartialElement("a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

private[html] sealed trait EncodingState {
private[template] sealed trait EncodingState {
def nextElemSeparator: String
def inner: EncodingState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import scala.language.implicitConversions

Expand All @@ -28,7 +28,7 @@ sealed trait Html { self =>
def encode(spaces: Int): CharSequence =
encode(EncodingState.Indentation(0, spaces))

private[html] def encode(state: EncodingState): CharSequence = {
private[template] def encode(state: EncodingState): CharSequence = {
self match {
case Html.Empty => ""
case Html.Single(element) => element.encode(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

/**
* A ZIO Http styled general purpose templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package zio.http

package object html extends Attributes with Elements {}
package object template extends Attributes with Elements {}
6 changes: 3 additions & 3 deletions zio-http/src/test/scala/zio/http/ServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import zio.test._

import zio.stream.{ZPipeline, ZStream}

import zio.http.html.{body, div, id}
import zio.http.internal.{DynamicServer, HttpGen, HttpRunnableSpec}
import zio.http.template.{body, div, id}

object ServerSpec extends HttpRunnableSpec {

Expand Down Expand Up @@ -367,7 +367,7 @@ object ServerSpec extends HttpRunnableSpec {
test("body") {
val res =
Handler
.html(zio.http.html.html(body(div(id := "foo", "bar"))))
.html(zio.http.template.html(body(div(id := "foo", "bar"))))
.sandbox
.toHttpApp
.deploy
Expand All @@ -377,7 +377,7 @@ object ServerSpec extends HttpRunnableSpec {
assertZIO(res)(equalTo("""<!DOCTYPE html><html><body><div id="foo">bar</div></body></html>"""))
},
test("content-type") {
val app = Handler.html(zio.http.html.html(body(div(id := "foo", "bar")))).sandbox.toHttpApp
val app = Handler.html(zio.http.template.html(body(div(id := "foo", "bar")))).sandbox.toHttpApp
val res = app.deploy.header(Header.ContentType).run()
assertZIO(res)(isSome(equalTo(Header.ContentType(MediaType.text.html))))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import zio.test.{assertTrue, check, checkAll}

import zio.http.ZIOHttpSpec
import zio.http.html.HtmlGen.{tagGen, voidTagGen}
import zio.http.template.HtmlGen.{tagGen, voidTagGen}

object DomSpec extends ZIOHttpSpec {
def spec = suite("DomSpec")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import zio.test.Gen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package zio.http.html
package zio.http.template

import zio.test.Assertion.equalTo
import zio.test._
Expand Down

0 comments on commit ac3e544

Please sign in to comment.