Skip to content

Commit

Permalink
Merge branch 'master' into fix-markdown-partials
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasschlueter authored Dec 8, 2018
2 parents fdfcbe3 + df16205 commit 54d9d65
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ func (c *compiler) evalCallExpression(node *ast.CallExpression) (interface{}, er
mname = i.Value
}
rv = rc.MethodByName(mname)
if !rv.IsValid() && rc.Type().Kind() != reflect.Ptr {
ptr := reflect.New(reflect.TypeOf(c))
ptr.Elem().Set(rc)
rv = ptr.MethodByName(mname)
}
if !rv.IsValid() {
if rv.Kind() == reflect.Slice {
rv = rc.FieldByName(mname)
Expand Down
10 changes: 10 additions & 0 deletions plush.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package plush
import (
"fmt"
"html/template"
"io"
"io/ioutil"
"sync"

"github.com/pkg/errors"
Expand Down Expand Up @@ -67,6 +69,14 @@ func Render(input string, ctx *Context) (string, error) {
return t.Exec(ctx)
}

func RenderR(input io.Reader, ctx *Context) (string, error) {
b, err := ioutil.ReadAll(input)
if err != nil {
return "", errors.WithStack(err)
}
return Render(string(b), ctx)
}

// RunScript allows for "pure" plush scripts to be executed.
func RunScript(input string, ctx *Context) error {
input = "<% " + input + "%>"
Expand Down
2 changes: 2 additions & 0 deletions shoulders.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Thank you to the following **GIANTS**:

* [github.com/gobuffalo/envy](https://godoc.org/github.com/gobuffalo/envy)

* [github.com/gobuffalo/flect](https://godoc.org/github.com/gobuffalo/flect)

* [github.com/gobuffalo/github_flavored_markdown](https://godoc.org/github.com/gobuffalo/github_flavored_markdown)

* [github.com/gobuffalo/github_flavored_markdown/internal/russross/blackfriday](https://godoc.org/github.com/gobuffalo/github_flavored_markdown/internal/russross/blackfriday)
Expand Down
26 changes: 26 additions & 0 deletions struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func Test_Render_UnknownAttribute_on_Callee(t *testing.T) {

type Robot struct {
Avatar Avatar
name string
}

type Avatar string
Expand All @@ -40,6 +41,10 @@ func (a Avatar) URL() string {
return strings.ToUpper(string(a))
}

func (r *Robot) Name() string {
return r.name
}

func Test_Render_Function_on_sub_Struct(t *testing.T) {
r := require.New(t)
ctx := NewContext()
Expand All @@ -52,3 +57,24 @@ func Test_Render_Function_on_sub_Struct(t *testing.T) {
r.NoError(err)
r.Equal("BENDER.JPG", s)
}

func Test_Render_Struct_PointerMethod(t *testing.T) {
r := require.New(t)
ctx := NewContext()
robot := Robot{name: "robot"}

t.Run("ByValue", func(t *testing.T) {
ctx.Set("robot", robot)
input := `<%= robot.Name() %>`
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("robot", s)
})
t.Run("ByPointer", func(t *testing.T) {
ctx.Set("robot", &robot)
input := `<%= robot.Name() %>`
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("robot", s)
})
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package plush

const Version = "v3.7.30"
const Version = "v3.7.32"

0 comments on commit 54d9d65

Please sign in to comment.