Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 27 04:41
    SVyatoslavG opened #197
  • Sep 29 15:43
    replay111 commented #191
  • Sep 29 15:43
    replay111 commented #191
  • Sep 28 16:39
    replay111 commented #191
  • Sep 27 14:26
    replay111 commented #191
  • Sep 27 14:23
    replay111 commented #191
  • Sep 27 14:19
    replay111 commented #195
  • Sep 27 13:29
    richp10 opened #196
  • Sep 27 08:45
    sauerbraten closed #195
  • Sep 27 08:45
    sauerbraten commented #195
  • Sep 25 20:35
    replay111 opened #195
  • Jul 29 17:30
    proyb6 closed #194
  • Jul 24 18:10
    wsantos commented #193
  • Jul 22 14:23
    sauerbraten commented #193
  • Jul 22 13:48
    proyb6 opened #194
  • Jul 22 04:55
    nkev commented #190
  • Jul 18 16:57
    wsantos commented #193
  • Jul 13 18:37
    sauerbraten commented #107
  • Jul 13 18:37
    sauerbraten commented #107
  • Jul 13 18:30
    sauerbraten closed #193
Daniel Lohse
@annismckenzie
I'm here to answer questions about Jet. Been working with it for quite a while.
Gipi66
@Gipi66
how coonect u template engine (jet) whith gin? i try like this, but this dont work
func indexFunc(w http.ResponseWriter, r http.Request) {
var todos = map[string]
tTODO{
"example-todo-1": &tTODO{Text: "Add an show todo page to the example project", Done: true},
"example-todo-2": &tTODO{Text: "Add an add todo page to the example project"},
"example-todo-3": &tTODO{Text: "Add an update todo page to the example project"},
"example-todo-4": &tTODO{Text: "Add an delete todo page to the example project", Done: true},
}
views, err := view.GetTemplate("todos/index.jet")
if err != nil {
log.Println("Unexpected template err:", err.Error())
}
views.Execute(w, nil, todos)
}
router.GET("/", indexFunc)
Vojtech Vitek
@VojtechVitek
CloudyKit/jet#48 @annismckenzie @jhsx
Gipi66
@Gipi66
can you give an example of how to connect gin + jet? Sorry for my english.. thank you in advance
José Santos
@jhsx
@annismckenzie can you give some advice to @Gipi66 since i never used gin i can't speak without check first.
Daniel Lohse
@annismckenzie
Wow, so sorry that I didn't see this – somehow I didn't get notified via email.
@Gipi66: I commented on the issue. You example above doesn't look that wrong – one thing that might help you understand if there's an error is checking the error returned from the views.Execute function above. Can you inspect that? Please also see the example in #51.
Still, I'm left wondering what's up with your function signature: func indexFunc(w http.ResponseWriter, r http.Request) { – that doesn't look like a controller action you use with Gin (that would be func indexFunc(c *gin.Context)). Yours looks more like a standard Go net/http request handler.
Mark Sargent
@sarge
Hey question, I want to support internationalization {{ msg "setting_title" }} - is that the intended syntax. I know I need to plug in my own translator
Daniel Lohse
@annismckenzie
@sarge Argh, Gitter still doesn't consistently notify me via email.
To answer your question: we added a global function named t and use it in the templates like so {{ t("setting_title") }}. You might have to curry it on a per request basis to provide it with the (user's) locale.
Mark Sargent
@sarge
no worries. I have run with a custom function for the moment. Is this the correct injection point - https://github.com/CloudyKit/jet/blob/master/template.go#L382
Daniel Lohse
@annismckenzie
As far as I understood @jhsx he wasn't finished with the I18n implementation. It looks usable but we started using Jet when it was still at version 1.x and I haven't touched that again yet. The issue is tracked in #3.
José Santos
@jhsx
@annismckenzie same thing with me, i never receive updates by email
Daniel Lohse
@annismckenzie
@jhsx I actually did receive an email notification with your message. Don't know what changed. :)
Jeff Lindsay
@progrium
awesome work with jet! is there any way to get access to a block's arguments as a map?
sort of like arguments in javascript or using kwargs in python
Jeff Lindsay
@progrium
Screen Shot 2017-11-03 at 6.37.46 PM.png
mildly successful using blocks as a sort of server side react component alternative, and then modeling semantic ui components in it
Screen Shot 2017-11-03 at 6.38.36 PM.png
payoff is not great for like a single anchor tag with an "item" class, but once it builds up to more complex components it should be pretty cool
the problem is the number of attributes those components have is quite large https://react.semantic-ui.com/collections/menu
and i think also lets you passthrough attributes, so we'd need variadic blocks or something
Jeff Lindsay
@progrium
at the end of the day it would be more practical to use semantic ui directly in html until a lot of conditional logic happens that you'd want to DRY up, but it would be nice if blocks had what was needed to model these kinds of components when necessary
Daniel Lohse
@annismckenzie
Wow, that's literally a gazillion props. I'm also not familiar with React (more of a Vue.js guy) but we usually try to keep the number of props of our own components down lest it becomes unwieldy. I do however see that this isn't possible for you. Here's what you could do: you could write a fast function as described in the docs: https://github.com/CloudyKit/jet/wiki/Advanced. It's generally not advisable to construct maps in a template context because they are quite heavy with regards to performance (reflection is used extensively behind the scenes) so you'd build a function that builds up your props. It's possible to make this variadic by setting a.RequireNumOfArguments("componentProps", 0, -1) (maybe the minimum number should be at least 2 and also divisible by 2?). Could you work with that?
Jeff Lindsay
@progrium
hmm, that's helpful, but maybe not enough. i'm thinking maybe fast functions instead of blocks? but i'd need functions that can take a content body template... hmm
also is there whitespace trimming syntax i'm not seeing?
Daniel Lohse
@annismckenzie
You raise a few good points to which I can only respond with that, generally, blocks are preferred because they are parsed and cached as well as more composable. I usually don't worry about whitespace trimming because our templates are packaged into the binary and delivered gzipped, making this a non-issue to me. There is an open issue, however: #34.
José Santos
@jhsx
I'm still not receiving notifications by mail
I think that will not be hard allow jet functions to accept a content block, @progrium let me know if this what you need.
Jeff Lindsay
@progrium
that could be helpful, though ... is the content body you can pass to a block a feature of yield or blocks? i can imagine using a jet function to help orchestrate the setting up of a "component" block, but it would still need that inner content to pass as well... i don't know, like {{ yield com(myComponent, args...) content }}<h1>Hello</h1>{{ end }}
where myComponent is ... a block maybe?
José Santos
@jhsx

@progrium you can pass the name of the block, and yield the block inside of JetFunc,

{{ yield com("myComponent", args...) content }}<h1>Hello</h1>{{ end }}

and what

    varmap := jet.VarMap{}
    varmap.SetFunc("com", func(arg jet.Arguments) reflect.Value {
        arg.Runtime().YieldBlock(arg.Get(0).String(),nil)
        arg.Content() // this  would yield the content passed to the func if any
        return reflect.Value{}
    })
Mark Sargent
@sarge
Just exploring what optional values look like, e.g. *string which could be nil or a pointer to a string. By default the pointer id will be rendered instead of dereferencing the pointer to get the string. Thoughts on a good approach to prevent this
Mark Sargent
@sarge
view.AddGlobalFunc("stringify", func(a jet.Arguments) reflect.Value {
    a.RequireNumOfArguments("stringify", 1, 1)

    if a.Get(0).Kind() == reflect.Ptr {
        if a.Get(0).IsNil() {
            return reflect.ValueOf("")
        }
        return reflect.ValueOf(fmt.Sprint(a.Get(0).Elem()))
    }

    buffer := bytes.NewBuffer(nil)
    fmt.Fprint(buffer, a.Get(0))
    return reflect.ValueOf(buffer.Bytes())
})
Daniel Lohse
@annismckenzie
Did you answer your own question? :grimacing: Hmmm, we could open an issue and investigate that printing a *string as an empty string if it's nil or dereference it if it's not?
Mark Sargent
@sarge
Yeah I did. In the end I removed the pointers in favour of a suitable default
Still in the case of a pointer, printing ,<nil> or the address of the value is never what you want
Daniel Lohse
@annismckenzie
Exactly what I was thinking.
Mark Sargent
@sarge
Also struck an issue dealing with pointers being passed to i18n as counts etc was causing more type coercion issues, I got the feeling that it was creating more issues than it was going to solve. Having to apply {{.MaybeAPointer | stringify}} is pretty tedious for a template developer to deal with.
Daniel Lohse
@annismckenzie
Hmmm, I see. Have an example?
Mark Sargent
@sarge
I i18n issue is my implementation issue. But to use the stringify solution above would require the template user to write {{.MaybeAPointer | stringify}} which isn't very usable
Where I got to is pointers make templates a bit harder and if you can avoid then it makes sense.
Daniel Lohse
@annismckenzie
You can find the PR with 2 failing test cases here: CloudyKit/jet#96
Let's see when and how we can fix that.
Mark Sargent
@sarge
Added a PR CloudyKit/jet#97
Mark Sargent
@sarge
Hey wondering about returning multiple parameters from a global function, so that I can check an internal cast has been successful {{if i, ok := globalFunction("args"); ok }}{{ . i }}{{end}} - get unexpected number of operands in assign on range - should this be possible?
cayter
@cayter
@annismckenzie hey thanks for this awesome library. I have a few questions:
  • would master branch be the latest stable branch to use? 'cause the latest release seems to be quite outdated (2017 Nov)
  • is there a plan to release new version?
  • what's the difference between VarMap and Context that are passed into Execute()?
voidhaze
@voidhaze
Hi guys, any one know if there is a equivalent of a break statement that can be used in range blocks?
simonli
@simonli
Hi Guys, how to use bind Jet with Gin?