newui layout, only for dev-server use for now.

Change-Id: I0e77b8088b2e04fd56e017678cb6e0a476b10682
This commit is contained in:
mpl 2012-12-03 23:46:08 +01:00
parent 6cb3b6d69f
commit 19edba9f64
6 changed files with 95 additions and 5 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ clients/go/camwebdav/camwebdav
appengine-sdk
build/root
.DS_Store
tmp/closure

View File

@ -9,6 +9,9 @@ sub usage {
die "Usage: dev-server [--wipe] [--mongo|--memory] [--tls] <portnumber> -- [other_blobserver_opts]";
}
my $closure_rev = "r2322";
my $closure_svn = "http://closure-library.googlecode.com/svn/trunk/";
chdir $Bin or die;
my $opt_wipe;
@ -125,8 +128,6 @@ if ($opt_tls) {
$base =~ s/^http/https/;
}
print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
$ENV{CAMLI_TLS} = "false";
if ($opt_tls) {
$ENV{CAMLI_TLS} = "true";
@ -155,8 +156,25 @@ if ($opt_wipe && -d $templatedir) {
# binary:
unless ($opt_staticres) {
$ENV{CAMLI_DEV_UI_FILES} = "$FindBin::Bin/server/camlistored/ui"; # set in server/camlistored/ui/fileembed.go
$ENV{CAMLI_DEV_NEWUI_FILES} = "$FindBin::Bin/server/camlistored/newui"; # set in server/camlistored/newui/fileembed.go
my $closure_dir = "tmp/closure";
if (-d $closure_dir) {
chdir $closure_dir or die;
my $local_rev = "r" . `svnversion`;
chomp($local_rev);
if ($local_rev ne $closure_rev) {
system("svn", "update", "-r", $closure_rev)
and die "Failed to svn up the closure library: $!\n";
}
chdir $Bin or die;
} else {
system("svn", "checkout", "-r", $closure_rev, $closure_svn, "tmp")
and die "Failed to svn co the closure library: $!\n";
}
}
print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
exec("$camlistored",
"-configfile=$Bin/config/dev-server-config.json",
"-listen=$listen",

View File

@ -22,6 +22,7 @@ import (
"log"
"net/http"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
@ -30,14 +31,16 @@ import (
"camlistore.org/pkg/blobserver"
"camlistore.org/pkg/httputil"
"camlistore.org/pkg/jsonconfig"
newuistatic "camlistore.org/server/camlistored/newui"
uistatic "camlistore.org/server/camlistored/ui"
)
var _ = log.Printf
var (
staticFilePattern = regexp.MustCompile(`^([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`)
identPattern = regexp.MustCompile(`^[a-zA-Z\_]+$`)
staticFilePattern = regexp.MustCompile(`^([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`)
static2FilePattern = regexp.MustCompile(`^(new/)([a-zA-Z0-9\-\_]+\.(html|js|css|png|jpg|gif))$`)
identPattern = regexp.MustCompile(`^[a-zA-Z\_]+$`)
// Download URL suffix:
// $1: blobref (checked in download handler)
@ -46,9 +49,11 @@ var (
downloadPattern = regexp.MustCompile(`^download/([^/]+)(/.*)?$`)
thumbnailPattern = regexp.MustCompile(`^thumbnail/([^/]+)(/.*)?$`)
treePattern = regexp.MustCompile(`^tree/([^/]+)(/.*)?$`)
closurePattern = regexp.MustCompile(`^(new/closure/)([^/]+)(/.*)?$`)
)
var uiFiles = uistatic.Files
var newuiFiles = newuistatic.Files
// UIHandler handles serving the UI and discovery JSON.
type UIHandler struct {
@ -68,7 +73,9 @@ type UIHandler struct {
Cache blobserver.Storage // or nil
sc ScaledImage // cache for scaled images, optional
staticHandler http.Handler
staticHandler http.Handler
staticHandler2 http.Handler // for the new ui
closureHandler http.Handler
}
func init() {
@ -134,6 +141,10 @@ func newUIFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler,
}
ui.staticHandler = http.FileServer(uiFiles)
ui.staticHandler2 = http.FileServer(newuiFiles)
// TODO(mpl): figure out camliroot and use an abs path
closureDir := filepath.Join("tmp", "closure")
ui.closureHandler = http.FileServer(http.Dir(closureDir))
rootPrefix, _, err := ld.FindHandlerByType("root")
if err != nil {
@ -203,6 +214,17 @@ func (ui *UIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
file := ""
if m := staticFilePattern.FindStringSubmatch(suffix); m != nil {
file = m[1]
// TODO(mpl): change the regexp to make it not match the stripped part
} else if m := static2FilePattern.FindStringSubmatch(suffix); m != nil {
file = strings.Replace(suffix, m[1], "", 1)
req.URL.Path = "/" + file
ui.staticHandler2.ServeHTTP(rw, req)
break
} else if m := closurePattern.FindStringSubmatch(suffix); m != nil {
file = strings.Replace(suffix, m[1], "", 1)
req.URL.Path = "/" + file
ui.closureHandler.ServeHTTP(rw, req)
break
} else {
switch {
case wantsRecentPermanodes(req):

View File

@ -0,0 +1,28 @@
/*
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
#fileembed pattern .+\.(js|css|html|png)$
*/
package newui
import (
"camlistore.org/pkg/fileembed"
)
var Files = &fileembed.Files{
OverrideEnv: "CAMLI_DEV_NEWUI_FILES",
}

View File

@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<script src="closure/goog/base.js"></script>
<script src="home.js"></script>
</head>
<body>
<script>
home.hello();
</script>
</body>
</html>

View File

@ -0,0 +1,8 @@
goog.provide('home');
goog.require('goog.dom');
home.hello = function() {
var h1 = goog.dom.createDom('h1', {'style': 'background-color:#EEE'},
'Welcome to the new camlistore ui');
goog.dom.appendChild(document.body, h1);
}