Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

adds the environment flag as a build tag when building bins #1046

Merged
merged 3 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions buffalo/cmd/build/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion render/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion render/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions render/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions render/template_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"})
Expand All @@ -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)
Expand All @@ -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"})
Expand All @@ -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)
Expand All @@ -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"})
Expand Down