Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App can't find embedded pug template files by go-bindata #1450

Closed
yansigit opened this issue Feb 14, 2020 · 8 comments
Closed

App can't find embedded pug template files by go-bindata #1450

yansigit opened this issue Feb 14, 2020 · 8 comments

Comments

@yansigit
Copy link

yansigit commented Feb 14, 2020

Output when running the app

user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 00:49 template:1: open layout.pug: no such file or directory  work dir: /home/user/Codes  for name 'delete.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 00:49 template:1: open layout.pug: no such file or directory  work dir: /home/user/Codes  for name 'edit.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 00:49 template:1: open layout.pug: no such file or directory  work dir: /home/user/Codes  for name 'delete.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 00:49 template:4: open header.pug: no such file or directory  work dir: /home/user/Codes  for name 'layout.pug'

Go source

tmpl := iris.Pug("./templates", ".pug").Binary(Asset, AssetNames)
app.RegisterView(tmpl)

Building scripts

go-bindata ./assets/... ./templates/...
go build

Folder structure

main.go
bindata.go
assets(folder)
ㄴ....
templates(folder)
ㄴdelete.pug
ㄴedit.pug
.
.
ㄴlayout.pug
ㄴindex.pug
.
.

bindata.go

// sources:
// assets/style/bulma.sass
// assets/style/sass/.DS_Store
// assets/style/sass/base/_all.sass
// assets/style/sass/base/generic.sass
.
.
.
// assets/style/style.scss
// templates/delete.pug
// templates/edit.pug
// templates/footer.pug
.
.
// templates/sidebar.pug
package main
.
.

All template files are imported in bindata.go well, and imported them on main source using Binary(Asset, AssetNames) too, but it's not working...
Pug files are all associated as expected with codes like include, block
Full source can be found in my repository

It's working if templates folder is on same location with compiled binary file, but what i want is embedding all static files to binary file.

I am not sure whether it's because of my mistake or bug, so I'll let it be as a question.

@kataras
Copy link
Owner

kataras commented Feb 14, 2020

Hello @yansigit, indeed pug engine has an issue on its .Binary. This is a very good and well-written bug report, expect a fix very soon.

@kataras
Copy link
Owner

kataras commented Feb 14, 2020

The issue is found at: https://github.com/Joker/jade/blob/d475f43051e722977ea1bfa344e52b1bafd832ba/jade_parse.go#L442-L454 which is called on pug include & extends directives and forces to read from directory even if we give the whole directory/contents, it's a bad design by its author because its Parse(name, contents) should not be depended on the filesystem at all. I think I have to deep in its parser itself, clone the repository, push a PR there and add a replace on our go.mod file for the jade/pug engine until the author accept the PR...

@kataras
Copy link
Owner

kataras commented Feb 14, 2020

It's fixed on master branch, you can test it out by go get -u github.com/kataras/iris/v12@master.

More improvements :

  • before that update the parser itself changed the current working directory to map extends templates - this is fixed too
  • you should now use extends layout.pug instead of the full path extends templates/layout.pug - makes template contents not relative to the root folder of the templates

It will be officially available on the next minor version, v12.1.8. I have to implement a new feature request before pushing the release (I am close to it too).

Again, thanks for the report.

@yansigit
Copy link
Author

Thank you for super fast update @kataras!
I wish i could solve the problem, but another error is popping up if i compile and execute binary with master branch.

user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 19:45 template:1: in '/home/user/Codes' subtemplate 'layout.pug': parseSubFile() error: template:4: open header.pug: no such file or directory  work dir: /home/user/Codes  for name 'delete.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 20:10 template:1: in '/home/user/Codes' subtemplate 'layout.pug': parseSubFile() error: template:4: open header.pug: no such file or directory  work dir: /home/user/Codes  for name 'index.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 20:10 template:1: in '/home/user/Codes' subtemplate 'layout.pug': parseSubFile() error: template:4: open header.pug: no such file or directory  work dir: /home/user/Codes  for name 'index.pug'
user@Home:~/Codes$ ./linux_x64
title_1
[ERRO] 2020/02/15 20:10 template:1: in '/home/user/Codes' subtemplate 'layout.pug': parseSubFile() error: template:4: open header.pug: no such file or directory  work dir: /home/user/Codes  for name 'edit.pug'
user@Home:~/Codes$

go.mod

module frescawiki

go 1.13

require (
	github.com/Kamva/mgm v1.2.1
	github.com/kataras/iris/v12 v12.1.8-0.20200214213456-387c90b350d5
	github.com/klauspost/compress v1.10.0 // indirect
	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
	github.com/modern-go/reflect2 v1.0.1 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
	github.com/yuin/goldmark v1.1.22
	go.mongodb.org/mongo-driver v1.3.0
	golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 // indirect
	golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
	golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
	gopkg.in/ini.v1 v1.52.0 // indirect
	gopkg.in/yaml.v2 v2.2.8 // indirect
	gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71 // indirect
)

build scripts

go-bindata ./assets/... ./templates/...
go build

Another difference is that the app cannot recognize template files even if it has template folder on same directory now.
Again, full source can be found at Here

@kataras
Copy link
Owner

kataras commented Feb 15, 2020

Hmm @yansigit this works here, I tested it without the templates and with the templates folder yesterday. Let me check it again.

kataras added a commit to iris-contrib/jade that referenced this issue Feb 15, 2020
kataras added a commit that referenced this issue Feb 15, 2020
kataras added a commit that referenced this issue Feb 15, 2020
@kataras
Copy link
Owner

kataras commented Feb 15, 2020

OK @yansigit, it was a minor addition... it really hurts my eyes (the code of jade go parser) but we support it so I fixed it, please test it and sorry for spent your time with this one.

isssss

@yansigit
Copy link
Author

Thank you @kataras, working like a charm after updating framework 😊
I'll try to debug myself and submit a PR next time. Thanks for your effort again!

@kataras
Copy link
Owner

kataras commented Feb 16, 2020

No worries, but yes debugging is the best way to learn the framework too :) Just pushed the v12.1.8 release which brings support for grpc-compatible controllers too! go get -u github.com/kataras/iris/v12@latest

github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: 617f64d061e88f050a443ea1751fa244164656c5
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: 43318477e7f8bf5f8c35fbf2f53922909a11d8fd
github-actions bot pushed a commit to goproxies/github.com-kataras-iris that referenced this issue Jul 27, 2020
Former-commit-id: 2b8dfec7d43298bc9ace94595359867180634f04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants