Skip to content

Commit

Permalink
keep
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher committed Sep 11, 2023
1 parent b22cfd1 commit 8081d66
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/main.go
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)

Check failure on line 23 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 20, in <argument> detected (gomnd)

image := image.New("image1")

col1 := col.New(4)

Check failure on line 27 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 4, in <argument> detected (gomnd)
col1.Add(image)

col2 := col.New(4)

Check failure on line 30 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 4, in <argument> detected (gomnd)
col3 := col.New(4)

Check failure on line 31 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 4, in <argument> detected (gomnd)

row.Add(col1, col2, col3)
return row
}
43 changes: 43 additions & 0 deletions pkg/v2/col/col.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package col

import (
"fmt"

Check failure on line 4 in pkg/v2/col/col.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/johnfercher/maroto/pkg/v2"

Check failure on line 5 in pkg/v2/col/col.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
)

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)
}
}
}
7 changes: 7 additions & 0 deletions pkg/v2/component.go
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)
}
40 changes: 40 additions & 0 deletions pkg/v2/document.go
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)
}
}
}
34 changes: 34 additions & 0 deletions pkg/v2/image/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package image

import (
"fmt"

Check failure on line 4 in pkg/v2/image/image.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/johnfercher/maroto/pkg/v2"

Check failure on line 5 in pkg/v2/image/image.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
)

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
}
43 changes: 43 additions & 0 deletions pkg/v2/row/row.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package row

import (
"fmt"

Check failure on line 4 in pkg/v2/row/row.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
"github.com/johnfercher/maroto/pkg/v2"

Check failure on line 5 in pkg/v2/row/row.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
)

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)
}
}
}
8 changes: 8 additions & 0 deletions pkg/v2/types.go
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"
)

0 comments on commit 8081d66

Please sign in to comment.