Skip to content

Commit

Permalink
feat: setup multi layout mode + small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jan 28, 2019
1 parent ee8dd11 commit 7cd20da
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 62 deletions.
12 changes: 10 additions & 2 deletions pkg/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ func MotDebileQuiSeMange() string {

func MotCool() string {
mots := []string{
"cool", "sympa", "gentil", "genial", "excellent", "superbe", "super",
"vraiment tres bien", "bien", "qui en a dans le pantalon", "top",
"cool", "sympa", "gentil", "génial", "excellent", "superbe", "super",
"vraiment très bien", "bien", "qui en a dans le pantalon", "top",
}
return mots[rand.Intn(len(mots))]
}

func MotCoolPluriel() string {
mots := []string{
"cools", "sympas", "gentils", "géniaux", "excellents", "superbes", "supers",
"vraiment très biens", "biens", "qui en ont dans le pantalon", "tops",
}
return mots[rand.Intn(len(mots))]
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/soundcloud/entities.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package soundcloud

import "fmt"
import (
"fmt"
"strings"
)

func (p *Playlist) IsMain() bool {
switch p.PlaylistType {
Expand Down Expand Up @@ -47,3 +50,7 @@ func (t *Track) URL() string {
func (t *Track) IsExternal() bool { return false }

func (t *Track) ImageURL() string { return t.ArtworkUrl }

func (t *Track) Tags() []string {
return strings.Split(t.TagList, " ") // FIXME: use shell lexer
}
20 changes: 11 additions & 9 deletions templates/hackz.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{{define "title"}}Hackz{{end}}

{{/*
{% block title %}Des hackz{% endblock %}
{% block subtitle %}à l'unité{% endblock %}
*/}}
{{define "h1"}}Des hackz{{end}}
{{define "h1small"}}à l'unité{{end}}

{{define "content"}}
{{ $columns := 3 }}
Expand All @@ -14,7 +11,7 @@
<div class="row">
{{ range $entry := .hackz.Entries }}

<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3 rotate-random">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 rotate-random">
<a href="{{ $entry.URL}}" class="thumbnail"
width="{{$square_size}}" height="{{$square_size}}"
{{ if $entry.IsExternal }} target="_blank"{{ end }}>
Expand All @@ -30,14 +27,19 @@
</div>

{{ end }}

</div>
<p class="well">Et plein d'autres..</p>

<!--<p class="well">Et plein d'autres..</p>-->
{{end}}


{{define "secondary_column"}}
<h3>Hackzers les plus {{ mot_cool_pluriel }} <small>(pour l'instant !)</small></h3>
Les scores sont cassés et reviendront bientôt
{{end}}

{{/*
{% block secondary_column %}
<h2>Hackzers les plus {{ mot_cool() }} <small>(pour l'instant !)</small></h2>
<ul>
{% for scor in hackzers %}
<li>#{{ loop.index }} {{ scor.login }} avec {{ scor.score }} {{ mot_debile_qui_se_mange() }}</li>
Expand Down
7 changes: 2 additions & 5 deletions templates/home.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{{define "fulltitle"}}Camembert au lait crew{{end}}

{{/*
{{ block title }}{{ images | length }} trucs{{ endblock }}
{{ block subtitle }}au hasard{{ endblock }}
*/}}
{{define "h1"}}{{len .dashboard.Entries}} trucs {{mot_cool_pluriel}}{{end}}
{{define "h1small"}}au hasard{{end}}


{{define "content"}}
Expand Down
35 changes: 17 additions & 18 deletions templates/layout/base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,25 @@

<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9 col-md-push-3 col-lg-push-3">
<div class="row">
{{ block "content" . }}{{end}}
{{/*
{{ if layout == 'two_columns' }}
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<h1>{{ self.title() }} <small>{{ self.subtitle() }}</small></h1>
{{ block main_column }}{{ endblock }}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<hr class="hidden-md hidden-lg" />
{{ block secondary_column }}{{ endblock }}
</div>
{{ else }} {# one column #}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1>{{ self.title() }} <small>{{ self.subtitle() }}</small></h1>
{{template "content" .}}
</div>

{{if eq .layout_mode "single_column"}}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h1>{{ block "h1" . }}{{end}} <small>{{ block "h1small" . }}{{end}}</small></h1>
{{ block "content" . }}{{end}}
</div>
{{end}}
{{if eq .layout_mode "two_columns"}}
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<h1>{{ block "h1" . }}{{end}} <small>{{ block "h1small" . }}{{end}}</small></h1>
{{ block "content" . }}{{end}}
</div>
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
<hr class="hidden-md hidden-lg" />
{{ block "secondary_column" . }}{{ end }}
</div>
{{end}}
*/}}

</div>
</div>
</div>

<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3 col-md-pull-9 col-lg-pull-9">
Expand Down
6 changes: 2 additions & 4 deletions templates/muzik.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{{define "title"}}Muzik{{end}}
{{define "h1"}}Des albums {{mot_cool_pluriel}}{{end}}
{{define "h1small"}}pas au hasard{{end}}

{{/*
{% block title %}Des albums{% endblock %}
{% block subtitle %}pas au hasard{% endblock %}
*/}}

{{define "content"}}
{{ $columns := 2 }}
Expand Down
37 changes: 16 additions & 21 deletions templates/track.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{define "h1"}}Du son {{ mot_cool }}{{end}}
{{define "h1small"}}{{.track.Title}}{{end}}

{{define "content"}}

{{define "content"}}
<!--<pre>{{.track|toPrettyJson}}</pre>-->

<iframe
Expand All @@ -19,27 +19,22 @@
{{end}}
{{end}}

{{/*
{% block main_column %}
{% endblock %}

{% block secondary_column %}
<a href="{{ track.ext_url }}" target="_blank">
<img src="{{ track.img | cache_external_assets }}" alt="{{ track.title }}"
class="img-responsive img-rounded rotate-random" />
</a>
{{define "secondary_column"}}
<a href="{{ .track.PermalinkUrl }}" target="_blank">
<img src="{{ .track.ImageURL | cache_external_asset }}" alt="{{ .track.Title }}"
class="img-responsive img-rounded rotate-random" />
</a>

<div class="track_date">
{{ track.created_at }}
</div>
<div class="track_date">
{{ .track.CreatedAt }}
</div>

{# FIXME: handle tags etc in html headers for SEO #}
<!-- FIXME: handle tags etc in html headers for SEO -->

<div class="track_tags">
{% for tag in track.tags %}
<span class="label label-primary">#{{ tag }}</span>
{% endfor %}
</div>

{% endblock %}
*/}}
<div class="track_tags">
{{ range $tag := .track.Tags }}
<span class="label label-primary">#{{ $tag }}</span>
{{ end }}
</div>
{{end}}
1 change: 1 addition & 0 deletions views/funcmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func getFuncmap(opts *Options) *ctxFuncmap {
fm["logo_alternate"] = random.AlternateLogo
fm["mot_du_jour"] = random.WOTD
fm["mot_cool"] = random.MotCool
fm["mot_cool_pluriel"] = random.MotCoolPluriel
fm["megahertz"] = f.megahertz
fm["mot_debile_qui_se_mange"] = random.MotDebileQuiSeMange
fm["neige"] = func() bool { return false }
Expand Down
3 changes: 3 additions & 0 deletions views/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (h *handlers) render(w http.ResponseWriter, r *http.Request, name string, d
"name": name,
"r": r,
}
if _, found := data["layout_mode"]; !found {
data["layout_mode"] = "single_column"
}

// set current request in ctxFuncmap objects
h.templatesMutex.Lock()
Expand Down
10 changes: 8 additions & 2 deletions views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func (h *handlers) trackHandler(w http.ResponseWriter, r *http.Request) {
h.renderError(w, r, err)
return
}
data := renderData{"track": track}
data := renderData{
"track": track,
"layout_mode": "two_columns",
}
h.render(w, r, "track.tmpl", data)
}

Expand Down Expand Up @@ -160,6 +163,9 @@ func (h *handlers) hackzHandler(w http.ResponseWriter, r *http.Request) {
h.renderError(w, r, err)
return
}
data := renderData{"hackz": hackz}
data := renderData{
"hackz": hackz,
"layout_mode": "two_columns",
}
h.render(w, r, "hackz.tmpl", data)
}

0 comments on commit 7cd20da

Please sign in to comment.