Skip to content

Commit

Permalink
Merge pull request #30 from ancientHacker/v0.8
Browse files Browse the repository at this point in the history
fix issues 24 and 29; ready to release v0.8
(build footer finally works in the review app, now to try stage itself.)
  • Loading branch information
brotskydotcom committed Dec 27, 2015
2 parents ca0fd71 + 7ad55da commit ea03ba2
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 49 deletions.
15 changes: 14 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
"scripts": {
},
"env": {
"REDISTOGO_ENV": "dev"
"REDISTOGO_ENV": "dev",
"APPLICATION_ENV": "dev",
"HEROKU_APP_NAME": {
"required": true
},
"HEROKU_RELEASE_VERSION": {
"required": false
},
"HEROKU_SLUG_COMMIT": {
"required": false
},
"HEROKU_DYNO_ID": {
"required": false
}
},
"addons": [
"papertrail",
Expand Down
14 changes: 9 additions & 5 deletions client/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ Common client settings
*/

const (
applicationName = "Sūsen"
applicationVersion = "0.7"
templatePageSuffix = "Page.tmpl.html"
defaultTemplateDirectoryEnvVar = "TEMPLATE_DIRECTORY"
defaultStaticDirectoryEnvVar = "STATIC_DIRECTORY"
iconPath = "/favicon.ico"
reportBugPath = "/bugreport.html"
templatePageSuffix = "Page.tmpl.html"
applicationNameEnvVar = "HEROKU_APP_NAME"
applicationVersionEnvVar = "HEROKU_RELEASE_VERSION"
applicationBuildEnvVar = "HEROKU_SLUG_COMMIT"
applicationInstanceEnvVar = "HEROKU_DYNO_ID"
applicationEnvEnvVar = "APPLICATION_ENV"
)

var (
brandName = "Sūsen"
iconPath = "/favicon.ico"
reportBugPath = "/bugreport.html"
defaultStaticDirectory = "static"
defaultTemplateDirectory = filepath.Join(defaultStaticDirectory, "tmpl")
staticResourcePaths = map[string]string{
Expand Down
98 changes: 76 additions & 22 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ancientHacker/susen.go/puzzle"
"html/template"
"os"
"path/filepath"
)

Expand All @@ -19,13 +20,14 @@ solver pages
// findSolverPageTemplate for template location details.
var solverPageTemplate *template.Template

// A templateSolverPage contains the values to file the solver
// A templateSolverPage contains the values to fill the solver
// page template.
type templateSolverPage struct {
SessionID, PuzzleID string
Title, TopHead string
IconFile, CssFile, JsFile string
Puzzle templatePuzzle
ApplicationFooter string
}

// templatePuzzle is the structure expected by the puzzle grid
Expand Down Expand Up @@ -65,14 +67,15 @@ func SolverPage(sessionID string, puzzleID string, state *puzzle.State) string {
}

tsp := templateSolverPage{
SessionID: sessionID,
PuzzleID: puzzleID,
Title: fmt.Sprintf("%s: Solver", applicationName),
TopHead: fmt.Sprintf("%s v%s Puzzle Solver", applicationName, applicationVersion),
IconFile: iconPath,
CssFile: "/solver.css",
JsFile: "/solver.js",
Puzzle: tp,
SessionID: sessionID,
PuzzleID: puzzleID,
Title: fmt.Sprintf("%s: Solver", brandName),
TopHead: fmt.Sprintf("Puzzle Solver"),
IconFile: iconPath,
CssFile: "/solver.css",
JsFile: "/solver.js",
Puzzle: tp,
ApplicationFooter: applicationFooter(),
}

tmpl, err := loadPageTemplate("solver")
Expand Down Expand Up @@ -239,16 +242,18 @@ error pages
type templateErrorPage struct {
Title, TopHead, Message string
IconFile, ReportBugPage string
ApplicationFooter string
}

// return error page content
func errorPage(e error) string {
tep := templateErrorPage{
Title: fmt.Sprintf("%s: Error", applicationName),
TopHead: fmt.Sprintf("%s v%s Error Page", applicationName, applicationVersion),
Message: e.Error(),
IconFile: iconPath,
ReportBugPage: reportBugPath,
Title: fmt.Sprintf("%s: Error", brandName),
TopHead: fmt.Sprintf("Error Page"),
Message: e.Error(),
IconFile: iconPath,
ReportBugPage: reportBugPath,
ApplicationFooter: applicationFooter(),
}

tmpl, err := loadPageTemplate("error")
Expand Down Expand Up @@ -282,6 +287,7 @@ type templateHomePage struct {
Title, TopHead string
IconFile, CssFile, JsFile string
PuzzleIDs []string
ApplicationFooter string
}

// add home statics to the static list
Expand All @@ -296,14 +302,15 @@ func init() {
// page content as a string.
func HomePage(sessionID string, puzzleID string, puzzleIDs []string) string {
tsp := templateHomePage{
SessionID: sessionID,
PuzzleID: puzzleID,
Title: fmt.Sprintf("%s: Home", applicationName),
TopHead: fmt.Sprintf("%s v%s Home", applicationName, applicationVersion),
IconFile: iconPath,
CssFile: "/home.css",
JsFile: "/home.js",
PuzzleIDs: puzzleIDs,
SessionID: sessionID,
PuzzleID: puzzleID,
Title: fmt.Sprintf("%s: Home", brandName),
TopHead: fmt.Sprintf("%s", brandName),
IconFile: iconPath,
CssFile: "/home.css",
JsFile: "/home.js",
PuzzleIDs: puzzleIDs,
ApplicationFooter: applicationFooter(),
}

tmpl, err := loadPageTemplate("home")
Expand All @@ -317,3 +324,50 @@ func HomePage(sessionID string, puzzleID string, puzzleIDs []string) string {
}
return buf.String()
}

/*
application footer
*/

// applicationFooter - the application footer that shows at the
// bottom of all pages.
func applicationFooter() string {
appName := os.Getenv(applicationNameEnvVar)
appEnv := os.Getenv(applicationEnvEnvVar)
appVersion := os.Getenv(applicationVersionEnvVar)
appInstance := os.Getenv(applicationInstanceEnvVar)
appBuild := os.Getenv(applicationBuildEnvVar)

if appName == "" {
appName = brandName
}

if appEnv == "" {
appEnv = "local"
}

if appVersion != "" {
appVersion = " " + appVersion
}
if len(appBuild) >= 7 {
appBuild = appBuild[:7]
}

if appInstance != "" {
appInstance = " (dyno " + appInstance + ")"
}

switch appEnv {
case "local":
return "[" + appName + " local]"
case "dev":
return "[" + appName + " CI/CD]"
case "stg":
return "[" + appName + appVersion + " <" + appBuild + ">]"
case "prd":
return "[" + appName + appVersion + " <" + appBuild + ">" + appInstance + "]"
}
return "[" + appName + " <??>]"
}
46 changes: 46 additions & 0 deletions client/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ func TestSolverPage(t *testing.T) {

/*
footer
*/

type footerTestcase struct {
name, version, instance, build, env string
footer string
}

func TestApplicationFooter(t *testing.T) {
testcases := []footerTestcase{
{"", "", "", "", "",
"[" + brandName + " local]"},
{"susen-staging-pr-30",
"v29",
"",
"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
"dev",
"[susen-staging-pr-30 CI/CD]"},
{"susen-staging",
"v29",
"1vac4117-c29f-4312-521e-ba4d8638c1ac",
"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
"stg",
"[susen-staging v29 <ca0fd71>]"},
{"susen-production",
"v22",
"1vac4117-c29f-4312-521e-ba4d8638c1ac",
"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
"prd",
"[susen-production v22 <ca0fd71> (dyno 1vac4117-c29f-4312-521e-ba4d8638c1ac)]"},
}
for i, tc := range testcases {
os.Setenv(applicationNameEnvVar, tc.name)
os.Setenv(applicationVersionEnvVar, tc.version)
os.Setenv(applicationInstanceEnvVar, tc.instance)
os.Setenv(applicationBuildEnvVar, tc.build)
os.Setenv(applicationEnvEnvVar, tc.env)
if footer := applicationFooter(); footer != tc.footer {
t.Errorf("Case %d: got %q, expected %q", i, footer, tc.footer)
}
}
}

/*
helpers
*/
Expand Down
5 changes: 3 additions & 2 deletions client/testdata/TestErrorPage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/favicon.ico" />
</head>
<body>
<h1>Sūsen v0.7 Error Page</h1>
<h1>Error Page</h1>
<p>Sorry, a server error has occurred while generating this page. The English description of the error is:</p>
<blockquote><em>Test Error 0</em></blockquote>
<p>To report this error, <a href="/bugreport.html">click here</a>.</p>
<p>To report this error, <a href="/bugreport.html">click here</a>. When reporting your error, please include the following build info:</p>
<p>[Sūsen local]</p>
</body>
</html>
5 changes: 4 additions & 1 deletion client/testdata/TestHomePage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script src="/home.js"></script>
</head>
<body sessionID="httpx-Test0" puzzleID="test-0" onload="initializePage()">
<h1>Sūsen v0.7 Home</h1>
<h1>Sūsen</h1>
<div class="home">
<div class="left">
<div class="activity">
Expand Down Expand Up @@ -39,5 +39,8 @@ <h3>Solve a Puzzle</h3>
</div>
</div>
</div>
<div class="footer">
<p>[Sūsen local]</p>
</div>
</body>
</html>
5 changes: 4 additions & 1 deletion client/testdata/TestSolverPage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body sessionID="httpx-Test0" puzzleID="test-0"
onload="initializePage( 4 )" onclick="clickNowhere(event);">
<h1>Sūsen v0.7 Puzzle Solver</h1>
<h1>Puzzle Solver</h1>
<div class="puzzle">
<table>
<tr>
Expand Down Expand Up @@ -131,5 +131,8 @@ <h1>Sūsen v0.7 Puzzle Solver</h1>
</div>
</div>
</div>
<div class="footer">
<p>[Sūsen local]</p>
</div>
</body>
</html>
5 changes: 4 additions & 1 deletion client/testdata/TestSolverPage1.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body sessionID="https-Test1" puzzleID="test-1"
onload="initializePage( 9 )" onclick="clickNowhere(event);">
<h1>Sūsen v0.7 Puzzle Solver</h1>
<h1>Puzzle Solver</h1>
<div class="puzzle">
<table>
<tr>
Expand Down Expand Up @@ -421,5 +421,8 @@ <h1>Sūsen v0.7 Puzzle Solver</h1>
</div>
</div>
</div>
<div class="footer">
<p>[Sūsen local]</p>
</div>
</body>
</html>
9 changes: 9 additions & 0 deletions static/home/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@
background: #b8d1f3;
margin-bottom: 12px
}

.footer {
position: absolute;
bottom: 2px;
}

.footer p {
color: #b3b3b3;
}
16 changes: 14 additions & 2 deletions static/solver/puzzle.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ td[hover="one"]:hover {
background-color: #99ff99;
}
td[hover="two"]:hover {
background-color: #99ff99;
background-color: #ffff99;
}
td[hover="many"]:hover {
background-color: #ffff99;
background-color: #ff6666;
}
td[hover="opaque"]:hover {
background-color: #f1f6fd;
Expand All @@ -53,6 +53,9 @@ td[hover="opaque"]:hover {
td[selected="none"] {
background-color: #a6bcdb;
}
td[hover="zero"]:hover {
background-color: #ff6666;
}
td[selected="one"] {
background-color: #99ff99;
}
Expand Down Expand Up @@ -161,3 +164,12 @@ div[guess="maybe"] {
.stepButton.warning:hover {
background-color: #ff6666;
}

.footer {
position: absolute;
bottom: 2px;
}

.footer p {
color: #b3b3b3;
}
Loading

0 comments on commit ea03ba2

Please sign in to comment.