mgutz / razor

Golang Razor compiled template functions
7 stars 0 forks source link

Parser error when body not wrapped in html tag #1

Open troyk opened 9 years ago

troyk commented 9 years ago

If I do not wrap @section body in an html tag, the content is not wrapped in a __buffer.WriteString call. btw, are you using this in production? I really prefer razor to html/template and sipin/gorazor has a strong dependency on pkg structure and $GOPATH settings (I'm assuming that is why you forked) so thank you very much for putting this library together.

@{
  data := razor.M{
    "title": "Edit Keyword",
  }
  +extends Layout(data, ...)
}

@section body {

  Hello

}

produces:

/ DO NOT EDIT! Auto-generated by github.com/mgutz/razor

package admin

import (
    "github.com/mgutz/razor"
)

// Keyword_edit is generated
func Keyword_edit() *razor.SafeBuffer {
    __buffer := razor.NewSafeBuffer()
    data := razor.M{
        "title": "Edit Keyword",
    }

    __body := func() *razor.SafeBuffer {
        __buffer := razor.NewSafeBuffer()

        Hello

        return __buffer
    }

    __sections := make(razor.Sections)
    __sections["body"] = __body()
    __buffer = Layout(data, __buffer, &__sections)
    return __buffer
}

however, wrap in html tag

@{
  data := razor.M{
    "title": "Edit Keyword",
  }
  +extends Layout(data, ...)
}

@section body {

  <h1>Hello</h1>

}
// DO NOT EDIT! Auto-generated by github.com/mgutz/razor

package admin

import (
    "github.com/mgutz/razor"
)

// Keyword_edit is generated
func Keyword_edit() *razor.SafeBuffer {
    __buffer := razor.NewSafeBuffer()
    data := razor.M{
        "title": "Edit Keyword",
    }

    __body := func() *razor.SafeBuffer {
        __buffer := razor.NewSafeBuffer()

        __buffer.WriteString("<h1>Hello</h1>")

        return __buffer
    }

    __sections := make(razor.Sections)
    __sections["body"] = __body()
    __buffer = Layout(data, __buffer, &__sections)
    return __buffer
}
mgutz commented 9 years ago

I am only using it for a single page app right which now doesn't really excercise it. I will look into this tomorrow.