Skip to content

Commit

Permalink
features/add method to return pdf settings (#440)
Browse files Browse the repository at this point in the history
* feat: Add method to return core.maroto Config

* test: Add tests to validate GetCurrentConfig method

* feat: regenerate mocks to include new method from maroto.core
  • Loading branch information
Fernando-hub527 authored May 26, 2024
1 parent cb26f0d commit f76ae41
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 45 deletions.
9 changes: 9 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func ExampleMaroto_FitlnCurrentPage() {
// Do things and generate
}

// ExampleMaroto_FitlnCurrentPage demonstrate how to check if the new line fits on the current page
func ExampleMaroto_GetCurrentConfig() {
m := maroto.New()

m.GetCurrentConfig()

// Do things and generate
}

// ExampleMaroto_RegisterHeader demonstrates how to register a header to me added in every new page.
// An error is returned if the area occupied by the header is greater than the page area.
func ExampleMaroto_RegisterHeader() {
Expand Down
5 changes: 5 additions & 0 deletions maroto.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type Maroto struct {
pool async.Processor[[]core.Page, []byte]
}

// GetCurrentConfig is responsible for returning the current settings from the file
func (m *Maroto) GetCurrentConfig() *entity.Config {
return m.config
}

// New is responsible for create a new instance of core.Maroto.
// It's optional to provide an *entity.Config with customizations
// those customization are created by using the config.Builder.
Expand Down
10 changes: 10 additions & 0 deletions maroto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ func TestMaroto_FitlnCurrentPage(t *testing.T) {
})
}

func TestMaroto_GetCurrentConfig(t *testing.T) {
t.Run("When GetCurrentConfig is called then current settings are returned", func(t *testing.T) {
sut := maroto.New(config.NewBuilder().
WithMaxGridSize(20).
Build())

assert.Equal(t, sut.GetCurrentConfig().MaxGridSize, 20)
})
}

// nolint:dupl // dupl is good here
func TestMaroto_RegisterHeader(t *testing.T) {
t.Run("when header size is greater than useful area, should return error", func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions metricsdecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/johnfercher/go-tree/node"
"github.com/johnfercher/maroto/v2/internal/time"
"github.com/johnfercher/maroto/v2/pkg/core"
"github.com/johnfercher/maroto/v2/pkg/core/entity"
"github.com/johnfercher/maroto/v2/pkg/metrics"
)

Expand All @@ -30,6 +31,11 @@ func (m *MetricsDecorator) FitlnCurrentPage(heightNewLine float64) bool {
return m.inner.FitlnCurrentPage(heightNewLine)
}

// GetCurrentConfig decorates the GetCurrentConfig method of maroto instance.
func (m *MetricsDecorator) GetCurrentConfig() *entity.Config {
return m.inner.GetCurrentConfig()
}

// Generate decorates the Generate method of maroto instance.
func (m *MetricsDecorator) Generate() (core.Document, error) {
var document core.Document
Expand Down
3 changes: 1 addition & 2 deletions mocks/Builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Cache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/CellWriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Code.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Col.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Component.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Document.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Font.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Fpdf.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Image.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Line.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Listable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 50 additions & 2 deletions mocks/Maroto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Math.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Node.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Page.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 51 additions & 7 deletions mocks/Repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Row.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions mocks/Text.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f76ae41

Please sign in to comment.