Skip to content

Commit

Permalink
docs: #188 Reflect changes in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rlemaitre committed Dec 3, 2024
1 parent 91d7c42 commit f6bb9ef
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
9 changes: 4 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.typelevel.sbt.gha.Permissions
import xerial.sbt.Sonatype.GitHubHosting
import xerial.sbt.Sonatype.sonatypeCentralHost

ThisBuild / tlBaseVersion := "0.3" // your current series x.y

Expand Down Expand Up @@ -244,10 +243,10 @@ lazy val example = Project("pillars-example", file("modules/example"))
.settings(
name := "pillars-example", // //<2>
description := "pillars-example is an example of application using pillars", // //<3>
libraryDependencies ++= Dependencies.tests ++ Dependencies.migrationsRuntime,
buildInfoKeys := Seq[BuildInfoKey](name, version, description), // //<4>
buildInfoOptions := Seq(BuildInfoOption.Traits("pillars.BuildInfo")), // //<5>
buildInfoPackage := "example.build", // //<6>
libraryDependencies ++= Dependencies.tests ++ Dependencies.migrationsRuntime, // //<4>
buildInfoKeys := Seq[BuildInfoKey](name, version, description), // //<5>
buildInfoOptions := Seq(BuildInfoOption.Traits("pillars.BuildInfo")), // //<6>
buildInfoPackage := "example.build", // //<7>
publish / skip := true,
tlMimaPreviousVersions := Set.empty,
libraryDependencySchemes ++= libDependencySchemes
Expand Down
4 changes: 4 additions & 0 deletions modules/core/src/main/scala/pillars/graph.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2024-2024 by Raphaël Lemaitre and Contributors
// This software is licensed under the Eclipse Public License v2.0 (EPL-2.0).
// For more information see LICENSE or https://opensource.org/license/epl-2-0

package pillars

import io.github.iltotore.iron.*
Expand Down
29 changes: 19 additions & 10 deletions modules/docs/src/docs/user-guide/10_quick-start.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ First, you need to create a xref:20_features/10_configuration.adoc[configuration
You can find an example in the `modules/example/src/main/resources/application.conf` file.


Then, you can create your entry point by extending the `EntryPoint` trait:
Then, you can create your entry point by extending the `pillars.IOApp` trait:

[source,scala,linenums,role="data-noescape"]
----
include::{projectRootDir}/modules/example/src/main/scala/example/app.scala[tag=quick-start]
----
<1> The `EntryPoint` trait is a simple trait that provides a `main` method and initialize the `Pillars` instance.
<2> The `pillars.App[IO]` must contain your application logic
<3> `infos` defines some metadata about your application.
<2> `infos` defines some metadata about your application.
It is used by the admin server to display information about your application.
See
<4> The `run` is the entry point of your application. Here, you have access to the `Pillars` instance.
See <<Application Metadata>> for more information.
<3> The `run` is the entry point of your application.
Thanks to the `Run[F[_], T]` context function, you have access to a `Pillars[F]` instance that contains all your modules.
<4> Each module is accessible through the `Pillars` instance or through a top-level function in the module's package.
The `dbMigration.migrate` function is a top-level function that is provided by the `db-migration` module.
<5> The API server must be started with the `server.start` function with the controllers you want to expose.

Then, you can run your application. For example, you can run it with `sbt`:

Expand Down Expand Up @@ -133,19 +136,25 @@ include::{projectRootDir}/build.sbt[tag=example]
<1> Enable the `BuildInfo` plugin
<2> Define the name of your application
<3> Define the description of your application
<4> Tell buildinfo to generate the `BuildInfo` object including at least `name`, `description` and `version` properties.
<4> Declare the dependencies you want to use in your app.
<5> Tell buildinfo to generate the `BuildInfo` object including at least `name`, `description` and `version` properties.
In this specific case, `version` is defined by the link:https://github.com/sbt/sbt-dynver[sbt-dynver] plugin.
<5> Configure BuildInfo to implement the `pillars.BuildInfo` trait.
<6> Configure BuildInfo to implement the `pillars.BuildInfo` trait.
It is required to use the `BuildInfo` object in your application.
<6> Specify in which package will be generated the `BuildInfo` object.
<7> Specify in which package will be generated the `BuildInfo` object.

[CAUTION]
====
If you use the `db-migration` module, you have to add a dependency to your JDBC driver and possibly to a flyway
specific library for your DB (`org.flyway:flyway-postgresql` for PostgreSQL for example).
====

Then, you can use the `BuildInfo` object in your application:

[source,scala,linenums,role="data-noescape"]
----
import example.build.BuildInfo
val app = new App[IO]:
override val infos = BuildInfo.toAppInfo
override def run(pillars: Pillars[IO]): IO[Unit] = ???
override def run(): Run[IO, IO[Unit]] = ???
----
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include::{projectRootDir}/modules/example/src/main/resources/config.yaml[tag=pil
----

[NOTE]
If you are using the `EntryPoint` trait, the path to this file must be given to the application using the `--config` command line option.
When using the `pillars.IOApp` trait, the path to this file must be given to the application using the `--config` command line option.

The config *must* contain the following keys:

Expand Down
37 changes: 18 additions & 19 deletions modules/docs/src/site/doc/landingpage.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@
<code class="language-scala">
import ... // import your dependencies

object app extends pillars.EntryPoint:
def app: pillars.App[IO] = new: // define your app
def infos: AppInfo = BuildInfo.toAppInfo // automatic description from your build
object app extends pillars.IOApp(DB, DBMigration, FeatureFlags, HttpClient): //define your apps modules
def infos: AppInfo = BuildInfo.toAppInfo // automatic description from your build

def run: Run[IO, IO[Unit]] = // enjoy!
for
_ <- Logger[IO].info(s"📚 Welcome to \${Config[IO].name}!")
_ <- DBMigration[IO].migrate("db/migrations")
_ <- flag"feature-1".whenEnabled:
DB[IO].use: session =>
for
date <- session.unique(sql"select now()".query(timestamptz))
_ <- Logger[IO].info(s"The current date is \$date.")
yield ()
_ <- HttpClient[IO].get("https://pillars.dev"): response =>
Logger[IO].info(s"Response: \${response.status}")
_ <- ApiServer[IO].start(endpoints.all)
yield ()
end for
end run
def run: Run[IO, IO[Unit]] = // enjoy!
for
_ <- logger.info(s"📚 Welcome to \${Config[IO].name}!") // logging is included in pillars-core
_ <- dbMigration.migrate("classpath:db/migrations") // you can access directly your modules
_ <- flag"feature-1".whenEnabled: // handy feature flag interpolation
db.use: session =>
for
date <- session.unique(sql"select now()".query(timestamptz))
_ <- Logger[IO].info(s"The current date is \$date.")
yield ()
_ <- http.get("https://pillars.dev"): response =>
logger.info(s"Response: \${response.status}")
_ <- server.start(homeController, userController) // start your server with your controllers
yield ()
end for
end run
end app
</code>
</pre>
Expand Down
8 changes: 4 additions & 4 deletions modules/example/src/main/scala/example/app.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import skunk.implicits.*

// tag::quick-start[]
object app extends pillars.IOApp(DB, DBMigration, FeatureFlags, HttpClient): // // <1>
def infos: AppInfo = BuildInfo.toAppInfo // // <3>
def infos: AppInfo = BuildInfo.toAppInfo // // <2>

def run: Run[IO, IO[Unit]] = // // <4>
def run: Run[IO, IO[Unit]] = // // <3>
for
_ <- logger.info(s"📚 Welcome to ${config.name}!")
_ <- dbMigration.migrate("classpath:db-migrations") // // <5>
_ <- dbMigration.migrate("classpath:db-migrations") // // <4>
_ <- flag"feature-1".whenEnabled:
sessions.use: session =>
for
Expand All @@ -37,7 +37,7 @@ object app extends pillars.IOApp(DB, DBMigration, FeatureFlags, HttpClient): //
size <- response.body.compile.count
_ <- logger.info(s"Body: $size bytes")
yield ()
_ <- server.start(homeController, userController) // // <6>
_ <- server.start(homeController, userController) // // <5>
yield ()
end for
end run
Expand Down

0 comments on commit f6bb9ef

Please sign in to comment.