Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ppurang/abctemplates
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.1.0-RC4
Choose a base ref
...
head repository: ppurang/abctemplates
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: scala3
Choose a head ref

Commits on Apr 1, 2021

  1. release 3.0.0-RC4

    ppurang committed Apr 1, 2021
    Copy the full SHA
    084a042 View commit details

Commits on Apr 4, 2021

  1. Copy the full SHA
    1fb7a6e View commit details

Commits on Apr 5, 2021

  1. Merge pull request #18 from scala-steward/update/sbt-1.5.0

    Update sbt, sbt-dependency-tree to 1.5.0
    ppurang authored Apr 5, 2021
    Copy the full SHA
    447f16f View commit details
  2. Copy the full SHA
    a721eab View commit details
  3. sbt slash syntax

    ppurang committed Apr 5, 2021
    Copy the full SHA
    f609ba2 View commit details

Commits on Apr 10, 2021

  1. Copy the full SHA
    1f68bbe View commit details

Commits on Apr 12, 2021

  1. Merge pull request #19 from scala-steward/update/cats-effect-3.0.2

    Update cats-effect to 3.0.2
    ppurang authored Apr 12, 2021
    Copy the full SHA
    93bc5f1 View commit details

Commits on Apr 19, 2021

  1. Update munit to 0.7.25

    scala-steward committed Apr 19, 2021
    Copy the full SHA
    a1692f4 View commit details

Commits on Apr 20, 2021

  1. Copy the full SHA
    5dc5783 View commit details

Commits on Apr 22, 2021

  1. Merge pull request #20 from scala-steward/update/munit-0.7.25

    Update munit to 0.7.25
    ppurang authored Apr 22, 2021
    Copy the full SHA
    7bbf748 View commit details
  2. Copy the full SHA
    0f613df View commit details
  3. Merge pull request #21 from scala-steward/update/cats-effect-3.1.0

    Update cats-effect to 3.1.0
    ppurang authored Apr 22, 2021
    Copy the full SHA
    d6e9942 View commit details

Commits on Apr 26, 2021

  1. Copy the full SHA
    4529086 View commit details

Commits on Apr 28, 2021

  1. Merge pull request #23 from scala-steward/update/sbt-1.5.1

    Update sbt, sbt-dependency-tree to 1.5.1
    ppurang authored Apr 28, 2021
    Copy the full SHA
    82f5c13 View commit details

Commits on May 10, 2021

  1. Copy the full SHA
    f1a81dd View commit details

Commits on May 23, 2021

  1. Merge pull request #24 from scala-steward/update/sbt-1.5.2

    Update sbt, sbt-dependency-tree to 1.5.2
    ppurang authored May 23, 2021
    Copy the full SHA
    d8d5c70 View commit details

Commits on Jun 1, 2021

  1. Copy the full SHA
    618a3a5 View commit details
  2. Merge pull request #25 from scala-steward/update/sbt-1.5.3

    Update sbt, sbt-dependency-tree to 1.5.3
    ppurang authored Jun 1, 2021
    Copy the full SHA
    4ba0367 View commit details

Commits on Jun 14, 2021

  1. Copy the full SHA
    a6708dc View commit details
  2. Merge pull request #26 from scala-steward/update/sbt-1.5.4

    Update sbt, sbt-dependency-tree to 1.5.4
    ppurang authored Jun 14, 2021
    Copy the full SHA
    342edf2 View commit details

Commits on Jun 20, 2021

  1. scala 3 + sbt 1.5.4

    ppurang committed Jun 20, 2021
    Copy the full SHA
    92a31e0 View commit details

Commits on Jul 2, 2021

  1. Update munit to 0.7.27

    scala-steward committed Jul 2, 2021
    Copy the full SHA
    a8f969b View commit details

Commits on Jul 7, 2021

  1. Merge pull request #27 from scala-steward/update/munit-0.7.27

    Update munit to 0.7.27
    ppurang authored Jul 7, 2021
    Copy the full SHA
    2a889b9 View commit details

Commits on Jul 9, 2021

  1. Copy the full SHA
    1b224f9 View commit details

Commits on Jul 10, 2021

  1. Update jsoup to 1.14.1

    scala-steward committed Jul 10, 2021
    Copy the full SHA
    4ed9ec7 View commit details

Commits on Jul 12, 2021

  1. Copy the full SHA
    42aa042 View commit details
  2. Merge pull request #28 from scala-steward/update/scala3-library-3.0.1

    Update scala3-library to 3.0.1
    ppurang authored Jul 12, 2021
    Copy the full SHA
    79d20b3 View commit details
  3. Merge pull request #29 from scala-steward/update/jsoup-1.14.1

    Update jsoup to 1.14.1
    ppurang authored Jul 12, 2021
    Copy the full SHA
    e54c7b8 View commit details
  4. Merge pull request #30 from scala-steward/update/sbt-1.5.5

    Update sbt, sbt-dependency-tree to 1.5.5
    ppurang authored Jul 12, 2021
    Copy the full SHA
    a840e76 View commit details

Commits on Jul 25, 2021

  1. Copy the full SHA
    0c2912c View commit details
  2. Merge pull request #31 from scala-steward/update/cats-effect-3.2.0

    Update cats-effect to 3.2.0
    ppurang authored Jul 25, 2021
    Copy the full SHA
    bfbc12c View commit details

Commits on Jul 31, 2021

  1. Copy the full SHA
    9d25d6f View commit details

Commits on Aug 3, 2021

  1. Merge pull request #32 from scala-steward/update/cats-effect-3.2.1

    Update cats-effect to 3.2.1
    ppurang authored Aug 3, 2021
    Copy the full SHA
    7f39f82 View commit details

Commits on Aug 6, 2021

  1. Copy the full SHA
    93b2367 View commit details

Commits on Aug 9, 2021

  1. Update munit to 0.7.28

    scala-steward committed Aug 9, 2021
    Copy the full SHA
    044ca3a View commit details

Commits on Aug 10, 2021

  1. Merge pull request #34 from scala-steward/update/munit-0.7.28

    Update munit to 0.7.28
    ppurang authored Aug 10, 2021
    Copy the full SHA
    f657e32 View commit details
  2. Copy the full SHA
    37c5450 View commit details
  3. Copy the full SHA
    be452ac View commit details
  4. Merge pull request #33 from scala-steward/update/cats-effect-3.2.2

    Update cats-effect to 3.2.2
    ppurang authored Aug 10, 2021
    Copy the full SHA
    79e6f85 View commit details

Commits on Aug 15, 2021

  1. Copy the full SHA
    3b5e616 View commit details
  2. Update jsoup to 1.14.2

    scala-steward committed Aug 15, 2021
    Copy the full SHA
    dd4ce55 View commit details
  3. Merge pull request #35 from scala-steward/update/sbt-sonatype-3.9.9

    Update sbt-sonatype to 3.9.9
    ppurang authored Aug 15, 2021
    Copy the full SHA
    263c7e7 View commit details
  4. Merge pull request #36 from scala-steward/update/jsoup-1.14.2

    Update jsoup to 1.14.2
    ppurang authored Aug 15, 2021
    Copy the full SHA
    7623901 View commit details

Commits on Aug 16, 2021

  1. Copy the full SHA
    4423504 View commit details

Commits on Aug 18, 2021

  1. Merge pull request #37 from scala-steward/update/cats-effect-3.2.3

    Update cats-effect to 3.2.3
    ppurang authored Aug 18, 2021
    Copy the full SHA
    e5a0d6b View commit details

Commits on Aug 19, 2021

  1. Copy the full SHA
    098d5b5 View commit details
  2. Copy the full SHA
    3c949d9 View commit details

Commits on Aug 25, 2021

  1. Merge pull request #38 from scala-steward/update/scalafmt-core-3.0.0

    Update scalafmt-core to 3.0.0
    ppurang authored Aug 25, 2021
    Copy the full SHA
    daf4a5c View commit details
  2. Copy the full SHA
    d3b095d View commit details

Commits on Aug 31, 2021

  1. Update munit to 0.7.29

    scala-steward committed Aug 31, 2021
    Copy the full SHA
    9fb3905 View commit details
11 changes: 10 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
version = 2.7.5
runner.dialect = scala3
version = 3.7.1
maxColumn = 120
align.preset = most
spaces.inImportCurlyBraces = true
rewrite.rules = [SortModifiers]
rewrite.redundantBraces.stringInterpolation = true

assumeStandardLibraryStripMargin = true
align.stripMargin = true
2 changes: 1 addition & 1 deletion aliases.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Util._
import OurUtil._

addCommandAlias("l", "projects")
addCommandAlias("ll", "projects")
36 changes: 25 additions & 11 deletions build.sbt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
ThisBuild / name := "abctemplates"

ThisBuild / version := "3.1.0-RC3" //we will follow milestones from scala effect 3
ThisBuild / version := "3.3.1" //we will follow milestones from scala effect 3

ThisBuild / organization := "org.purang.templates"

ThisBuild / scalaVersion := "3.0.0-RC2"
ThisBuild / scalaVersion := "3.3.1"

ThisBuild / crossScalaVersions := Seq("3.3.1", "2.13.12")

ThisBuild / versionScheme := Some("early-semver")
ThisBuild / fork := true
ThisBuild / logBuffered := false
ThisBuild / Test / parallelExecution := true

ThisBuild / scalacOptions ++= Seq(
"-encoding",
@@ -13,14 +20,21 @@ ThisBuild / scalacOptions ++= Seq(
"-unchecked",
"-Xfatal-warnings",
"-deprecation",
"-language:implicitConversions",
"-Ykind-projector"
)
"-language:implicitConversions"
) ++ {
if (scalaVersion.value.matches("^3.")) {
Seq("-Ykind-projector")
} else if (scalaVersion.value.matches("^2.12")) {
Seq("-language:higherKinds")
} else {
Seq()
}
}

ThisBuild / libraryDependencies ++= Seq(
"org.jsoup" % "jsoup" % "1.13.1",
"org.typelevel" %% "cats-effect" % "3.0.1",
"org.scalameta" %% "munit" % "0.7.23" % Test
"org.jsoup" % "jsoup" % "1.16.1",
"org.typelevel" %% "cats-effect" % "3.5.1",
"org.scalameta" %% "munit" % "0.7.29" % Test
).map(_ withSources ())

ThisBuild / testFrameworks += new TestFramework("munit.Framework")
@@ -29,8 +43,8 @@ ThisBuild / licenses += ("BSD", url(
"http://www.tldrlegal.com/license/bsd-3-clause-license-%28revised%29"
))

This / sources in (sbt.Compile, doc) := Seq()
ThisBuild / publishArtifact in packageSrc := true
ThisBuild / publishArtifact in packageSrc in Test := false
(ThisBuild / sbt.Compile / doc / sources) := Seq()
(ThisBuild / packageSrc / publishArtifact) := true
(ThisBuild / Test / packageSrc / publishArtifact) := false

publishTo := sonatypePublishToBundle.value
2 changes: 1 addition & 1 deletion project/Util.scala → project/OurUtil.scala
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ import scala.sys.process._

import sbt._

object Util {
object OurUtil {
def styled(in: Any): String =
scala.Console.CYAN + in + scala.Console.RESET

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.4.9
sbt.version=1.9.6
12 changes: 8 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")

addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.4")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")

addDependencyTreePlugin

addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.0")

addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.15.0")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3")
4 changes: 2 additions & 2 deletions sbt.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Util._
import OurUtil._

Global / onChangedBuildSource := ReloadOnSourceChanges
Global / lintUnusedKeysOnLoad := false
@@ -31,6 +31,6 @@ ThisBuild / fork := true

ThisBuild / logBuffered := false

ThisBuild / parallelExecution in Test := true
ThisBuild / Test / parallelExecution := true

//ThisBuild / scalafmtOnCompile := true
6 changes: 4 additions & 2 deletions sonatype.sbt
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ publishMavenStyle := true

// Where is the source code hosted: GitHub or GitLab?
import xerial.sbt.Sonatype._
sonatypeProjectHosting := Some(GitHubHosting("ppurang", "abctemplates", "ppurang@gmail.com"))
sonatypeProjectHosting := Some(
GitHubHosting("ppurang", "abctemplates", "ppurang@gmail.com")
)

// or if you want to set these fields manually
//homepage := Some(url("https://(your project url)"))
@@ -19,4 +21,4 @@ sonatypeProjectHosting := Some(GitHubHosting("ppurang", "abctemplates", "ppurang
//)
//developers := List(
// Developer(id="(your id)", name="(your name)", email="(your e-mail)", url=url("(your home page)"))
//)
//)
13 changes: 6 additions & 7 deletions src/main/scala/org/purang/templates/abc/DataTypes.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.purang.templates.abc

final case class Pattern(p: String) extends AnyVal
final case class Template(c: String) extends AnyVal
final case class Result(r: String) extends AnyVal
final case class Pattern(p: String) extends AnyVal
final case class Template(c: String) extends AnyVal
final case class Result(r: String) extends AnyVal
final case class Namespace(ns: String) extends AnyVal

sealed abstract class SubstitutionPattern {
def isAttributePattern: Boolean
}

final case class AttributePattern(pattern: Pattern)
extends SubstitutionPattern {
final case class AttributePattern(pattern: Pattern) extends SubstitutionPattern {
override val isAttributePattern: Boolean = true
override def toString: String = s"a.[${pattern.p}]"
override def toString: String = s"a.[${pattern.p}]"
}

final case class ElementPattern(pattern: Pattern) extends SubstitutionPattern {
override val isAttributePattern: Boolean = false
override def toString: String = s"[${pattern.p}]"
override def toString: String = s"[${pattern.p}]"
}
4 changes: 2 additions & 2 deletions src/main/scala/org/purang/templates/abc/JsoupTemplates.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.purang.templates.abc

import cats._
import org.purang.templates.abc.unsafe.{Template => UnsafeTemplate}
import org.purang.templates.abc.unsafe.{ Template => UnsafeTemplate }

object JsoupTemplates {

//def default[F[+_]: [M[_]] =>> ApplicativeError[M, Throwable]]: TemplateAlgebra[F] = new TemplateAlgebra[F] {
// def default[F[+_]: [M[_]] =>> ApplicativeError[M, Throwable]]: TemplateAlgebra[F] = new TemplateAlgebra[F] {
def default[F[+_]](implicit F: ApplicativeError[F, Throwable]): Templates[F] =
new Templates[F] {

25 changes: 13 additions & 12 deletions src/main/scala/org/purang/templates/abc/unsafe/Template.scala
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import scala.util.matching.Regex
import cats.syntax.all._
//import cats.syntax.traverse._
import cats.Monoid.combineAll
import cats.implicits._

class Template private[unsafe] (private val contents: String) {

@@ -19,17 +18,16 @@ class Template private[unsafe] (private val contents: String) {
Jsoup.parse(contents, "", Parser.xmlParser()).outputSettings(settings)
m.foreach { case (k, v) =>
if (k.startsWith(ATTRIBUTE + ".")) {
val a: String = k.replaceFirst(ATTRIBUTE + ".", "")
val NS_ATTRIBUTE(_, ns, pattr) =
a // div[abc:href] => div && abc:href && href
val a: String = k.replaceFirst(ATTRIBUTE + ".", "")
val NS_ATTRIBUTE(_, ns, pattr) = a: @unchecked // div[abc:href] => div && abc:href && href
document
.select(a)
.attr(pattr, v)
.removeAttr(
s"$ns:$pattr"
) //select("div[abc:href]").attr("href", "somev").remove("abc:href")
) // select("div[abc:href]").attr("href", "somev").remove("abc:href")
} else {
val ELAT(_, attr) = k
val ELAT(_, attr) = k: @unchecked
document.select(k).html(v).removeAttr(attr)
}
}
@@ -38,22 +36,25 @@ class Template private[unsafe] (private val contents: String) {

def embeddedTemplate(cssQuery: String): Option[String] = {
Either.catchNonFatal {
//todo too many documents initialized for #embeddedTemplates
// todo too many documents initialized for #embeddedTemplates
val document: Document =
Jsoup.parse(contents, "", Parser.xmlParser()).outputSettings(settings)
document.select(cssQuery).first().outerHtml()
}.toOption
}

def embeddedTemplates(cssQueries: List[String]): Option[String] = (for {
cssQuery <- cssQueries
} yield embeddedTemplate(cssQuery)).sequence.map(l => combineAll(l))
def embeddedTemplates(cssQueries: List[String]): Option[String] = {
val value: List[Option[String]] = for {
cssQuery <- cssQueries
} yield embeddedTemplate(cssQuery)
value.sequence.map(l => combineAll(l)) // 2.13.x compatibility
}

}

object Template {
val ATTRIBUTE: String = "a"
private val ELAT: Regex = """(.*)\[(.*)]""".r
val ATTRIBUTE: String = "a"
private val ELAT: Regex = """(.*)\[(.*)]""".r
private val NS_ATTRIBUTE: Regex = """(.*)\[(.*):(.*)]""".r

private val settings: Document.OutputSettings =
31 changes: 15 additions & 16 deletions src/test/scala/TemplatesApp.scala
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
import org.purang.templates.abc._
import org.purang.templates.abc.unsafe.Template._
import cats.Monad
import cats.effect.{ExitCode, IO, IOApp}
import cats.effect.{ ExitCode, IO, IOApp }
import cats.syntax.flatMap._
import cats.syntax.functor._

object TemplatesApp extends IOApp {

def prg[F[+_] : Monad](talg: Templates[F]): F[(Result, Boolean)] = {
def prg[F[+_]: Monad](talg: Templates[F]): F[(Result, Boolean)] = {
for {
t <- talg.template(
"""|<div id="content" abc:content>
| <p>
| some imaginary data for instant visualization in the browser
| </p>
|</div>""".stripMargin)
t <- talg.template("""|<div id="content" abc:content>
| <p>
| some imaginary data for instant visualization in the browser
| </p>
|</div>""".stripMargin)
m <- talg.merge(
t,
Map(
ElementPattern(Pattern("abc:content")) -> "<b>What's Up Folks!<b>"
)
)
t,
Map(
ElementPattern(Pattern("abc:content")) -> "<b>What's Up Folks!<b>"
)
)
v <- talg.validate(m, Namespace("abc"))
} yield (m, v)
}

def run(args: List[String]): IO[ExitCode] = {
(for {
t <- prg[IO](JsoupTemplates.default)
t <- prg[IO](JsoupTemplates.default[IO]) // 2.13.x compatibility
_ <- IO {
println(t)
}
println(t)
}
} yield ()).as(ExitCode.Success)
}
}
23 changes: 12 additions & 11 deletions src/test/scala/UnsafeMain.scala
Original file line number Diff line number Diff line change
@@ -5,27 +5,28 @@ object UnsafeMain {
def main(args: Array[String]): Unit = {

val h: String = """
|<div id="content" abc:content>
| <p>
| some imaginary data for instant visualization in the browser
| </p>
|</div>
|<div id="content" abc:content>
| <p>
| some imaginary data for instant visualization in the browser
| </p>
|</div>
""".stripMargin

val template = Template(h)

val context: Map[String, String] = Map(
"[abc:content]" // identifier in the template
"[abc:content]" // identifier in the template
->
"<h1>the real content!</h1>" // the new inner html contents
)

// merge template with a context
val result: String = template.merge(context)
//result should be (note: <p> tags have been dropped)
// <div id="content">
// <h1>the real content!</h1>
// </div>
assert(result.contains("<h1>the real content!</h1>"))
// result should be (note: <p> tags have been dropped)
// <div id="content"><h1>the real content!</h1></div>
println(result)
assert(h.contains("p>"), "'h' doesn't contain <p>?")
assert(result.contains("<h1>the real content!</h1>"), "'result' doesn't contain '<h1>the real content!</h1>'?")
assert(!result.contains("p>"), "'result' does contain <p>?")
}
}
Loading