Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
container-manager
Commits
a1c84985
Commit
a1c84985
authored
Sep 26, 2018
by
Mohamed, Fawzi Roberto (fawzi)
Browse files
html templates
parent
5b27798d
Changes
4
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
a1c84985
...
...
@@ -81,7 +81,6 @@ target
build
null
tmp*
temp*
dist
test-output
build.log
...
...
app/components.js
View file @
a1c84985
...
...
@@ -92,6 +92,71 @@ function evalTemplate(templatePath, extraRepl, next) {
})
}
// evaluates a template, here only the most basic replacements are given, you normally need to pass in extraRepl.
// calls next with the resolved template plus all replacements defined
function
evalTemplate
(
templatePath
,
extraRepl
,
next
)
{
loadTemplate
(
templatePath
,
function
(
err
,
template
)
{
if
(
err
)
{
next
(
err
,
null
,
undefined
)
}
else
{
const
repl
=
Object
.
assign
({},
extraRepl
,
baseRepl
)
const
res
=
template
(
repl
)
//logger.debug(`evaluating <<${templatePath}>> with ${stringify(repl)} gives <<${res}>>`)
next
(
null
,
res
,
repl
)
}
})
}
// Immediately returns an html describing the error
function
getHtmlErrorTemplate
(
err
,
context
=
''
)
{
let
error
=
''
,
error_msg
=
''
,
error_detail
=
''
if
(
!
err
)
{
try
{
error_detail
=
stringify
(
err
,
null
,
2
)
error
=
err
.
error
||
''
error_msg
=
error
.
message
||
''
}
catch
(
e
)
{
}
return
`<!doctype html>
<html>
<head>
<title>Error
${
error
}
</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Error
${
error
}
</h1>
<h2>context</h2>
<p>
${
error_msg
}
</p>
<pre>
${
error_detail
}
</pre>
</body>
</html>`
}
}
// Helper to evaluate a web page template (layout + content)
// will *always* give an html as result (it there was an error it describe the error
function
evalHtmlTemplate
(
htmlPath
,
repl
,
next
,
layout
=
null
,
context
=
''
)
{
const
layout
=
repl
.
layout
||
"
defaultTemplate.html
"
evalTemplate
(
"
html/
"
+
htmlPath
,
repl
,
function
(
err
,
template
){
if
(
err
)
{
next
(
err
,
getHtmlErrorTemplate
(
err
,
context
))
}
else
{
const
repl2
=
Object
.
assign
({
title
:
htmlPath
,
head
:
''
},
repl
,
{
body
:
template
})
evalHtmlTemplate
(
"
html/
"
+
layout
,
repl2
,
function
(
err
,
res
){
if
(
err
)
{
next
(
err
,
getHtmlErrorTemplate
(
err
,
context
))
}
else
{
next
(
nil
,
res
)
}
})
}
})
}
function
namespaceTemplate
(
name
,
next
)
{
evalTemplate
(
"
kube/namespace.yaml
"
,
{
namespace
:
name
},
next
)
}
...
...
templates/html/defaultLayout.html
0 → 100644
View file @
a1c84985
<!doctype html>
<html>
<head>
<title>
{{title}}
</title>
<meta
charset=
"utf-8"
/>
{{head}}
</head>
<body>
{{body}}
</body>
</html>
templates/html/reloadMsg.html
0 → 100644
View file @
a1c84985
<h3>
Please wait while we start a container for you!
</h3>
<p>
You might need to refresh manually (F5)...
</p>
p>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment