Skip to content

Commit

Permalink
fix: fix recettator
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Feb 10, 2019
1 parent 9196b6f commit 45f8bbc
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 11 deletions.
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ module ultre.me/calcbiz

require (
github.com/Masterminds/sprig v2.16.0+incompatible
github.com/aokoli/goutils v1.0.1 // indirect
github.com/disintegration/imaging v1.5.0
github.com/gobuffalo/packd v0.0.0-20181212173646-eca3b8fd6687
github.com/gobuffalo/packr v1.21.9
github.com/gogo/gateway v1.0.0
github.com/gogo/protobuf v1.2.0
github.com/golang/protobuf v1.2.0
github.com/google/uuid v1.0.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/handlers v1.4.0
github.com/gorilla/mux v1.6.2
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190104160321-4832df01553a
github.com/grpc-ecosystem/grpc-gateway v1.6.4
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/moul/advanced-ssh-config v2.8.0+incompatible // indirect
github.com/moul/numberinfo v0.0.0-20160903151149-753f372df509
github.com/oxtoacart/bpool v0.0.0-20150712133111-4e1c5567d7c2
github.com/pkg/errors v0.8.1
Expand All @@ -36,5 +41,5 @@ require (
google.golang.org/genproto v0.0.0-20190108161440-ae2f86662275
google.golang.org/grpc v1.17.0
ultre.me/kryptos v0.0.0-20181023194748-240fe1a16033
ultre.me/recettator v0.4.0
ultre.me/recettator v0.4.1-0.20190210231503-241df3a046a3
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,5 @@ ultre.me/kryptos v0.0.0-20181023194748-240fe1a16033 h1:t1sY4eMB9q2+ZmzxjxHagtz1i
ultre.me/kryptos v0.0.0-20181023194748-240fe1a16033/go.mod h1:NueMpFJdxVrRfBPrlVYEfjJhNj6ozlBz1RXYRhsWUak=
ultre.me/recettator v0.4.0 h1:h6Xq3bfiLu8jaQSLarOU5ArD4Q7W33pNGhSl3tQqCiY=
ultre.me/recettator v0.4.0/go.mod h1:snUoYZS9gzrGRq6tlKDRwBExrzGLjcWS05QVLhSuztA=
ultre.me/recettator v0.4.1-0.20190210231503-241df3a046a3 h1:o3cEyILq21aY8wT0qDY0N6fv2hduN9ICEGdQiMUCy6o=
ultre.me/recettator v0.4.1-0.20190210231503-241df3a046a3/go.mod h1:N52M6NqHXK4BWbvDL4ue2cuN3yvn1VYP5adytNtjTWQ=
47 changes: 43 additions & 4 deletions templates/hackz.recettator.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
{{define "title"}}Hack cassé{{end}}
{{define "h1"}}Hack {{mot_cool}}, mais cassé{{end}}
{{define "h1small"}}travaux {{mot_cool_pluriel}} en cours{{end}}
{{define "title"}}Recettator{{end}}
{{define "h1"}}Recettator{{end}}
{{define "h1small"}}bon appetit hein <a href="?recette={{.seed}}">#{{.seed}}</a>{{end}}

{{define "content"}}
Je reviendrai.
<div class="paper-container">
<div class="paper">
<ul>
<h3>{{ .Title | title}}</h3>
<div>Pour {{ .People }} {{ if eq .People 1 }}personne{{ else }}personnes{{ end }}</div>

<h4>Ingr&eacute;dients</h4>
<ul>
{{ range .Pool.MainIngredients.Picked }}
<li>{{ .NameAndQuantity }}</li>
{{ end }}
{{ range .Pool.SecondaryIngredients.Picked }}
<li>{{ .NameAndQuantity }}</li>
{{ end }}
</ul>

<h4>Etapes</h4>
<ul>
{{ range .Steps }}
<li>{{.}}</li>
{{ end }}
<li>Et bon appétit!</li>
</ul>
</div>
</div>
{{end}}

{{define "secondary_column"}}
<img src="/img/hackz/recettator/logo.jpg" alt="Recettator"
class="img-responsive img-rounded rotate-random" />
<hr />
<a href="/hackz/recettator" class="btn btn-primary blink_me">Nouvelle recette</a>

<ul>
{{ range .otherRecettes }}
<li>
<a href="/hackz/recettator?recette={{.}}">Recette #{{.}}</a>
</li>
{{ end }}
</ul>
{{end}}
10 changes: 5 additions & 5 deletions templates/old/hackz/recettator.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
{% set layout = 'two_columns' %}

{% block title %}Recettator{% endblock %}
{% block subtitle %}bon appetit hein <a href="{{seed_url}}">#{{recettator.seed}}</a>{% endblock %}
{% block subtitle %}bon appetit hein <a href="{{.seed_url}}">#{{.recettator.seed}}</a>{% endblock %}

{% block main_column %}
<div class="paper-container">
<div class="paper">
<h3>{{ recettator.title }}</h3>
<h3>{{ .recettator.title }}</h3>

<div>{{ recettator.people }}</div>
<div>{{ .recettator.people }}</div>

<h4>Ingr&eacute;dients</h4>
<ul>
{% for ingredient in recettator.ingredients %}
{% for ingredient in .recettator.ingredients %}
<li>{{ingredient}}</li>
{% endfor %}
</ul>

<h4>Etapes</h4>
<ul>
{% for step in recettator.steps %}
{% for step in .recettator.steps %}
<li>{{step}}</li>
{% endfor %}
</ul>
Expand Down
44 changes: 43 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package views

import (
"fmt"
"html/template"
"log"
"math/rand"
"net/http"
"strconv"
"sync"
Expand All @@ -12,6 +15,7 @@ import (

"ultre.me/calcbiz/api"
"ultre.me/calcbiz/pkg/crew"
"ultre.me/recettator"
)

type Options struct {
Expand Down Expand Up @@ -235,7 +239,45 @@ func (h *handlers) hackzPaint(w http.ResponseWriter, r *http.Request) {

func (h *handlers) hackzRecettator(w http.ResponseWriter, r *http.Request) {
h.setDefaultHeaders(w)
h.render(w, r, "hackz.recettator.tmpl", nil)

seed := r.FormValue("recette")
if seed == "" {
http.Redirect(w, r, fmt.Sprintf("/hackz/recettator?recette=%d", rand.Intn(10000+1)), http.StatusFound)
return
}

seedInt, err := strconv.Atoi(seed)
if err != nil {
log.Printf("invalid seed: %v (err=$v)", seed, err)
seedInt = 42
}

rctt := recettator.New(int64(seedInt))
rctt.SetSettings(recettator.Settings{
//MainIngredients: uint64(rand.Intn(4) + 1),
//SecondaryIngredients: uint64(rand.Intn(4) + 1),
//Steps: uint64(rand.Intn(5) + 2),
// People: 100
})

otherRecettes := []string{}
for i := 0; i < 10; i++ {
newSeed := (rand.Intn(588-59) + 59) * 17 // limits to 529 results between 1000 and 10000 (for SEO)
otherRecettes = append(otherRecettes, fmt.Sprintf("%d", newSeed))
}

data := renderData{
"layout_mode": "two_columns",
"seed": seed,
"seedInt": seedInt,
"recettator": rctt,
"Title": rctt.Title(),
"People": rctt.People(),
"Steps": rctt.Steps(),
"Pool": rctt.Pool(),
"otherRecettes": otherRecettes,
}
h.render(w, r, "hackz.recettator.tmpl", data)
}

func (h *handlers) hackzPhazms(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 45f8bbc

Please sign in to comment.