Skip to content

Commit b6a95a8

Browse files
tboergerlunny
authored andcommitted
Integrate public as bindata optionally (#293)
* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
1 parent 4680c34 commit b6a95a8

File tree

691 files changed

+305318
-1272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

691 files changed

+305318
-1272
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ _testmain.go
2828

2929
coverage.out
3030

31+
/modules/public/bindata.go
32+
3133
*.db
3234
*.log
3335

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ clean:
3737
go clean -i ./...
3838
rm -rf $(BIN) $(DIST)
3939

40-
.PHONY: deps
41-
deps:
42-
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
43-
go get -u github.com/jteeuwen/go-bindata/...; \
44-
fi
45-
4640
.PHONY: fmt
4741
fmt:
4842
go fmt $(PACKAGES)
@@ -51,6 +45,13 @@ fmt:
5145
vet:
5246
go vet $(PACKAGES)
5347

48+
.PHONY: generate
49+
generate:
50+
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
51+
go get -u github.com/jteeuwen/go-bindata/...; \
52+
fi
53+
go generate $(PACKAGES)
54+
5455
.PHONY: errcheck
5556
errcheck:
5657
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
@@ -129,6 +130,9 @@ bindata: modules/bindata/bindata.go
129130

130131
.IGNORE: modules/bindata/bindata.go
131132
modules/bindata/bindata.go: $(BINDATA)
133+
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
134+
go get -u github.com/jteeuwen/go-bindata/...; \
135+
fi
132136
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
133137
go fmt $@
134138
sed -i.bak 's/confLocaleLocale_/confLocaleLocale/' $@
@@ -148,5 +152,5 @@ stylesheets: public/css/index.css
148152
public/css/index.css: $(STYLESHEETS)
149153
lessc $< $@
150154

151-
.PHONY: generate
152-
generate: bindata javascripts stylesheets
155+
.PHONY: assets
156+
assets: bindata javascripts stylesheets

cmd/web.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/bindata"
2222
"code.gitea.io/gitea/modules/context"
2323
"code.gitea.io/gitea/modules/log"
24+
"code.gitea.io/gitea/modules/public"
2425
"code.gitea.io/gitea/modules/setting"
2526
"code.gitea.io/gitea/modules/template"
2627
"code.gitea.io/gitea/routers"
@@ -125,9 +126,9 @@ func newMacaron() *macaron.Macaron {
125126
if setting.Protocol == setting.FCGI {
126127
m.SetURLPrefix(setting.AppSubURL)
127128
}
128-
m.Use(macaron.Static(
129-
path.Join(setting.StaticRootPath, "public"),
130-
macaron.StaticOptions{
129+
m.Use(public.Static(
130+
&public.Options{
131+
Directory: path.Join(setting.StaticRootPath, "public"),
131132
SkipLogging: setting.DisableRouterLog,
132133
},
133134
))

modules/public/dynamic.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build !bindata
2+
3+
// Copyright 2016 The Gitea Authors. All rights reserved.
4+
// Use of this source code is governed by a MIT-style
5+
// license that can be found in the LICENSE file.
6+
7+
package public
8+
9+
import (
10+
"gopkg.in/macaron.v1"
11+
)
12+
13+
// Static implements the macaron static handler for serving assets.
14+
func Static(opts *Options) macaron.Handler {
15+
return macaron.Static(
16+
opts.Directory,
17+
macaron.StaticOptions{
18+
SkipLogging: opts.SkipLogging,
19+
},
20+
)
21+
}

modules/public/public.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package public
6+
7+
//go:generate go-bindata -tags "bindata" -ignore "\\.go|\\.less" -pkg "public" -o "bindata.go" ../../public/...
8+
//go:generate go fmt bindata.go
9+
10+
// Options represents the available options to configure the macaron handler.
11+
type Options struct {
12+
Directory string
13+
SkipLogging bool
14+
}

modules/public/static.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build bindata
2+
3+
// Copyright 2016 The Gitea Authors. All rights reserved.
4+
// Use of this source code is governed by a MIT-style
5+
// license that can be found in the LICENSE file.
6+
7+
package public
8+
9+
import (
10+
"github.com/go-macaron/bindata"
11+
"gopkg.in/macaron.v1"
12+
)
13+
14+
// Static implements the macaron static handler for serving assets.
15+
func Static(opts *Options) macaron.Handler {
16+
return macaron.Static(
17+
opts.Directory,
18+
macaron.StaticOptions{
19+
SkipLogging: opts.SkipLogging,
20+
FileSystem: bindata.Static(bindata.Options{
21+
Asset: Asset,
22+
AssetDir: AssetDir,
23+
AssetInfo: AssetInfo,
24+
AssetNames: AssetNames,
25+
Prefix: "../../public",
26+
}),
27+
},
28+
)
29+
}

0 commit comments

Comments
 (0)