// If ignorePackages is nonempty, callers in any package specified are ignored.
// If there's an error accessing the file, it will be returned when calling
// Open() (Reader, error).
-func File(filename string, ignorePackages ...string) FileOpener {
+func File(filename string, ignorePackages ...string) (FileOpener, error) {
opener := new(fileOpener)
if path.IsAbs(filename) {
opener.absPath = filename
} else {
- caller, err := getCallStackButt(ignorePackages)
- if err != nil {
- opener.alwaysErr = err
- } else {
+ if caller, err := getCallStackButt(ignorePackages); err == nil {
opener.absPath = path.Join(path.Dir(caller), filename)
+ } else {
+ return nil, err
}
}
- return opener
+ return opener, nil
}
name string
fileName string
source include.Opener
-
includes []compile.Source
+
+ err error
}
type Config func(*Component)
// Assign basic parameters
p.name = name
p.fileName = source
- p.source = include.File(source, "git.earlybird.gay/today/web/component")
+ p.source, p.err = include.File(source, "git.earlybird.gay/today/web/component")
+ if p.err != nil {
+ return p
+ }
// Run optional arguments
for _, of := range optional {
of(p)
+ if p.err != nil {
+ return p
+ }
}
return p
}
func Source(source string) Config {
return func(p *Page) {
- p.source = include.File(source, "git.earlybird.gay/today/web/part")
+ p.source, p.err = include.File(source, "git.earlybird.gay/today/web/part")
}
}
}
}
-func New(name string, source string, optional ...func(*Page)) *Page {
+func New(name string, source string, optional ...Config) *Page {
p := new(Page)
// Assign basic parameters
p.name = name
- p.source = include.File(source, "git.earlybird.gay/today/web/page")
+ p.source, p.err = include.File(source, "git.earlybird.gay/today/web/page")
+ if p.err != nil {
+ return p
+ }
p.onLoad = func(ctx context.Context, d render.Data) error {
return nil
}
}
// With returns a shallow copy of p with all of optional applied to it.
-func (p *Page) With(optional ...func(*Page)) *Page {
+func (p *Page) With(optional ...Config) *Page {
q := &Page{
name: p.name,
source: p.source,
includes []compile.Source
onLoad render.OnLoadFunc
templateFuncs template.FuncMap
+
+ err error
}
type Config func(*Part)
func Source(source string) Config {
return func(p *Part) {
- p.source = include.File(source, "git.earlybird.gay/today/web/part")
+ p.source, p.err = include.File(source, "git.earlybird.gay/today/web/part")
}
}
}
}
-func New(name string, source string, optional ...func(*Part)) *Part {
+func New(name string, source string, optional ...Config) *Part {
p := new(Part)
// Assign basic parameters
p.name = name
- p.source = include.File(source, "git.earlybird.gay/today/web/part")
+ p.source, p.err = include.File(source, "git.earlybird.gay/today/web/part")
+ if p.err != nil {
+ return p
+ }
p.onLoad = func(ctx context.Context, data render.Data) error {
return nil
}
// Run optional arguments
for _, of := range optional {
of(p)
+ if p.err != nil {
+ return p
+ }
}
return p
}
// With returns a shallow copy of p with all of optional applied to it.
-func (p *Part) With(optional ...func(*Part)) *Part {
+func (p *Part) With(optional ...Config) *Part {
q := &Part{
name: p.name,
source: p.source,
for _, of := range optional {
of(q)
+ if q.err != nil {
+ return q
+ }
}
return q
}
func (p *Part) Includes() []compile.Source {
return p.includes
}
+
+func (p *Part) Error() error {
+ return p.err
+}