Skip to content
Permalink
Browse files

Well I won't have time to finish I think

  • Loading branch information...
Depado committed Sep 30, 2016
1 parent 3b13e9f commit 57bbb7325cb6da7646e9454893ee7ea2e349b4a2
Showing with 248 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. BIN assets/bg.png
  3. BIN assets/favicon.png
  4. BIN assets/header_bg.png
  5. +35 −0 conf/conf.go
  6. +28 −0 main.go
  7. +122 −0 templates/index.tmpl
  8. +20 −0 views/data.go
  9. +12 −0 views/index.go
  10. +26 −0 views/message.go
@@ -22,3 +22,8 @@ _testmain.go
*.exe
*.test
*.prof

assets/node_modules
assets/semantic
assets/semantic.json
conf.yml
BIN +11.8 KB assets/bg.png
Binary file not shown.
BIN +5.21 KB assets/favicon.png
Binary file not shown.
BIN +32.9 KB assets/header_bg.png
Binary file not shown.
@@ -0,0 +1,35 @@
package conf

import (
"io/ioutil"

"gopkg.in/yaml.v2"
)

type conf struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Debug bool `yaml:"debug"`
}

// C is the global conf
var C conf

// Load loads the configuration file into C and fills it with default
// configuration if fields are empty
// (Listen to 127.0.0.1, on port 8080, watching the "pages" directory)
func Load(fp string) error {
var err error
var c []byte

if c, err = ioutil.ReadFile(fp); err != nil {
return err
}
if C.Host == "" {
C.Host = "127.0.0.1"
}
if C.Port == 0 {
C.Port = 8080
}
return yaml.Unmarshal(c, &C)
}
28 main.go
@@ -0,0 +1,28 @@
package main

import (
"fmt"
"log"

"github.com/gin-gonic/gin"

"github.com/Depado/royancouragements/conf"
"github.com/Depado/royancouragements/views"
)

func main() {
var err error

if err = conf.Load("conf.yml"); err != nil {
log.Fatal(err)
}

r := gin.Default()
r.Static("/static", "./assets")
r.LoadHTMLGlob("templates/*")

r.GET("/", views.Index)
r.POST("/", views.PostMessage)

r.Run(fmt.Sprintf("%v:%d", conf.C.Host, conf.C.Port))
}
@@ -0,0 +1,122 @@
<!doctype html>
<html lang="fr">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>Royancouragements</title>
<link rel="icon" type="image/png" href="/static/favicon.png" />
<link rel="stylesheet" type="text/css" href="/static/semantic/dist/semantic.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<script src="/static/semantic/dist/semantic.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style>
body {
background-image: url("/static/bg.png");
background-repeat: repeat;
font-family: 'Roboto', sans-serif;
}
</style>
<style type="text/css">
#head {
background-image: url("/static/header_bg.png");
background-repeat: repeat;
}

.masthead h1.ui.header {
margin-top: 0.5em;
margin-bottom: 0em;
font-size: 4em;
font-weight: normal;
}

.masthead h2.ui.header {
font-size: 1.7em;
margin-bottom: 1.5em;
font-weight: normal;
}

@media only screen and (max-width: 700px) {
.masthead h1.ui.header {
font-size: 2em;
margin-top: 1.5em;
}
.masthead h2.ui.header {
margin-top: 0.5em;
font-size: 1.5em;
}
}
</style>

</head>

<body>
<div class="ui vertical masthead center aligned segment" id="head">
<div class="ui text container">
<h1 class="ui inverted header">LBC @ Royan</h1>
<h2 class="ui inverted header">Et si on les encourageait un peu ?</h2>
</div>
</div>

<div class="ui container" style="margin-top: 1em;">
{{ if eq .posted "errors" }}
<div class="ui negative message">
<i class="close icon"></i>
<div class="header">
Des erreurs dans le formulaire il semblerait.
</div>
</div>
{{ end }}
<div class="ui icon message">
<i class="inbox icon"></i>
<div class="content">
<div class="header">
Toi aussi offre ton soutiens à ces braves gens !
</div>
<p>Parce que chaque jour qui passe, nous nous demandons tous : “Mais combien de kilomètres aurait fait Fanch si il avait couru 24h d'affilé ?” et qu'enfin nous allons avoir notre réponse.</p>
</div>
</div>
<div class="ui segment center aligned">
<form class="ui form" action="/" method="post">
<div class="field">
<div class="ui selection dropdown">
<input name="athlete" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Athlete</div>
<div class="menu">
{{ range .athletes }}
<div class="item" data-value="{{ .ID }}">{{ .Name }}</div>
{{ end }}
</div>
</div>
</div>
<div class="field">
<input name="name" placeholder="Name" type="text">
</div>
<div class="field">
<input name="mail" placeholder="Mail" type="email">
</div>
<div class="field">
<textarea name="message" rows="2" placeholder="Message"></textarea>
</div>
<button class="ui button" type="submit">Submit</button>
</form>
</div>
</div>
<script>
$('.dropdown')
.dropdown();
$('.ui.form')
.form({
fields: {
athlete: 'empty',
name: 'empty',
mail: 'empty',
message: 'empty'
}
});
</script>
</body>

</html>
@@ -0,0 +1,20 @@
package views

// Athlete is a simple struct holding athlete data
type Athlete struct {
ID int
Name string
}

var athletes = []Athlete{
{29977, "Wilfrid ‘The Warrior’ Lancelle"},
{29983, "Christophe ‘FREYBLA’ Freihuber"},
{29988, "François(e) ‘Fanch’ Donval"},
{29986, "Jean-‘The Director’ Louis Bergamo"},
{29984, "Robin ‘Not Batman’ Leboeuf"},
{29985, "Stéph ‘Bikette’ Baltus"},
{29979, "Pauline ‘Queen of the Gif’ Barnouin"},
{29982, "Pierre ‘Dark Poupou’ Houssin"},
{29872, "Christian ‘Le Fou’ Mauduit"},
{29976, "Alison ‘Pimpante Party Planner’ Eastaway"},
}
@@ -0,0 +1,12 @@
package views

import (
"net/http"

"github.com/gin-gonic/gin"
)

// Index is the main view
func Index(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{"athletes": athletes, "posted": "nope"})
}
@@ -0,0 +1,26 @@
package views

import (
"net/http"

"github.com/gin-gonic/gin"
)

// SendForm is the form required to send a message
type SendForm struct {
Athlete string `form:"athlete" binding:"required"`
Name string `form:"name" binding:"required"`
Mail string `form:"mail" binding:"required"`
Message string `form:"message" binding:"required"`
}

// PostMessage is the handler for the form post
func PostMessage(c *gin.Context) {
var err error
var form SendForm
if err = c.Bind(&form); err != nil {
c.HTML(http.StatusOK, "index.tmpl", gin.H{"athletes": athletes, "posted": "errors"})
return
}
c.HTML(http.StatusOK, "index.tmpl", gin.H{"athletes": athletes, "posted": "success"})
}

0 comments on commit 57bbb73

Please sign in to comment.
You can’t perform that action at this time.