Skip to content

Commit

Permalink
Update docs (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher authored Jan 31, 2024
1 parent f96a873 commit 39d22da
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ You can write your PDFs like you are creating a site using Bootstrap. A Row may
Besides that, pages will be added when content may extrapolate the useful area. You can define a header which will be added
always when a new page appear, in this case, a header may have many rows, lines or tablelist.

#### Maroto `v2.0.0-beta.13` is here! Try out:
#### Maroto `v2.0.0-beta.14` is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.13
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.14
```

* You can see the full `v2` documentation [here](https://maroto.io/).
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

* We are about to create a document processor to generate PDFs by interpreting serialized data as: yml, json or html. Please contribute with your ideas in [this discussion](https://github.com/johnfercher/maroto/discussions/390).

#### 3. Maroto`v2.0.0-beta.13`is here! Try out:
#### 3. Maroto`v2.0.0-beta.14`is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.13
go get github.com/johnfercher/maroto/v2@v2.0.0-beta.14
```

The public API was completely redesigned with the aim of enhancing the
Expand Down
2 changes: 1 addition & 1 deletion docs/_coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](assets/images/logo.png)

# Maroto <small>v2.0.0-beta.13</small>
# Maroto <small>v2.0.0-beta.14</small>

> An open-source golang lib to create PDFs. Fast and Simple.
Expand Down
3 changes: 3 additions & 0 deletions docs/v2/features/footer.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Footer

## GoDoc
* [maroto : RegisterFooter](https://pkg.go.dev/github.com/johnfercher/maroto/v2#Maroto.RegisterFooter)

## Code Example
[filename](../../assets/examples/footer/v2/main.go ':include :type=code')

Expand Down
3 changes: 3 additions & 0 deletions docs/v2/features/header.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Header

## GoDoc
* [maroto : RegisterHeader](https://pkg.go.dev/github.com/johnfercher/maroto/v2#Maroto.RegisterHeader)

## Code Example
[filename](../../assets/examples/header/v2/main.go ':include :type=code')

Expand Down
5 changes: 5 additions & 0 deletions docs/v2/features/list.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# List

## GoDoc
* [interface : Listable](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/list#Listable)
* [list : Build](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/list#Build)
* [list : BuildFromPointer](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/components/list#BuildFromPointer)

## Code Example
[filename](../../assets/examples/list/v2/main.go ':include :type=code')

Expand Down
5 changes: 4 additions & 1 deletion docs/v2/features/mergepdf.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Merge PDF

## GoDoc
* [merge : Bytes](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/merge#Bytes)
* [core : Document](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/core#Document)

## Code Example
[filename](../../assets/examples/mergepdf/v2/main.go ':include :type=code')


## PDF Generated
```pdf
assets/pdf/mergepdfv2.pdf
Expand Down
6 changes: 6 additions & 0 deletions docs/v2/features/unittests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unit Testing

## GoDoc
* [constructor : New](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/test#New)
* [method : Assert](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/test#MarotoTest.Assert)
* [method : Equals](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/test#MarotoTest.Equals)
* [method : Save](https://pkg.go.dev/github.com/johnfercher/maroto/v2/pkg/test#MarotoTest.Save)

## Configuration
To allow unit testing of PDFs, you must create the`.maroto.yml`file on the root project folder. The field`test_path`define which [folder](https://github.com/johnfercher/maroto/tree/v2/test/maroto)
will keep the json files to unit test the components tree.
Expand Down
16 changes: 8 additions & 8 deletions pkg/core/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,41 @@ import (
"github.com/johnfercher/maroto/v2/pkg/metrics"
)

type pdf struct {
type Pdf struct {
bytes []byte
report *metrics.Report
}

// NewPDF is responsible to create a new instance of PDF.
func NewPDF(bytes []byte, report *metrics.Report) Document {
return &pdf{
return &Pdf{
bytes: bytes,
report: report,
}
}

// GetBytes returns the PDF bytes.
func (p *pdf) GetBytes() []byte {
func (p *Pdf) GetBytes() []byte {
return p.bytes
}

// GetBase64 returns the PDF bytes in base64.
func (p *pdf) GetBase64() string {
func (p *Pdf) GetBase64() string {
return base64.StdEncoding.EncodeToString(p.bytes)
}

// GetReport returns the metrics.Report.
func (p *pdf) GetReport() *metrics.Report {
func (p *Pdf) GetReport() *metrics.Report {
return p.report
}

// Save saves the PDF in a file.
func (p *pdf) Save(file string) error {
func (p *Pdf) Save(file string) error {
return os.WriteFile(file, p.bytes, os.ModePerm)
}

// Merge merges the PDF with another PDF.
func (p *pdf) Merge(bytes []byte) error {
func (p *Pdf) Merge(bytes []byte) error {
var mergedBytes []byte
var err error

Expand All @@ -62,7 +62,7 @@ func (p *pdf) Merge(bytes []byte) error {
return nil
}

func (p *pdf) appendMetric(timeSpent *metrics.Time) {
func (p *Pdf) appendMetric(timeSpent *metrics.Time) {
timeMetric := metrics.TimeMetric{
Key: "merge_pdf",
Times: []*metrics.Time{timeSpent},
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/pdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewPDF(t *testing.T) {

// Assert
assert.NotNil(t, sut)
assert.Equal(t, "*core.pdf", fmt.Sprintf("%T", sut))
assert.Equal(t, "*core.Pdf", fmt.Sprintf("%T", sut))
}

func TestPdf_GetBase64(t *testing.T) {
Expand Down

0 comments on commit 39d22da

Please sign in to comment.