-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package premailer | ||
|
||
import ( | ||
"github.com/PuerkitoBio/goquery" | ||
"os" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
) | ||
|
||
// NewPremailerFromFile take an filename | ||
// Read the content of this file | ||
// and create a goquery.Document | ||
// and then create and Premailer instance. | ||
// It will panic if any error happens | ||
func NewPremailerFromFile(filename string, options *Options) Premailer { | ||
func NewPremailerFromFile(filename string, options *Options) (Premailer, error) { | ||
fd, err := os.Open(filename) | ||
if err != nil { | ||
panic(err) | ||
return nil, err | ||
} | ||
defer fd.Close() | ||
d, err := goquery.NewDocumentFromReader(fd) | ||
if err != nil { | ||
panic(err) | ||
return nil, err | ||
} | ||
return NewPremailer(d, options) | ||
return NewPremailer(d, options), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package premailer | ||
|
||
import ( | ||
"github.com/PuerkitoBio/goquery" | ||
"strings" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
) | ||
|
||
// NewPremailerFromString take in a document in string format | ||
// and create a goquery.Document | ||
// and then create and Premailer instance. | ||
// It will panic if any error happens | ||
func NewPremailerFromString(doc string, options *Options) Premailer { | ||
func NewPremailerFromString(doc string, options *Options) (Premailer, error) { | ||
read := strings.NewReader(doc) | ||
d, err := goquery.NewDocumentFromReader(read) | ||
if err != nil { | ||
panic(err) | ||
return nil, err | ||
} | ||
return NewPremailer(d, options) | ||
return NewPremailer(d, options), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters