Skip to content

Commit

Permalink
Merge pull request #9 from arskang/hotfix/ancho-clumna
Browse files Browse the repository at this point in the history
fix: se puede definir un ancho de columna
  • Loading branch information
arskang authored Oct 11, 2024
2 parents 72b5473 + 66a55c9 commit 3533d78
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
9 changes: 7 additions & 2 deletions acorn/boilerplate.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package acorn

import (
"fmt"
"strings"

"github.com/arskang/acornmail/acorntypes"
)

// Generate a new boilerplate html element
func (h HTML) GetBoilerplate(elements acorntypes.AcornComponents, withoutMargins *bool) string {
func (h HTML) GetBoilerplate(elements acorntypes.AcornComponents, withoutMargins *bool, width ...int) string {
spacer := h.NewSpacer()
if withoutMargins != nil && *withoutMargins {
spacer = ""
}
defaultWidth := 600
if len(width) > 0 {
defaultWidth = width[0]
}
return `
<!DOCTYPE html>
<html lang="es" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
Expand Down Expand Up @@ -149,7 +154,7 @@ func (h HTML) GetBoilerplate(elements acorntypes.AcornComponents, withoutMargins
<table lang="es" bgcolor="#EEEEEE" cellpadding="16" cellspacing="0" role="presentation" width="100%">
<tr>
<td align="center">
<table class="container" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" role="presentation" width="600">
<table class="container" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0" role="presentation" width="` + fmt.Sprint(defaultWidth) + `">
<tr>
<td align="left">
` + spacer + strings.Join(elements, " ") + spacer + `
Expand Down
47 changes: 38 additions & 9 deletions acornstyles/columns.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package acornstyles

import "github.com/arskang/acornmail/acorntypes"
import (
"fmt"

"github.com/arskang/acornmail/acorntypes"
)

type widthColumns struct {
Full, Quarter, Medium, ThreeQuarters, OneThird, TwoThird *acorntypes.WidthColumn
Expand All @@ -10,18 +14,43 @@ func setColumn(s string) *acorntypes.WidthColumn {
return (*acorntypes.WidthColumn)(&s)
}

func calculateWidths(width int) map[string]int {
return map[string]int{
"Quarter": width / 4,
"Medium": width / 2,
"ThreeQuarters": (3 * width) / 4,
"OneThird": width / 3,
"TwoThird": (2 * width) / 3,
}
}

// Return width columns:
// Full, Quarter, Medium, ThreeQuarters, OneThird and TwoThird
// (*acorntypes.WidthColumn)
func GetWidthColumns() *widthColumns {
return &widthColumns{
Full: setColumn("100%"),
Quarter: setColumn("138"),
Medium: setColumn("276"),
ThreeQuarters: setColumn("414"),
OneThird: setColumn("184"),
TwoThird: setColumn("368"),
func GetWidthColumns(width ...int) *widthColumns {
defaultWidth := 600
if len(width) > 0 {
defaultWidth = width[0]
}
values := calculateWidths(defaultWidth)
WidthColumns := &widthColumns{
Full: setColumn("100%"),
}
for key, v := range values {
switch key {
case "Quarter":
WidthColumns.Quarter = setColumn(fmt.Sprint(v))
case "Medium":
WidthColumns.Medium = setColumn(fmt.Sprint(v))
case "ThreeQuarters":
WidthColumns.ThreeQuarters = setColumn(fmt.Sprint(v))
case "OneThird":
WidthColumns.OneThird = setColumn(fmt.Sprint(v))
case "TwoThird":
WidthColumns.TwoThird = setColumn(fmt.Sprint(v))
}
}
return WidthColumns
}

func WithoutMargins() *bool {
Expand Down
6 changes: 3 additions & 3 deletions test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ func TestExample(t *testing.T) {
}

func TestGrid(t *testing.T) {

width := 800
acorn := acornmail.NewAcornEmailComponents()

widthColumns := acornstyles.GetWidthColumns()
widthColumns := acornstyles.GetWidthColumns(width)
colors := acornstyles.GetColors()

grid := acorn.NewGrid([][]*acorntypes.ColumnParams{
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestGrid(t *testing.T) {
},
})

boilerplate := acorn.GetBoilerplate(acorntypes.AcornComponents{grid}, nil)
boilerplate := acorn.GetBoilerplate(acorntypes.AcornComponents{grid}, nil, width)

t.Log(boilerplate)

Expand Down

0 comments on commit 3533d78

Please sign in to comment.