forked from mirror/pkger
Merge branch 'master' into here-here
This commit is contained in:
commit
7a3189e727
|
@ -141,10 +141,16 @@ func Package(info here.Info, out string, decls parser.Decls) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(f, "package %s\n\n", c.Name)
|
||||
fmt.Fprintf(f, "import \"github.com/markbates/pkger\"\n\n")
|
||||
fmt.Fprintf(f, "import \"github.com/markbates/pkger/pkging/mem\"\n\n")
|
||||
fmt.Fprintf(f, "\nvar _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`")
|
||||
|
||||
name := c.Name
|
||||
if info.Module.Main {
|
||||
name = "main"
|
||||
}
|
||||
|
||||
fmt.Fprintf(f, "package %s\n\n", name)
|
||||
fmt.Fprintf(f, "import (\n\t\"github.com/markbates/pkger\"\n\t")
|
||||
fmt.Fprintf(f, "\"github.com/markbates/pkger/pkging/mem\"\n)\n\n")
|
||||
fmt.Fprintf(f, "var _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`")
|
||||
|
||||
if err := pkgutil.Stuff(f, info, decls); err != nil {
|
||||
return err
|
||||
|
|
|
@ -5,6 +5,9 @@ import (
|
|||
"fmt"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
)
|
||||
|
||||
var _ Decl = IncludeDecl{}
|
||||
|
@ -15,6 +18,34 @@ type IncludeDecl struct {
|
|||
value string
|
||||
}
|
||||
|
||||
func NewInclude(her here.Info, inc string) (IncludeDecl, error) {
|
||||
var id IncludeDecl
|
||||
pt, err := her.Parse(inc)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
|
||||
if pt.Pkg != her.ImportPath {
|
||||
her, err = here.Package(pt.Pkg)
|
||||
if err != nil {
|
||||
return id, err
|
||||
}
|
||||
}
|
||||
|
||||
abs := filepath.Join(her.Module.Dir, pt.Name)
|
||||
|
||||
f := &File{
|
||||
Abs: abs,
|
||||
Path: pt,
|
||||
Here: her,
|
||||
}
|
||||
|
||||
return IncludeDecl{
|
||||
value: inc,
|
||||
file: f,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d IncludeDecl) String() string {
|
||||
return fmt.Sprintf("pkger.Include(%q)", d.value)
|
||||
}
|
||||
|
|
|
@ -226,30 +226,12 @@ func (p *Parser) parse() error {
|
|||
|
||||
func (p *Parser) parseIncludes() error {
|
||||
for _, i := range p.includes {
|
||||
pt, err := p.Info.Parse(i)
|
||||
d, err := NewInclude(p.Info, i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
her := p.Info
|
||||
if pt.Pkg != her.ImportPath {
|
||||
her, err = here.Package(pt.Pkg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
abs := filepath.Join(her.Module.Dir, pt.Name)
|
||||
|
||||
f := &File{
|
||||
Abs: abs,
|
||||
Path: pt,
|
||||
Here: her,
|
||||
}
|
||||
p.decls["Include"] = append(p.decls["Include"], IncludeDecl{
|
||||
value: i,
|
||||
file: f,
|
||||
})
|
||||
p.decls["Include"] = append(p.decls["Include"], d)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -41,14 +41,6 @@ func Test_Parser_Ref(t *testing.T) {
|
|||
fmt.Println(f.Path)
|
||||
}
|
||||
r.Len(files, 25)
|
||||
|
||||
for _, f := range files {
|
||||
if f.Path.Pkg == ref.Module.Path {
|
||||
r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
|
||||
} else {
|
||||
r.False(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Parser_Ref_Include(t *testing.T) {
|
||||
|
@ -74,19 +66,9 @@ func Test_Parser_Ref_Include(t *testing.T) {
|
|||
|
||||
files, err := res.Files()
|
||||
r.NoError(err)
|
||||
// t.FailNow()
|
||||
|
||||
l := len(files)
|
||||
r.Equal(26, l)
|
||||
// r.Len(files, 27)
|
||||
|
||||
for _, f := range files {
|
||||
if f.Path.Pkg == ref.Module.Path {
|
||||
r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
|
||||
} else {
|
||||
r.False(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Parser_Example_HTTP(t *testing.T) {
|
||||
|
|
|
@ -21,7 +21,6 @@ func NewRef() (*Ref, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root := filepath.Join(
|
||||
her.Module.Dir,
|
||||
"pkging",
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func Serve() {
|
||||
pkger.Stat("github.com/stretchr/testify:/README.md")
|
||||
pkger.Stat("github.com/markbates/pkger:/README.md")
|
||||
dir := http.FileServer(pkger.Dir("/public"))
|
||||
http.ListenAndServe(":3000", dir)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue