Browse files

add base.html and convert main.html to use it

  • Loading branch information...
1 parent 8b9613c commit cb88517cc7cef0d3530214731efeef2469339e0d @kjk committed May 20, 2012
Showing with 50 additions and 44 deletions.
  1. +22 −2 main.go
  2. +1 −1 run.sh
  3. +1 −0 www/app.html
  4. +25 −0 www/base.html
  5. +1 −41 www/main.html
View
24 main.go
@@ -247,7 +247,8 @@ var (
tmplMain = "main.html"
tmplApp = "app.html"
tmplAppTrans = "apptrans.html"
- templateNames = [...]string{tmplMain, tmplApp, tmplAppTrans}
+ tmplBase = "base.html"
+ templateNames = [...]string{tmplMain, tmplApp, tmplAppTrans, tmplBase}
templatePaths = make([]string, 0)
templates *template.Template
reloadTemplates = true
@@ -367,13 +368,32 @@ type ModelMain struct {
ErrorMsg string
}
+type content struct {
+ ContentHTML template.HTML
+}
+
+type templateParser struct {
+ HTML string
+}
+
+func (tP *templateParser) Write(p []byte) (n int, err error){
+ tP.HTML += string(p)
+ return len(p), nil
+}
+
// handler for url: /
func handleMain(w http.ResponseWriter, r *http.Request) {
model := &ModelMain{&appState.Apps, true, ""}
- if err := GetTemplates().ExecuteTemplate(w, tmplMain, model); err != nil {
+ tp := &templateParser{}
+ if err := GetTemplates().ExecuteTemplate(tp, tmplMain, model); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
+ content := &content{template.HTML(tp.HTML)}
+ if err := GetTemplates().ExecuteTemplate(w, tmplBase, content); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
}
func appAlreadyExists(appName string) bool {
View
2 run.sh
@@ -1,2 +1,2 @@
-export GOPATH=`pwd`/ext
+export GOPATH=$GOPATH:`pwd`/ext
go run main.go langs.go
View
1 www/app.html
@@ -11,6 +11,7 @@
<body>
<div class="container">
+
<header class="jumbotron subhead" id="overview">
<h1>Translations for {{.App.Name}}</h1>
<p class="lead">There are {{.App.StringsCount}} strings translated
View
25 www/base.html
@@ -0,0 +1,25 @@
+<!doctype html>
+<html lang="en">
+<head>
+<link href="/static/css/bootstrap.css" rel="stylesheet">
+<link href="/static/css/bootstrap-responsive.css" rel="stylesheet">
+<!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+<![endif]-->
+</head>
+
+<body>
+
+<div class="container">
+{{.ContentHTML}}
+</div>
+
+<hr style="margin:4px">
+<center style="padding-bottom:12px"><a href="/">App Translator</a>, lovingly crafted by <a href="http://blog.kowalczyk.info">Krzysztof Kowalczyk<a></center>
+
+<!-- placed at the end for faster loading -->
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+<script src="/static/js/bootstrap.js"></script>
+
+</body>
+</html>
View
42 www/main.html
@@ -1,28 +1,7 @@
-<!doctype html>
-<html lang="en">
-<head>
-<link href="/static/css/bootstrap.css" rel="stylesheet">
-<link href="/static/css/bootstrap-responsive.css" rel="stylesheet">
-<!--[if lt IE 9]>
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
-<![endif]-->
-</head>
-
-<body>
-
-<div class="container">
<header class="jumbotron subhead" id="overview">
<h1>App Translator</h1>
- <p class="lead">We help desktop software developers
-translate their apps from English to other languages with the
-help of their users.</p>
+ <p class="lead">Crowd-sourced translations for software.</p>
</header>
-<!--
-<p><b>Developer?</b> You can add your application, submit
-strings for translation and download user submitted translations.</p>
-<p><b>User?</b> You can help translate your favourite app
-to your language.</p>
--->
{{if len .Apps}}
<p>Applications:</p>
@@ -78,23 +57,4 @@
{{else}}
<a href="/login">Log in</a> to add your application.
{{end}}
-</div>
-->
-
-<hr style="margin:4px">
-<center style="padding-bottom:12px"><a href="/">App Translator</a>, lovingly crafted by <a href="http://blog.kowalczyk.info">Krzysztof Kowalczyk<a></center>
-
-<!-- placed at the end for faster loading -->
-<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
-<script src="/static/js/bootstrap.js"></script>
-
-<script>
-
-{{if .ErrorMsg}}
-$("#errorMsg").modal('show');
-{{end}}
-
-</script>
-
-</body>
-</html>

0 comments on commit cb88517

Please sign in to comment.