Skip to content

Commit

Permalink
Update README and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tindzk committed Oct 4, 2020
1 parent 644a2f1 commit 94fdf9a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
[![Build Status](http://ci.sparse.tech/api/badges/sparsetech/pine/status.svg)](http://ci.sparse.tech/sparsetech/pine)
[![Maven Central](https://img.shields.io/maven-central/v/tech.sparse/pine_2.12.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22tech.sparse%22%20AND%20a%3A%22pine_2.12%22)

Pine is a functional HTML5 and XML library for the Scala platform. It supports parsing, manipulating and rendering of HTML. Pine provides type-safe bindings for HTML5 generated from [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element). It implements an immutable tree which can be created directly from compile-time or runtime HTML/XML content. The tree may be manipulated and rendered back as HTML or as a browser node.
Pine is a functional HTML5 and XML library for the Scala platform. It supports parsing, manipulating and rendering of HTML. Pine provides type-safe bindings for HTML5 generated from [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element). Tree nodes are immutable and can be constructed from compile-time or runtime HTML/XML content. The tree may be manipulated and rendered back as HTML or as a browser node.

## Features
* Immutable and typed trees
* Type-safe bindings, generated from MDN
* Support for custom elements and attributes
* HTML5 and XML parser (recursive descent)
* HTML5 and XML parser based on recursive descent
* Macros for compile-time HTML string/file parsing
* Tree manipulation
* Rendering as HTML strings
* DSL for common operations
* Unit and property-based tests
* Few dependencies

### JavaScript backend
### JavaScript back end
* Rendering as DOM nodes
* Updating nodes in DOM
* DSL for attaching/detaching events
Expand All @@ -27,7 +27,7 @@ Pine is a functional HTML5 and XML library for the Scala platform. It supports p
|:---------------|:-----------------|
| JVM | 2.11, 2.12, 2.13 |
| JavaScript (1) | 2.11, 2.12, 2.13 |
| LLVM | 2.11 |
| Native | 2.11 |

* (1) Adds support for browser DOM

Expand Down Expand Up @@ -80,7 +80,7 @@ addCompilerPlugin("org.scala-native" % "nscplugin" % nativeVersion cross CrossVe
### Dependencies
```scala
libraryDependencies += "tech.sparse" %% "pine" % "0.1.3" // JVM
libraryDependencies += "tech.sparse" %%% "pine" % "0.1.3" // JavaScript, LLVM
libraryDependencies += "tech.sparse" %%% "pine" % "0.1.3" // JavaScript, Native
```

## Links
Expand Down
11 changes: 5 additions & 6 deletions docs/1-tree-construction.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ As per the XML specification, Pine supports only the following four entities:
* `>` (`>`)
* `&` (`&`)

The underlying data structures are the same for both HTML and XML trees. Pine strives for simplicity and performance at the cost of implementing only a subset of XML's features. Please refer to [scala-xml](https://github.com/scala/scala-xml) for a more complete implementation.
The underlying data structures are the same for HTML and XML trees. Pine strives for simplicity and performance at the cost of implementing only a subset of XML's features. Please refer to [scala-xml](https://github.com/scala/scala-xml) for a more complete implementation.

At the moment, we are aware of the following parser limitations:

- The XML header is optional and its attributes are ignored. The input is expected to be in UTF-8 regardless of the specified character set.
- [DTDs](https://docstore.mik.ua/orelly/web2/xhtml/ch15_03.htm) are not supported. Therefore, additional entity or element declarations cannot be defined.
- Processing instructions (other than `<?xml ... ?>`) are not supported
- CDATA tags are not supported (see issue #37)

## Conversion
Some functions return `Tag[_]` when the tag type cannot be statically determined. A more concrete type is useful if you want to access element-specific attributes, like `href` on anchor nodes. You can use `as` to convert a tag to its correct type:
Expand All @@ -126,7 +125,7 @@ type CustomType = "custom-type"
val CustomType = Tag("CustomType")
```

The feature we use here is called a literal type which is provided by the Typelevel Scala compiler.
The compiler feature we use here are literal types. Originally developed within Typelevel Scala, it is now part of Lightbend Scala 2.13 onwards.

Additionally, you can define methods to access attributes conveniently:

Expand Down Expand Up @@ -177,8 +176,8 @@ tag.Div.dataLanguage(Language.Spanish)
```

## Rendering
A node defines two rendering methods:
A node has several rendering methods:

- **HTML:** `toHtml` is defined on every node and will return the tree as an HTML5 string. If the root node is an `<html>` tag, the `DOCTYPE` will be included as well.
* **XML:** `toXml` returns the tree as an XML 1.0 string. It always includes the XML header, specifying the encoding as UTF-8.
- **DOM:** `toDom` is only available in JavaScript; it renders the tree as a browser node, which can be inserted into the DOM
- **XML:** `toXml` returns the tree as an XML 1.0 string. It always includes the XML header, specifying the encoding as UTF-8.
- **DOM:** `toDom` is only available in JavaScript. It renders the tree as a browser node, which can be inserted into the DOM.
7 changes: 3 additions & 4 deletions docs/2-tree-updates.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Tree updates
## Operations
A `Node` is equipped with a variety of functions to easily manipulate trees such as `prepend`, `append`, `remove`, `clearAll`, `filter`, `flatMap`, `map` and others. See the [source code](https://github.com/sparsetech/pine/blob/master/shared/src/main/scala/pine/Node.scala)
for an overview.
A `Node` is equipped with a variety of functions to easily manipulate trees such as `prepend`, `append`, `remove`, `clearAll`, `filter`, `flatMap`, `map` and others. See the [source code](https://github.com/sparsetech/pine/blob/master/shared/src/main/scala/pine/Node.scala) for an overview.

## Referencing nodes
While the operations from the previous section allow you to modify the tree, they operate on either the root node or are applied recursively to all children.
Expand Down Expand Up @@ -149,14 +148,14 @@ Tags can be referenced using:
* Tag type: `TagRef[tag.A]`
* Class name: `TagRef.byClass[tag.A]("class-name")`

A `TagRef` exposes methods for manipulating nodes and their attributes. See its [source code](https://github.com/sparsetech/pine/blob/master/shared/src/main/scala/pine/TagRef.scala) for a full list of operations.
A `TagRef` exposes methods for manipulating nodes and their attributes. See its [source code](https://github.com/sparsetech/pine/tree/master/src/main/scala/pine/TagRef.scala) for a full list of operations.

## Diffs
A `Diff` is an immutable object which describes tree changes. It is instantiated for example by the `TagRef` operations you have seen before such as `:=` (`set`), `replace` etc.

So far, these changes were performed directly on the tree. However, for the JavaScript back end, we have an additional rendering context that can apply those changes to the DOM. This will be explained in the next chapter.

The full list of supported diffs can be found [here](https://github.com/sparsetech/pine/blob/master/shared/src/main/scala/pine/Diff.scala).
The full list of supported diffs can be found [here](https://github.com/sparsetech/pine/tree/master/src/main/scala/pine/Diff.scala).

### Multiple occurrences
If you would like to perform a change on all occurrences of a `TagRef`, use the `each` function:
Expand Down
2 changes: 1 addition & 1 deletion docs/5-manual.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Development
[![Build Status](https://api.travis-ci.org/sparsetech/pine.svg)](https://travis-ci.org/sparsetech/pine)
[![Build Status](https://travis-ci.org/sparsetech/pine.svg?branch=master)](https://travis-ci.org/sparsetech/pine)

## Manual
The manual was generated using [Instructor](https://github.com/sparsetech/instructor). Follow its installation instructions, then run the following command:
Expand Down

0 comments on commit 94fdf9a

Please sign in to comment.