Popularity
0.5
Declining
Activity
0.0
Stable
0
3
0

Description

mold your templated to HTML/ TEXT to PDF easily.

Programming language: HTML
License: BSD 3-clause "New" or "Revised" License
Tags: Command Line     Template     PDF     Pdf Generator     Invoice    
Latest version: v0.1

mold alternatives and similar packages

Based on the "Command Line" category.
Alternatively, view mold alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of mold or a related project?

Add another 'Command Line' Package

README

Godocs Go Report Card Release

mold

mold your templated to HTML/ TEXT/ PDF easily.

install

go get github.com/mayur-tolexo/mold

Example 1

//Todo model
type Todo struct {
    Title string
    Done  bool
}

//TodoPageData model
type TodoPageData struct {
    PageTitle string
    Todos     []Todo
}

func main() {

    tmpl := `
    <h1>{{.PageTitle}}<h1>
    <ul>
        {{range .Todos}}
            {{if .Done}}
                <li class="done">{{.Title}}</li>
            {{else}}
                <li>{{.Title}}</li>
            {{end}}
        {{end}}
    </ul>
    `

    mold, _ := mold.NewHTMLTemplate(tmpl)

    data := TodoPageData{
        PageTitle: "My TODO list",
        Todos: []Todo{
            {Title: "Task 1", Done: false},
            {Title: "Task 2", Done: true},
            {Title: "Task 3", Done: true},
            {Title: "Task 4", Done: true},
        },
    }

    if err := mold.Execute(data); err == nil {
        mold.PDF(".", "tmp.pdf")
    } else {
        fmt.Println(err)
    }
}

Example 2


//Invoice details
type Invoice struct {
    InvoiceNo   string
    InvoiceDate string
    Currency    string
    AmountDue   float64
    Items       []ItemDetail
    Total       float64
}

//ItemDetail : Item details
type ItemDetail struct {
    Name     string
    Desc     string
    Amount   float64
    Qty      int
    Total    float64
}

func main() {
    mold, _ := mold.NewHTMLTemplate()
    mold.HTMLPath = "invoice.html"

    item := []ItemDetail{
        {
            Name:     "Front End Consultation",
            Desc:     "Experience Review",
            Amount:   150,
            Qty:      4,
            Total:    600,
        },
    }

    data := Invoice{
        InvoiceNo:   "Invoice",
        InvoiceDate: "January 1, 2019",
        Currency:    "Rs.",
        AmountDue:   600,
        Items:       item,
        Total:       600,
    }

    if err := mold.Execute(data); err == nil {
        mold.PDF(".", "invoice.pdf")
    } else {
        fmt.Println(err)
    }
}

Output

Screenshot 2019-05-20 at 4 44 19 PM