From b2bf94655dbb499d4ee2e53689521a375ba28879 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Thu, 26 Apr 2018 17:28:56 -0400 Subject: [PATCH 1/2] make sure to merge partial args and the context. fixes #1044. fixes #1006 --- render/html.go | 2 +- render/js.go | 2 +- render/plain.go | 2 +- render/template.go | 15 ++++++++++++--- render/template_helpers_test.go | 12 ++++++------ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/render/html.go b/render/html.go index 74b8f8fae..179b0ff02 100644 --- a/render/html.go +++ b/render/html.go @@ -31,7 +31,7 @@ func (e *Engine) HTML(names ...string) Renderer { if e.HTMLLayout != "" && len(names) == 1 { names = append(names, e.HTMLLayout) } - hr := templateRenderer{ + hr := &templateRenderer{ Engine: e, contentType: "text/html", names: names, diff --git a/render/js.go b/render/js.go index c0f74726c..24ff8c057 100644 --- a/render/js.go +++ b/render/js.go @@ -32,7 +32,7 @@ func (e *Engine) JavaScript(names ...string) Renderer { if e.JavaScriptLayout != "" && len(names) == 1 { names = append(names, e.JavaScriptLayout) } - hr := templateRenderer{ + hr := &templateRenderer{ Engine: e, contentType: "application/javascript", names: names, diff --git a/render/plain.go b/render/plain.go index c526a4d54..62ebcc1e6 100644 --- a/render/plain.go +++ b/render/plain.go @@ -18,7 +18,7 @@ func Plain(names ...string) Renderer { // and the first file will be the "content" file which will // be placed into the "layout" using "<%= yield %>". func (e *Engine) Plain(names ...string) Renderer { - hr := templateRenderer{ + hr := &templateRenderer{ Engine: e, contentType: "text/plain; charset=utf-8", names: names, diff --git a/render/template.go b/render/template.go index 22f4cdea4..8cc072cf8 100644 --- a/render/template.go +++ b/render/template.go @@ -20,13 +20,15 @@ type templateRenderer struct { *Engine contentType string names []string + data Data } func (s templateRenderer) ContentType() string { return s.contentType } -func (s templateRenderer) Render(w io.Writer, data Data) error { +func (s *templateRenderer) Render(w io.Writer, data Data) error { + s.data = data var body template.HTML var err error for _, name := range s.names { @@ -43,7 +45,14 @@ func (s templateRenderer) Render(w io.Writer, data Data) error { func (s templateRenderer) partial(name string, dd Data) (template.HTML, error) { d, f := filepath.Split(name) name = filepath.Join(d, "_"+f) - return s.exec(name, dd) + m := Data{} + for k, v := range s.data { + m[k] = v + } + for k, v := range dd { + m[k] = v + } + return s.exec(name, m) } func (s templateRenderer) exec(name string, data Data) (template.HTML, error) { @@ -178,7 +187,7 @@ func Template(c string, names ...string) Renderer { // and the first file will be the "content" file which will // be placed into the "layout" using "{{yield}}". func (e *Engine) Template(c string, names ...string) Renderer { - return templateRenderer{ + return &templateRenderer{ Engine: e, contentType: c, names: names, diff --git a/render/template_helpers_test.go b/render/template_helpers_test.go index 8f970a062..1a1788572 100644 --- a/render/template_helpers_test.go +++ b/render/template_helpers_test.go @@ -14,7 +14,7 @@ func Test_javascriptTag(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["javascriptTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("application.js", nil) @@ -27,7 +27,7 @@ func Test_javascriptTag_Options(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["javascriptTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("application.js", tags.Options{"class": "foo"}) @@ -40,7 +40,7 @@ func Test_stylesheetTag(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["stylesheetTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("application.css", nil) @@ -53,7 +53,7 @@ func Test_stylesheetTag_Options(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["stylesheetTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("application.css", tags.Options{"class": "foo"}) @@ -65,7 +65,7 @@ func Test_imgTag(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["imgTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("foo.png", nil) @@ -78,7 +78,7 @@ func Test_imgTag_Options(t *testing.T) { re := New(Options{ AssetsBox: packr.NewBox(""), }) - tr := re.Template("").(templateRenderer) + tr := re.Template("").(*templateRenderer) h := tr.addAssetsHelpers(Helpers{}) f := h["imgTag"].(func(string, tags.Options) (template.HTML, error)) s, err := f("foo.png", tags.Options{"class": "foo"}) From f4b140df8b5bb63584f462d5e0611af8a631d36f Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sun, 29 Apr 2018 17:50:15 -0400 Subject: [PATCH 2/2] adds the environment flag as a build tag when building bins --- buffalo/cmd/build/bin.go | 5 ++--- buffalo/cmd/dev.go | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/buffalo/cmd/build/bin.go b/buffalo/cmd/build/bin.go index e95126617..5eedddae3 100644 --- a/buffalo/cmd/build/bin.go +++ b/buffalo/cmd/build/bin.go @@ -36,9 +36,8 @@ func (b *Builder) buildBin() error { if b.Debug { buildArgs = append(buildArgs, "-v") } - if len(b.Tags) > 0 { - buildArgs = append(buildArgs, "-tags", strings.Join(b.Tags, " ")) - } + b.Tags = append(b.Tags, b.Environment) + buildArgs = append(buildArgs, "-tags", strings.Join(b.Tags, " ")) buildArgs = append(buildArgs, "-o", b.Bin) diff --git a/buffalo/cmd/dev.go b/buffalo/cmd/dev.go index 04be5cad6..d4fb9b3a9 100644 --- a/buffalo/cmd/dev.go +++ b/buffalo/cmd/dev.go @@ -114,11 +114,13 @@ func startDevServer(ctx context.Context) error { return err } c.Debug = devOptions.Debug + tags := []string{"-tags", "development"} if b, err := ioutil.ReadFile("database.yml"); err == nil { if bytes.Contains(b, []byte("sqlite")) { - c.BuildFlags = append(c.BuildFlags, "-tags", "sqlite") + tags = append(tags, "sqlite") } } + c.BuildFlags = append(c.BuildFlags, tags...) r := refresh.NewWithContext(c, ctx) return r.Start() }