Skip to content

Commit

Permalink
builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher committed May 27, 2024
1 parent a73c242 commit 9ebc333
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 199 deletions.
79 changes: 49 additions & 30 deletions pkg/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func NewBuilder() Builder {
},
generationMode: generation.Sequential,
chunkWorkers: 1,
metadata: &entity.Metadata{},
}
}

Expand Down Expand Up @@ -148,6 +147,13 @@ func (b *CfgBuilder) WithConcurrentMode(chunkWorkers int) Builder {
return b
}

// WithSequentialMode defines that maroto will run in default mode.
func (b *CfgBuilder) WithSequentialMode() Builder {
b.chunkWorkers = 1
b.generationMode = generation.Sequential
return b
}

// WithSequentialLowMemoryMode defines that maroto will run focusing in reduce memory consumption,
// chunk workers define how many divisions the work will have.
func (b *CfgBuilder) WithSequentialLowMemoryMode(chunkWorkers int) Builder {
Expand All @@ -160,13 +166,6 @@ func (b *CfgBuilder) WithSequentialLowMemoryMode(chunkWorkers int) Builder {
return b
}

// WithSequentialMode defines that maroto will run in default mode.
func (b *CfgBuilder) WithSequentialMode() Builder {
b.chunkWorkers = 1
b.generationMode = generation.Sequential
return b
}

// WithDebug defines a debug behaviour where maroto will draw borders in everything.
func (b *CfgBuilder) WithDebug(on bool) Builder {
b.debug = on
Expand Down Expand Up @@ -208,24 +207,14 @@ func (b *CfgBuilder) WithDefaultFont(font *props.Font) Builder {
return b
}

// WithCustomFonts add custom fonts.
func (b *CfgBuilder) WithCustomFonts(customFonts []*entity.CustomFont) Builder {
if customFonts == nil {
return b
}

b.customFonts = customFonts
return b
}

// WithPageNumber defines a string pattern to write the current page and total.
func (b *CfgBuilder) WithPageNumber(pageNumber ...props.PageNumber) Builder {
var pageN props.PageNumber
if len(pageNumber) > 0 {
pageN = pageNumber[0]
}

if !strings.Contains(pageN.Pattern, "{current}") && !strings.Contains(pageN.Pattern, "{total}") {
if !strings.Contains(pageN.Pattern, "{current}") || !strings.Contains(pageN.Pattern, "{total}") {
pageN.Pattern = "{current} / {total}"
}

Expand Down Expand Up @@ -268,6 +257,10 @@ func (b *CfgBuilder) WithAuthor(author string, isUTF8 bool) Builder {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.Author = &entity.Utf8Text{
Text: author,
UTF8: isUTF8,
Expand All @@ -282,6 +275,10 @@ func (b *CfgBuilder) WithCreator(creator string, isUTF8 bool) Builder {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.Creator = &entity.Utf8Text{
Text: creator,
UTF8: isUTF8,
Expand All @@ -296,6 +293,10 @@ func (b *CfgBuilder) WithSubject(subject string, isUTF8 bool) Builder {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.Subject = &entity.Utf8Text{
Text: subject,
UTF8: isUTF8,
Expand All @@ -310,6 +311,10 @@ func (b *CfgBuilder) WithTitle(title string, isUTF8 bool) Builder {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.Title = &entity.Utf8Text{
Text: title,
UTF8: isUTF8,
Expand All @@ -324,22 +329,18 @@ func (b *CfgBuilder) WithCreationDate(time time.Time) Builder {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.CreationDate = &time

return b
}

// WithKeywords defines the document's keyword metadata.
func (b *CfgBuilder) WithKeywords(keywordsStr string, isUTF8 bool) Builder {
if keywordsStr == "" {
return b
}

b.metadata.KeywordsStr = &entity.Utf8Text{
Text: keywordsStr,
UTF8: isUTF8,
}

// WithCustomFonts add custom fonts.
func (b *CfgBuilder) WithCustomFonts(customFonts []*entity.CustomFont) Builder {
b.customFonts = customFonts
return b
}

Expand All @@ -359,6 +360,24 @@ func (b *CfgBuilder) WithDisableAutoPageBreak(disabled bool) Builder {
return b
}

// WithKeywords defines the document's keyword metadata.
func (b *CfgBuilder) WithKeywords(keywordsStr string, isUTF8 bool) Builder {
if keywordsStr == "" {
return b
}

if b.metadata == nil {
b.metadata = &entity.Metadata{}
}

b.metadata.KeywordsStr = &entity.Utf8Text{
Text: keywordsStr,
UTF8: isUTF8,
}

return b
}

// Build finalizes the customization returning the entity.Config.
func (b *CfgBuilder) Build() *entity.Config {
if b.pageNumber != nil {
Expand Down
Loading

0 comments on commit 9ebc333

Please sign in to comment.