anchorman-core


License

License

Categories

Categories

ORM Data
GroupId

GroupId

com.davegurnell
ArtifactId

ArtifactId

anchorman-core_2.13
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

anchorman-core
anchorman-core
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-core_2.13

How to add to project

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

Dependencies

compile (7)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
com.davegurnell : unindent_2.13 jar 1.3.1
com.outr : hasher_2.13 jar 1.2.2
joda-time : joda-time jar 2.10.5
org.apache.xmlgraphics : fop jar 2.1
org.scala-lang.modules : scala-xml_2.13 jar 1.2.0
org.typelevel : cats-core_2.13 jar 2.1.0

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 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