1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

move embedded assets to separate directory

This commit is contained in:
Elliott Stoneham 2016-07-22 20:56:56 +01:00
parent 1be2000bb7
commit 0b8a0fd5dc
7 changed files with 13286 additions and 25 deletions

2
.gitignore vendored
View file

@ -17,7 +17,7 @@ _convert
# Documize build artifacts # Documize build artifacts
bin/* bin/*
dist/* dist/*
/core/web/bindata/* embed/bindata/*
app/dist/* app/dist/*
app/dist-prod/* app/dist-prod/*

View file

@ -13,30 +13,30 @@ ember b -o dist-prod/ --environment=production intercom=$intercomKey
echo "Copying Ember assets..." echo "Copying Ember assets..."
cd .. cd ..
rm -rf core/web/bindata/public rm -rf embed/bindata/public
mkdir -p core/web/bindata/public mkdir -p embed/bindata/public
cp -r app/dist-prod/assets core/web/bindata/public cp -r app/dist-prod/assets embed/bindata/public
cp -r app/dist-prod/codemirror core/web/bindata/public/codemirror cp -r app/dist-prod/codemirror embed/bindata/public/codemirror
cp -r app/dist-prod/tinymce core/web/bindata/public/tinymce cp -r app/dist-prod/tinymce embed/bindata/public/tinymce
cp -r app/dist-prod/sections core/web/bindata/public/sections cp -r app/dist-prod/sections embed/bindata/public/sections
cp app/dist-prod/*.* core/web/bindata cp app/dist-prod/*.* embed/bindata
cp app/dist-prod/favicon.ico core/web/bindata/public cp app/dist-prod/favicon.ico embed/bindata/public
rm -rf core/web/bindata/mail rm -rf embed/bindata/mail
mkdir -p core/web/bindata/mail mkdir -p embed/bindata/mail
cp core/api/mail/*.html core/web/bindata/mail cp core/api/mail/*.html embed/bindata/mail
cp core/database/templates/*.html core/web/bindata cp core/database/templates/*.html embed/bindata
rm -rf core/web/bindata/scripts rm -rf embed/bindata/scripts
mkdir -p core/web/bindata/scripts mkdir -p embed/bindata/scripts
cp -r core/database/scripts/autobuild/*.sql core/web/bindata/scripts cp -r core/database/scripts/autobuild/*.sql embed/bindata/scripts
echo "Generating in-memory static assets..." echo "Generating in-memory static assets..."
go get -u github.com/jteeuwen/go-bindata/... go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/elazarl/go-bindata-assetfs/... go get -u github.com/elazarl/go-bindata-assetfs/...
cd core/web cd embed
go generate go generate
echo "Compiling app..." echo "Compiling app..."
cd ../.. cd ..
for arch in amd64 ; do for arch in amd64 ; do
for os in darwin linux windows ; do for os in darwin linux windows ; do
if [ "$os" == "windows" ] ; then if [ "$os" == "windows" ] ; then

View file

@ -17,6 +17,8 @@ import (
"github.com/documize/community/core/environment" "github.com/documize/community/core/environment"
"github.com/documize/community/core/section" "github.com/documize/community/core/section"
_ "github.com/documize/community/embed" // the compressed front-end code and static data
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes _ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
) )

View file

@ -12,16 +12,12 @@
// Package web contains the Documize static web data. // Package web contains the Documize static web data.
package web package web
//go:generate go-bindata-assetfs -pkg web bindata/...
import ( import (
"html/template" "html/template"
"net/http" "net/http"
"github.com/documize/community/core/api/util" "github.com/documize/community/core/api/util"
"github.com/documize/community/core/environment" "github.com/documize/community/core/environment"
assetfs "github.com/elazarl/go-bindata-assetfs"
) )
// SiteMode defines that the web server should show the system to be in a particular state. // SiteMode defines that the web server should show the system to be in a particular state.
@ -48,6 +44,16 @@ func init() {
SiteInfo.DBhash = util.GenerateRandomPassword() // do this only once SiteInfo.DBhash = util.GenerateRandomPassword() // do this only once
} }
// EmbedHandler is defined in each embed directory
type EmbedHandler interface {
Asset(string) ([]byte, error)
AssetDir(string) ([]string, error)
StaticAssetsFileSystem() http.FileSystem
}
// Embed allows access to the embedded data
var Embed EmbedHandler
// EmberHandler provides the webserver for pages developed using the Ember programming environment. // EmberHandler provides the webserver for pages developed using the Ember programming environment.
func EmberHandler(w http.ResponseWriter, r *http.Request) { func EmberHandler(w http.ResponseWriter, r *http.Request) {
filename := "index.html" filename := "index.html"
@ -62,7 +68,7 @@ func EmberHandler(w http.ResponseWriter, r *http.Request) {
SiteInfo.DBhash = "" SiteInfo.DBhash = ""
} }
data, err := Asset("bindata/" + filename) data, err := Embed.Asset("bindata/" + filename)
if err != nil { if err != nil {
// Asset was not found. // Asset was not found.
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
@ -78,10 +84,20 @@ func EmberHandler(w http.ResponseWriter, r *http.Request) {
// StaticAssetsFileSystem data encoded in the go:generate above. // StaticAssetsFileSystem data encoded in the go:generate above.
func StaticAssetsFileSystem() http.FileSystem { func StaticAssetsFileSystem() http.FileSystem {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "bindata/public"} return Embed.StaticAssetsFileSystem()
//return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "bindata/public"}
} }
// ReadFile is intended to substitute for ioutil.ReadFile(). // ReadFile is intended to substitute for ioutil.ReadFile().
func ReadFile(filename string) ([]byte, error) { func ReadFile(filename string) ([]byte, error) {
return Asset("bindata/" + filename) return Embed.Asset("bindata/" + filename)
}
// Asset fetch.
func Asset(location string) ([]byte, error) {
return Embed.Asset(location)
}
func AssetDir(dir string) ([]string, error) {
return Embed.AssetDir(dir)
} }

13199
embed/bindata_assetfs.go Normal file

File diff suppressed because one or more lines are too long

44
embed/embed.go Normal file
View file

@ -0,0 +1,44 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
// Package embed contains the Documize static web data.
package embed
//go:generate go-bindata-assetfs -pkg embed bindata/...
import (
"net/http"
"github.com/documize/community/core/web"
assetfs "github.com/elazarl/go-bindata-assetfs"
)
type embedderT struct{}
func (embedderT) Asset(name string) ([]byte, error) {
return Asset(name)
}
func (embedderT) AssetDir(dir string) ([]string, error) {
return AssetDir(dir)
}
// StaticAssetsFileSystem data encoded in the go:generate above.
func (embedderT) StaticAssetsFileSystem() http.FileSystem {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "bindata/public"}
}
var embedder embedderT
func init() {
web.Embed = embedder
}