Parcourir la source

add example html page rendering

tags/v0.9.0
jimzhan il y a 9 ans
Parent
révision
1020934b76
3 fichiers modifiés avec 79 ajouts et 1 suppressions
  1. +24
    -0
      example/main.go
  2. +54
    -0
      example/views/index.html
  3. +1
    -1
      livereload/middleware.go

+ 24
- 0
example/main.go Voir le fichier

@@ -0,0 +1,24 @@
package main

import (
"html/template"
"net/http"
"path/filepath"

"github.com/goanywhere/rex"
"github.com/goanywhere/rex/livereload"
)

func Index(w http.ResponseWriter, r *http.Request) {
if html, err := template.ParseFiles(filepath.Join("views", "index.html")); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
html.Execute(w, nil)
}
}

func main() {
rex.Use(livereload.Middleware)
rex.Get("/", Index)
rex.Run()
}

+ 54
- 0
example/views/index.html Voir le fichier

@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
<link rel="shortcut icon" href="favicon.ico">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css">
</head>
<body>
<nav class="fixed-navbar grey darken-3">
<div class="container nav-wrapper">
<a href="https://github.com/goanywhere/rex" class="brand-logo">
<i class="fa fa-home fa-2x"></i>
</a>
<a href="#" data-activates="mobile-demo" class="button-collapse">
<i class="mdi-navigation-menu"></i>
</a>
<ul class="right hide-on-med-and-down">
<li>
<a href="https://github.com/jimzhan/generator-alt">React</a>
</li>
</ul>
<ul class="side-nav" id="mobile-demo">
<li>
<a href="https://github.com/jimzhan/generator-alt">React</a>
</li>
</ul>
</div>
</nav>

<main>
<div class="container">
<h2>Index</h2>
</div>
</main>

<script defer src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script defer src="//cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script>
<script defer src="/livereload.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(){
$('.button-collapse').sideNav({closeOnClick: true});
});
</script>
</body>
</html>

+ 1
- 1
livereload/middleware.go Voir le fichier

@@ -64,7 +64,7 @@ func (self *writer) Write(data []byte) (size int, e error) {
return self.ResponseWriter.Write(data)
}

func Module(next http.Handler) http.Handler {
func Middleware(next http.Handler) http.Handler {
// ONLY run this under debug mode.
if !env.Bool("DEBUG", true) {
return next

Chargement…
Annuler
Enregistrer