diff options
| author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-07-12 12:24:04 -0400 | 
|---|---|---|
| committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2017-07-12 12:24:04 -0400 | 
| commit | 86245ba9e4341a096727158e06290fb8075654ce (patch) | |
| tree | f190ad3c8e507a3131784468113f157be4a2b4e6 /src | |
| parent | f177dcb7b98300634fdef408150a83e9f476d66d (diff) | |
refactor: Eliminate template duplication
Diffstat (limited to 'src')
| -rw-r--r-- | src/data/templates/add.hbs | 67 | ||||
| -rw-r--r-- | src/data/templates/approve.hbs | 68 | ||||
| -rw-r--r-- | src/data/templates/base.hbs | 76 | ||||
| -rw-r--r-- | src/data/templates/quotes.hbs | 79 | ||||
| -rw-r--r-- | src/server.rs | 4 | 
5 files changed, 98 insertions, 196 deletions
diff --git a/src/data/templates/add.hbs b/src/data/templates/add.hbs index 1f5d782..dedc0db 100644 --- a/src/data/templates/add.hbs +++ b/src/data/templates/add.hbs @@ -1,53 +1,8 @@ -<!doctype html> -<html lang="no"> -  <head> -    <meta name="robots" content="noindex, nofollow" /> -    <link rel="shortcut icon" href="/favicon.ico" /> -    <title>Quotes fra #linux.no på freenode</title> -    <style type="text/css"> -      body { -        font-family: monospace; -        background: #ffffff; -        color: #000000; -      } -      a, a:visited { -        color: #000000; -      } -      hr { -      	border-style: solid; -      	border-color: black; -      	border-width: 1px;  -      } -      .ragebutton { -        	font-family: monospace; -      	text-align: left; -          text-decoration: underline; -      	color: black; -      	background: none; -      	margin: 0; -      	padding: 0; -      	border: none; -      	cursor: pointer; -        	-moz-user-select: text; -      } -    </style> -  </head> -  <body> - -<pre> -                     _ _   -                    | (_)_ __  _   ___  __  _ __   ___   -              _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \  -              _|_|_ | | | | | | |_| |)  ( _| | | | (_) |  -               | |  |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/  -             -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=- - -              Legg til new quote - -             -=-=-=-=-=-=-=-=-=-=- -</pre> -<hr> +{{#*inline "heading"}} +                            Legg til quote +{{/inline}} +{{#*inline "page"}}  <form action="add.jsp" method="post">  ditt nick:<br>  <input type=text name="nick" size=20><br> @@ -59,16 +14,6 @@ Prøv å bruke sånn ca. samme timestamp-format (HH:MM) o.l. som eksisterende qu  <input type="submit" value="Legg til">  </form>  <a href="quotes.jsp"><- Tilbake til quotes</a> +{{/inline}} -<center> -<br> -<p>linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony. -<p>Source code at <a href="https://git.orbekk.com/linoquotes-gamma.git">https://git.orbekk.com/linoquotes-gamma.git</a>. -<p>The quotes on this page are copyright their respective owners and submitters.</p> -</center> - -  </body> -</html> - - - +{{~> base~}} diff --git a/src/data/templates/approve.hbs b/src/data/templates/approve.hbs index 195bb0d..70b8225 100644 --- a/src/data/templates/approve.hbs +++ b/src/data/templates/approve.hbs @@ -1,53 +1,8 @@ -<!doctype html> -<html lang="no"> -  <head> -    <meta name="robots" content="noindex, nofollow" /> -    <link rel="shortcut icon" href="/favicon.ico" /> -    <title>Quotes fra #linux.no på freenode</title> -    <style type="text/css"> -      body { -        font-family: monospace; -        background: #ffffff; -        color: #000000; -      } -      a, a:visited { -        color: #000000; -      } -      hr { -      	border-style: solid; -      	border-color: black; -      	border-width: 1px;  -      } -      .ragebutton { -        font-family: monospace; -      	text-align: left; -        text-decoration: underline; -      	color: black; -      	background: none; -      	margin: 0; -      	padding: 0; -      	border: none; -      	cursor: pointer; -        	-moz-user-select: text; -      } -    </style> -  </head> -  <body> - -<pre> -                     _ _   -                    | (_)_ __  _   ___  __  _ __   ___   -              _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \  -              _|_|_ | | | | | | |_| |)  ( _| | | | (_) |  -               | |  |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/  -             -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=- -                   Quotes fra #linux.no på freenode -                  Klikk <a href="add.jsp">her</a> for å legge til en quote - -              Sortér etter <a href="quotes.jsp?order=date">dato</a> | <a href="quotes.jsp?order=score">score</a> -</pre> -<hr> +{{#*inline "heading"}} +                              Godkjenning +{{/inline}} +{{#*inline "page"}}  {{#each quotes}}  <br> @@ -61,17 +16,6 @@ Dato: {{date}},  <br>  <hr>  {{/each}} +{{/inline}} - -<center> -<br> -<p>linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony. -<p>Source code at <a href="https://git.orbekk.com/linoquotes-gamma.git">https://git.orbekk.com/linoquotes-gamma.git</a>. -<p>The quotes on this page are copyright their respective owners and submitters.</p> -</center> - -  </body> -</html> - - - +{{~> base~}} diff --git a/src/data/templates/base.hbs b/src/data/templates/base.hbs new file mode 100644 index 0000000..d548965 --- /dev/null +++ b/src/data/templates/base.hbs @@ -0,0 +1,76 @@ +<!doctype html> +<html lang="no"> +  <head> +    <meta name="robots" content="noindex, nofollow" /> +    <link rel="shortcut icon" href="/favicon.ico" /> +    <title>Quotes fra #linux.no på freenode</title> +    <style type="text/css"> +      body { +        font-family: monospace; +        background: #ffffff; +        color: #000000; +      } +      a, a:visited { +        color: #000000; +      } +      hr { +      	border-style: solid; +      	border-color: black; +      	border-width: 1px;  +      } +      .ragebutton { +        font-family: monospace; +      	text-align: left; +        text-decoration: underline; +      	color: black; +      	background: none; +      	margin: 0; +      	padding: 0; +      	border: none; +      	cursor: pointer; +        	-moz-user-select: text; +      } +    </style> +    <script type="text/javascript"> +      function vote(id, value) { +          var http = new XMLHttpRequest(); +          http.open("GET","/vote?id="+id+"&vote="+value); +          http.onreadystatechange=function() { +              if(http.readyState==4) { +                  document.getElementById("v"+id).innerHTML = http.responseText; +              } +          } +          http.send(null); +      } +    </script> +  </head> +  <body> + +<pre> +                     _ _   +                    | (_)_ __  _   ___  __  _ __   ___   +              _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \  +              _|_|_ | | | | | | |_| |)  ( _| | | | (_) |  +               | |  |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/  +             -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=- +                   <a href="quotes.jsp">Quotes</a> fra #linux.no på freenode +                  Klikk <a href="add.jsp">her</a> for å legge til en quote + +{{~>heading}} +</pre> +<hr> + +{{~>page}} + +<center> +<br> +<p>linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony. +<p>Source code at <a href="https://git.orbekk.com/linoquotes-gamma.git">https://git.orbekk.com/linoquotes-gamma.git</a>. +<p>The quotes on this page are copyright their respective owners and submitters.</p> +</center> + +  </body> +</html> + + + diff --git a/src/data/templates/quotes.hbs b/src/data/templates/quotes.hbs index 45fa711..71732ab 100644 --- a/src/data/templates/quotes.hbs +++ b/src/data/templates/quotes.hbs @@ -1,65 +1,8 @@ -<!doctype html> -<html lang="no"> -  <head> -    <meta name="robots" content="noindex, nofollow" /> -    <link rel="shortcut icon" href="/favicon.ico" /> -    <title>Quotes fra #linux.no på freenode</title> -    <style type="text/css"> -      body { -        font-family: monospace; -        background: #ffffff; -        color: #000000; -      } -      a, a:visited { -        color: #000000; -      } -      hr { -      	border-style: solid; -      	border-color: black; -      	border-width: 1px;  -      } -      .ragebutton { -        font-family: monospace; -      	text-align: left; -        text-decoration: underline; -      	color: black; -      	background: none; -      	margin: 0; -      	padding: 0; -      	border: none; -      	cursor: pointer; -        	-moz-user-select: text; -      } -    </style> -    <script type="text/javascript"> -      function vote(id, value) { -          var http = new XMLHttpRequest(); -          http.open("GET","/vote?id="+id+"&vote="+value); -          http.onreadystatechange=function() { -              if(http.readyState==4) { -                  document.getElementById("v"+id).innerHTML = http.responseText; -              } -          } -          http.send(null); -      } -    </script> -  </head> -  <body> - -<pre> -                     _ _   -                    | (_)_ __  _   ___  __  _ __   ___   -              _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \  -              _|_|_ | | | | | | |_| |)  ( _| | | | (_) |  -               | |  |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/  -             -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=- -                   Quotes fra #linux.no på freenode -                  Klikk <a href="add.jsp">her</a> for å legge til en quote - -              Sortér etter <a href="quotes.jsp?order=date">dato</a> | <a href="quotes.jsp?order=score">score</a> -</pre> -<hr> +{{#*inline "heading"}} +                      Sortér etter <a href="quotes.jsp?order=date">dato</a> | <a href="quotes.jsp?order=score">score</a> +{{/inline}} +{{#*inline "page"}}  {{#each quotes}}  <br> @@ -80,16 +23,6 @@ Dato: {{date}}, Score:  <br>  <hr>  {{/each}} +{{/inline}} - -<center> -<br> -<p>linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony. -<p>Source code at <a href="https://git.orbekk.com/linoquotes-gamma.git">https://git.orbekk.com/linoquotes-gamma.git</a>. -<p>The quotes on this page are copyright their respective owners and submitters.</p> -</center> - -  </body> -</html> - - +{{~> base~}} diff --git a/src/server.rs b/src/server.rs index 4c8240b..ee51ef3 100644 --- a/src/server.rs +++ b/src/server.rs @@ -33,6 +33,10 @@ fn make_renderer() -> HandlebarsEngine {      let mut templates = BTreeMap::new();      templates.insert( +        "base".to_string(), +        include_str!("data/templates/base.hbs").to_string(), +    ); +    templates.insert(          "quotes".to_string(),          include_str!("data/templates/quotes.hbs").to_string(),      );  | 
