Skip to content

Commit

Permalink
Integrate public as bindata optionally (#293)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tboerger authored and lunny committed Nov 29, 2016
1 parent 4680c34 commit b6a95a8
Show file tree
Hide file tree
Showing 691 changed files with 305,318 additions and 1,272 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ _testmain.go

coverage.out

/modules/public/bindata.go

*.db
*.log

Expand Down
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ clean:
go clean -i ./...
rm -rf $(BIN) $(DIST)

.PHONY: deps
deps:
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/jteeuwen/go-bindata/...; \
fi

.PHONY: fmt
fmt:
go fmt $(PACKAGES)
Expand All @@ -51,6 +45,13 @@ fmt:
vet:
go vet $(PACKAGES)

.PHONY: generate
generate:
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/jteeuwen/go-bindata/...; \
fi
go generate $(PACKAGES)

.PHONY: errcheck
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
Expand Down Expand Up @@ -129,6 +130,9 @@ bindata: modules/bindata/bindata.go

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

.PHONY: generate
generate: bindata javascripts stylesheets
.PHONY: assets
assets: bindata javascripts stylesheets
7 changes: 4 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/template"
"code.gitea.io/gitea/routers"
Expand Down Expand Up @@ -125,9 +126,9 @@ func newMacaron() *macaron.Macaron {
if setting.Protocol == setting.FCGI {
m.SetURLPrefix(setting.AppSubURL)
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
m.Use(public.Static(
&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
SkipLogging: setting.DisableRouterLog,
},
))
Expand Down
21 changes: 21 additions & 0 deletions modules/public/dynamic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build !bindata

// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package public

import (
"gopkg.in/macaron.v1"
)

// Static implements the macaron static handler for serving assets.
func Static(opts *Options) macaron.Handler {
return macaron.Static(
opts.Directory,
macaron.StaticOptions{
SkipLogging: opts.SkipLogging,
},
)
}
14 changes: 14 additions & 0 deletions modules/public/public.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package public

//go:generate go-bindata -tags "bindata" -ignore "\\.go|\\.less" -pkg "public" -o "bindata.go" ../../public/...
//go:generate go fmt bindata.go

// Options represents the available options to configure the macaron handler.
type Options struct {
Directory string
SkipLogging bool
}
29 changes: 29 additions & 0 deletions modules/public/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build bindata

// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package public

import (
"github.com/go-macaron/bindata"
"gopkg.in/macaron.v1"
)

// Static implements the macaron static handler for serving assets.
func Static(opts *Options) macaron.Handler {
return macaron.Static(
opts.Directory,
macaron.StaticOptions{
SkipLogging: opts.SkipLogging,
FileSystem: bindata.Static(bindata.Options{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
AssetNames: AssetNames,
Prefix: "../../public",
}),
},
)
}
Loading

0 comments on commit b6a95a8

Please sign in to comment.