anchorman-play


License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.davegurnell
ArtifactId

ArtifactId

anchorman-play_2.12
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

anchorman-play
anchorman-play
Project URL

Project URL

https://github.com/davegurnell/anchorman
Project Organization

Project Organization

com.davegurnell
Source Code Management

Source Code Management

https://github.com/davegurnell/anchorman.git

Download anchorman-play_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.davegurnell/anchorman-play_2.12/ -->
<dependency>
    <groupId>com.davegurnell</groupId>
    <artifactId>anchorman-play_2.12</artifactId>
    <version>0.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.davegurnell/anchorman-play_2.12/
implementation 'com.davegurnell:anchorman-play_2.12:0.7.0'
// https://jarcasting.com/artifacts/com.davegurnell/anchorman-play_2.12/
implementation ("com.davegurnell:anchorman-play_2.12:0.7.0")
'com.davegurnell:anchorman-play_2.12:jar:0.7.0'
<dependency org="com.davegurnell" name="anchorman-play_2.12" rev="0.7.0">
  <artifact name="anchorman-play_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.davegurnell', module='anchorman-play_2.12', version='0.7.0')
)
libraryDependencies += "com.davegurnell" % "anchorman-play_2.12" % "0.7.0"
[com.davegurnell/anchorman-play_2.12 "0.7.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.12
com.davegurnell : anchorman-core_2.12 jar 0.7.0

provided (2)

Group / Artifact Type Version
com.typesafe.play : play-ws_2.12 jar 2.7.4
com.typesafe.play : play-ahc-ws_2.12 jar 2.7.4

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.1.0

Project Modules

There are no modules declared in this project.

Anchorman

Report generation library. Produces downloadable documents (DOCX, HTML, etc) from a Scala AST. Early alpha status. Work in progress.

Copyright 2016 Dave Gurnell. Licensed Apache 2.

Build Status Coverage status Maven Central

Getting Started

Grab the code from Bintray by adding the following to your build.sbt:

libraryDependencies ++= Seq(
  "com.davegurnell" %% "anchorman-core" % "<<VERSION>>", // You definitely need this
  "com.davegurnell" %% "anchorman-play" % "<<VERSION>>", // To download images in Play
)

Synopsis

Anchorman lets you generate "reports" (downloadable documents) for your web apps. First build an AST representing the document you want to write:

import anchorman.core._
import anchorman.syntax._

val doc: Document = document(
  para(
    """
    |This is a paragraph. Isn't it lovely?
    |But wait! There's more!
    """.trim.stripMargin
  ),
  para(
    """
    |The style modifier below centers this paragraph.
    """.trim.stripMargin
  ).align(TextAlign.Center),
  olist(
    item("This is a numbered list."),
    item("Amazing!"),
    item("Just like good old HTML"),
  )
)

Then "render" that document using a writer. Here's an HTML example:

import java.io.File

import anchorman.html._
import cats.implicits._

import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

val htmlWriter = new HtmlWriter[Future]()

val file = new File("doc.html")

val future: Future[Unit] =
  htmlWriter.write(doc, file)

Await.result(future, 5.seconds)

There's also a writer for DOCX files that needs a "media downloader" to download and cache images. We provide an implementation that uses the standalone version of play-ws, but you can code your own relatively easily. We'd happily accept a PR for an sttp client ;)

import java.io.File

import akka.actor._
import anchorman.core._
import anchorman.docx._
import anchorman.media._
import cats.implicits._
import org.scalatest._
import play.api.libs.ws.ahc._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
import scala.concurrent.duration._

implicit val system: ActorSystem =
  ActorSystem("Anchorman")

val wsClient = StandaloneAhcWSClient()
val mediaDownloader = new WsClientMediaDownloader(wsClient)
val docxWriter = new DocxWriter[Future](mediaDownloader)

val future: Future[Unit] =
  htmlWriter.write(doc, file)

Await.result(future, 5.seconds)

Versions

Version
0.7.0
0.6.1
0.5.0
0.4.0