-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b22cfd1
commit 8081d66
Showing
7 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
"github.com/johnfercher/maroto/pkg/v2/col" | ||
"github.com/johnfercher/maroto/pkg/v2/image" | ||
"github.com/johnfercher/maroto/pkg/v2/row" | ||
) | ||
|
||
func main() { | ||
pdf := v2.NewDocument("pdfzin") | ||
|
||
header := buildRow() | ||
content := buildRow() | ||
footer := buildRow() | ||
|
||
pdf.Add(header, content, footer) | ||
|
||
pdf.Render() | ||
} | ||
|
||
func buildRow() v2.Component { | ||
row := row.New(20) | ||
|
||
image := image.New("image1") | ||
|
||
col1 := col.New(4) | ||
col1.Add(image) | ||
|
||
col2 := col.New(4) | ||
col3 := col.New(4) | ||
|
||
row.Add(col1, col2, col3) | ||
return row | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package col | ||
|
||
import ( | ||
"fmt" | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
) | ||
|
||
type col struct { | ||
size int | ||
_type string | ||
accept map[string]bool | ||
components []v2.Component | ||
} | ||
|
||
func New(size int) *col { | ||
accept := make(map[string]bool) | ||
accept[v2.Image] = true | ||
|
||
return &col{ | ||
_type: v2.Col, | ||
accept: accept, | ||
size: size, | ||
} | ||
} | ||
|
||
func (d *col) Render() { | ||
fmt.Println(d.size) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *col) GetType() string { | ||
return d._type | ||
} | ||
|
||
func (d *col) Add(components ...v2.Component) { | ||
for _, component := range components { | ||
if _, ok := d.accept[component.GetType()]; ok { | ||
d.components = append(d.components, component) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package v2 | ||
|
||
type Component interface { | ||
Render() | ||
GetType() string | ||
Add(component ...Component) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package v2 | ||
|
||
import "fmt" | ||
|
||
type document struct { | ||
value string | ||
_type string | ||
accept map[string]bool | ||
components []Component | ||
} | ||
|
||
func NewDocument(value string) *document { | ||
accept := make(map[string]bool) | ||
accept[Row] = true | ||
|
||
return &document{ | ||
_type: Document, | ||
accept: accept, | ||
value: value, | ||
} | ||
} | ||
|
||
func (d *document) Render() { | ||
fmt.Println(d.value) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *document) GetType() string { | ||
return d._type | ||
} | ||
|
||
func (d *document) Add(components ...Component) { | ||
for _, component := range components { | ||
if _, ok := d.accept[component.GetType()]; ok { | ||
d.components = append(d.components, component) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package image | ||
|
||
import ( | ||
"fmt" | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
) | ||
|
||
type image struct { | ||
path string | ||
_type string | ||
components []v2.Component | ||
} | ||
|
||
func New(path string) *image { | ||
return &image{ | ||
_type: v2.Image, | ||
path: path, | ||
} | ||
} | ||
|
||
func (d *image) Render() { | ||
fmt.Println(d.path) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *image) GetType() string { | ||
return d._type | ||
} | ||
|
||
func (d *image) Add(_ ...v2.Component) { | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package row | ||
|
||
import ( | ||
"fmt" | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
) | ||
|
||
type row struct { | ||
height int | ||
_type string | ||
accept map[string]bool | ||
components []v2.Component | ||
} | ||
|
||
func New(height int) *row { | ||
accept := make(map[string]bool) | ||
accept[v2.Col] = true | ||
|
||
return &row{ | ||
_type: v2.Row, | ||
accept: accept, | ||
height: height, | ||
} | ||
} | ||
|
||
func (d *row) Render() { | ||
fmt.Println(d.height) | ||
for _, component := range d.components { | ||
component.Render() | ||
} | ||
} | ||
|
||
func (d *row) GetType() string { | ||
return d._type | ||
} | ||
|
||
func (d *row) Add(components ...v2.Component) { | ||
for _, component := range components { | ||
if _, ok := d.accept[component.GetType()]; ok { | ||
d.components = append(d.components, component) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package v2 | ||
|
||
const ( | ||
Document = "document" | ||
Row = "row" | ||
Col = "col" | ||
Image = "image" | ||
) |