Skip to content

Commit

Permalink
Improve docs (#435)
Browse files Browse the repository at this point in the history
* cell props
* page props
* row component
* add code examples
* add row examples
  • Loading branch information
johnfercher authored May 18, 2024
1 parent a3e9638 commit 04ee0dd
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 26 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.2` is here! Try out:
#### Maroto `v2.0.3` is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.2
go get github.com/johnfercher/maroto/v2@v2.0.3
```

* 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.2`is here! Try out:
#### 3. Maroto`v2.0.3`is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2@v2.0.2
go get github.com/johnfercher/maroto/v2@v2.0.3
```

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.2</small>
# Maroto <small>v2.0.3</small>

> An open-source golang lib to create PDFs. Fast and Simple.
Expand Down
87 changes: 75 additions & 12 deletions pkg/components/code/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,95 @@ import (
"github.com/johnfercher/maroto/v2/pkg/components/code"
)

// ExampleNewBar demonstrates how to generate a barcode and add it to maroto
// ExampleNewBar demonstrates how to generate a barcode and add it to maroto.
func ExampleNewBar() {
mrt := maroto.New()
m := maroto.NewMetricsDecorator(mrt)
m := maroto.New()

m.AddRow(10, col.New(6).Add(code.NewBar("123456789", props.Barcode{Percent: 70.5})))
barCode := code.NewBar("123456789", props.Barcode{Percent: 70.5})
col := col.New(6).Add(barCode)
m.AddRow(10, col)

// generate document
}

// ExampleNewBar demonstrates how to generate a column with a barcode and add it to maroto
// ExampleNewBarCol demonstrates how to generate a column with a barcode and add it to maroto.
func ExampleNewBarCol() {
mrt := maroto.New()
m := maroto.NewMetricsDecorator(mrt)
m := maroto.New()

m.AddRow(10, code.NewBarCol(6, "123456", props.Barcode{Percent: 70.5}))
barCodeCol := code.NewBarCol(6, "123456", props.Barcode{Percent: 70.5})
m.AddRow(10, barCodeCol)

// generate document
}

// ExampleNewBarRow demonstrates how to generate a row with a barcode and add it to maroto
// ExampleNewBarRow demonstrates how to generate a row with a barcode and add it to maroto.
func ExampleNewBarRow() {
mrt := maroto.New()
m := maroto.NewMetricsDecorator(mrt)
m := maroto.New()

m.AddRows(code.NewBarRow(10, "123456789", props.Barcode{Percent: 70.5}))
barCodeRow := code.NewBarRow(10, "123456789", props.Barcode{Percent: 70.5})
m.AddRows(barCodeRow)

// generate document
}

// ExampleNewQr demonstrates how to generate a qrcode and add it to maroto.
func ExampleNewQr() {
m := maroto.New()

qrCode := code.NewQr("123456789", props.Rect{Percent: 70.5})
col := col.New(6).Add(qrCode)
m.AddRow(10, col)

// generate document
}

// ExampleNewQrCol demonstrates how to generate a column with a qrcode and add it to maroto.
func ExampleNewQrCol() {
m := maroto.New()

qrCodeCol := code.NewQrCol(12, "123456789", props.Rect{Percent: 70.5})
m.AddRow(10, qrCodeCol)

// generate document
}

// ExampleNewQrRow demonstrates how to generate a row with a qrcode and add it to maroto.
func ExampleNewQrRow() {
m := maroto.New()

qrCodeRow := code.NewQrRow(10, "123456789", props.Rect{Percent: 70.5})
m.AddRows(qrCodeRow)

// generate document
}

// ExampleNewMatrix demonstrates how to generate a matrixcode and add it to maroto.
func ExampleNewMatrix() {
m := maroto.New()

matrixCode := code.NewMatrix("123456789", props.Rect{Percent: 70.5})
col := col.New(6).Add(matrixCode)
m.AddRow(10, col)

// generate document
}

// ExampleNewMatrixCol demonstrates how to generate a column with a matrixcode and add it to maroto.
func ExampleNewMatrixCol() {
m := maroto.New()

matrixCodeCol := code.NewMatrixCol(12, "123456789", props.Rect{Percent: 70.5})
m.AddRow(10, matrixCodeCol)

// generate document
}

// ExampleNewMatrixRow demonstrates how to generate a row with a matrixcode and add it to maroto.
func ExampleNewMatrixRow() {
m := maroto.New()

matrixCodeRow := code.NewMatrixRow(10, "123456789", props.Rect{Percent: 70.5})
m.AddRows(matrixCodeRow)

// generate document
}
70 changes: 70 additions & 0 deletions pkg/components/row/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package row_test

import (
"github.com/johnfercher/maroto/v2"
"github.com/johnfercher/maroto/v2/pkg/components/code"
"github.com/johnfercher/maroto/v2/pkg/components/row"
"github.com/johnfercher/maroto/v2/pkg/components/signature"
"github.com/johnfercher/maroto/v2/pkg/components/text"
"github.com/johnfercher/maroto/v2/pkg/consts/border"
"github.com/johnfercher/maroto/v2/pkg/consts/linestyle"
"github.com/johnfercher/maroto/v2/pkg/props"
)

// ExampleNew demonstrates how to create a Row instance.
func ExampleNew() {
// height defines the size of the useful area
// which can be used in the set of columns and components
// inside this row.
height := 10.0
row := row.New(height)

m := maroto.New()

m.AddRows(row)

// Do things and generate
_, _ = m.Generate()
}

// ExampleRow_Add demonstrates how to add cols inside a Row.
func ExampleRow_Add() {
textCol := text.NewCol(12, "text content")
qrCodeCol := code.NewQrCol(12, "qrcode")
signatureCol := signature.NewCol(12, "signature label")

row := row.New(10).Add(textCol, qrCodeCol, signatureCol)

m := maroto.New()
m.AddRows(row)

// Do things and generate
_, _ = m.Generate()
}

// ExampleRow_WithStyle demonstrates how to add style to Row.
func ExampleRow_WithStyle() {
row := row.New(10)

row.WithStyle(&props.Cell{
BackgroundColor: &props.Color{
Red: 10,
Green: 100,
Blue: 150,
},
BorderColor: &props.Color{
Red: 55,
Green: 10,
Blue: 60,
},
BorderType: border.Full,
BorderThickness: 0.1,
LineStyle: linestyle.Dashed,
})

m := maroto.New()
m.AddRows(row)

// Do things and generate
_, _ = m.Generate()
}
2 changes: 1 addition & 1 deletion pkg/components/row/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Row struct {
}

// New is responsible to create a core.Row.
// height is defined in mm
// height is defined in mm.
func New(height float64) core.Row {
return &Row{
height: height,
Expand Down
17 changes: 14 additions & 3 deletions pkg/props/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import (
)

// Cell is the representation of a cell in the grid system.
// This can be applied to Col or Row
type Cell struct {
// BackgroundColor defines which color will be applied to a cell.
// Default: nil
BackgroundColor *Color
BorderColor *Color
BorderType border.Type
// BorderColor defines which color will be applied to a border cell
// Default: nil
BorderColor *Color
// BorderType defines which kind of border will be applied to a cell.
// Default: border.None
BorderType border.Type
// BorderThickness defines the border thickness applied to a cell.
// Default: 0.2
BorderThickness float64
LineStyle linestyle.Type
// LineStyle defines which line style will be applied to a cell.
// Default: Solid
LineStyle linestyle.Type
}

// ToMap adds the Cell fields to the map.
Expand Down
16 changes: 11 additions & 5 deletions pkg/props/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ func (p Place) IsValid() bool {

// Page is the representation of a page.
type Page struct {
// Pattern is the string pattern which will be used to apply the page count component.
Pattern string
Place Place
Family string
Style fontstyle.Type
Size float64
Color *Color
// Place defines where the page count component will be placed.
Place Place
// Family defines which font family will be applied to page count.
Family string
// Style defines which font style will be applied to page count.
Style fontstyle.Type
// Size defines which font size will be applied to page count.
Size float64
// Color defines which will be applied to page count.
Color *Color
}

// GetNumberTextProp returns the Text properties of the page number.
Expand Down

0 comments on commit 04ee0dd

Please sign in to comment.