FAQ
Has there been any discussion about allowing template funcs to accept a
region?

For example, I would like to write a func that performs syntax highlighting
(server-side, while all existing solutions are in javascript):

{{/* A sample template */}}
...
A description of my ExampleFunc function and an example of its usage:
{{prettify "go"}}
func ExampleFunc() {
...
}
{{end}}

For that, I would like to use a template func with a signature like:

"prettify": func(lang, body string) template.HTML

Generally, the region could be be passed as the final parameter to the func.

Would there be interest if I submitted a code review to implement this?

--

Search Discussions

  • Andrew Gerrand at Jan 29, 2013 at 5:42 am
    Seems like a useful feature. It will require some thought on the design end.

    File an issue with your proposal here: http://golang.org/issue/new

    (Do not write the code! Just describe the new functionality in detail.)

    Thanks,
    Andrew

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rémy Oudompheng at Jan 29, 2013 at 5:55 am

    On Saturday, January 26, 2013 5:53:50 PM UTC+1, robfig wrote:
    Has there been any discussion about allowing template funcs to accept a
    region?

    For example, I would like to write a func that performs syntax
    highlighting (server-side, while all existing solutions are in javascript):

    {{/* A sample template */}}
    ...
    A description of my ExampleFunc function and an example of its usage:
    {{prettify "go"}}
    func ExampleFunc() {
    ...
    }
    {{end}}

    For that, I would like to use a template func with a signature like:

    "prettify": func(lang, body string) template.HTML

    Generally, the region could be be passed as the final parameter to the
    func.

    The proposed syntax would look a bit confusing to me. It would be very easy
    to accidentally pass a whole part of the template to a function because an
    argument is forgotten.

    Rémy.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sonia Keys at Jan 29, 2013 at 7:29 pm
    Can't this be done with raw strings? I realize it would involve dancing
    around raw strings in the embedded code, but this is code that is right
    there in the template anyway.
    On Saturday, January 26, 2013 11:53:50 AM UTC-5, robfig wrote:

    Has there been any discussion about allowing template funcs to accept a
    region?

    For example, I would like to write a func that performs syntax
    highlighting (server-side, while all existing solutions are in javascript):

    {{/* A sample template */}}
    ...
    A description of my ExampleFunc function and an example of its usage:
    {{prettify "go"}}
    func ExampleFunc() {
    ...
    }
    {{end}}

    For that, I would like to use a template func with a signature like:

    "prettify": func(lang, body string) template.HTML

    Generally, the region could be be passed as the final parameter to the
    func.

    Would there be interest if I submitted a code review to implement this?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Rob Figueiredo at Jan 29, 2013 at 7:45 pm
    Hm, I don't understand your suggestion. Do you mind explaining or
    sketching an example?

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Sonia Keys at Jan 29, 2013 at 8:55 pm
    Oh, I see the limitation on including raw strings in templates now. Sorry
    to reply too quickly.

    I still expect there are workarounds. Workarounds aren't pretty, but
    regions look like here documents to me though. It seems a shame if we say
    we don't need them in Go because we have raw strings, then we fall back on
    them in template. Maybe they're idomatic in templating languages, I don't
    know. If so, maybe it's worth persuing.
    On Tuesday, January 29, 2013 2:45:09 PM UTC-5, robfig wrote:

    Hm, I don't understand your suggestion. Do you mind explaining or
    sketching an example?
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 26, '13 at 4:53p
activeJan 29, '13 at 8:55p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase