Skip to content

Commit

Permalink
add some tests and bench generate site
Browse files Browse the repository at this point in the history
  • Loading branch information
mna committed Jul 14, 2013
1 parent e1328ad commit 4141bc9
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 80 deletions.
6 changes: 3 additions & 3 deletions example/public/002-meta-billet
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/003-dependances
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/004-npm-packages
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/005-structurer-express
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/006-dependency-injection
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/007-implement-js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/008-backbone-computed-properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/009-je-men-vais
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/010-demenagement
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
2 changes: 2 additions & 0 deletions example/public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ nav {
.middle {
width: 50%;
text-align: center;
}
nav .middle {
margin-top: 10px;
}
.right {
Expand Down
6 changes: 3 additions & 3 deletions example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
6 changes: 3 additions & 3 deletions example/public/j-42-preparation
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<link rel="stylesheet" href="/css/main.css" />
<link rel="stylesheet" href="/css/fontello.css" />
<link href="http://fonts.googleapis.com/css?family=Telex" rel="stylesheet" type="text/css" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="http://localhost/rss" />
<link rel="alternate" type="application/rss&#43;xml" title="RSS" href="/rss" />
</head>
<body>

<div class="header">
<div class="title">
<a href="/">Ø value</a>
<a href="/"></a>
<br />
<span class="tagline">a wysiwyg hypertext cybersite</span>
<span class="tagline"></span>
</div>
</div>
<nav>
Expand Down
2 changes: 1 addition & 1 deletion example/public/rss
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><title>Ø value</title><description></description><link>http://localhost</link><lastBuildDate>13 Jul 13 23:02 -0400</lastBuildDate><generator>trofaf</generator><item><title>Ce blogue a déménagé sur GitHub</title><link>http://localhost/010-demenagement</link><description>Suite à l&#39;annonce de la fermeture de Calepin.co, j&#39;ai déménagé ce blogue sur http://hypermegatop.github.com. Veuillez mettre à jour vos favoris!</description><author>Martin Angers</author><category></category><pubDate>30 Apr 12 00:00 +0000</pubDate></item><item><title>Je suis venu te dire que je m&#39;en vais</title><link>http://localhost/009-je-men-vais</link><description>Ou plutôt, &#34;je suis venu te dire qu&#39;on m&#39;évince&#34;, mais ça &#34;punch&#34; moins... En effet, mon coup de foudre pour le blogiciel Calepin aura finalement été son baiser de la mort. Sur Twitter la semaine dernière, via le canal officiel du site, on apprenait que c&#39;était la fin des haricots.</description><author>Martin Angers</author><category></category><pubDate>23 Apr 12 00:00 +0000</pubDate></item><item><title>Propriétés calculées avec Backbone</title><link>http://localhost/008-backbone-computed-properties</link><description>La beauté de l&#39;univers du code libre est que lorsqu&#39;il manque une fonctionnalité, on peut se retrousser les manches, ouvrir le code et l&#39;ajouter. Voici ma petite histoire des propriétés calculées avec Backbone.</description><author>Martin Angers</author><category></category><pubDate>13 Apr 12 00:00 +0000</pubDate></item><item><title>implement.js: typage fort et Javascript</title><link>http://localhost/007-implement-js</link><description>L&#39;injection de dépendance avec Javascript a comme conséquence de ne pouvoir assumer que les fonctionnalités offertes par l&#39;instance reçue seront celles attendues.</description><author>Martin Angers</author><category></category><pubDate>02 Apr 12 00:00 +0000</pubDate></item><item><title>Expérimentations sur l&#39;injection de dépendance avec node.js</title><link>http://localhost/006-dependency-injection</link><description>L&#39;injection de dépendance permet de découpler les différentes composantes d&#39;une application pour en faciliter l&#39;entretien, la testabilité, circonscrire l&#39;impact des changements, mais aussi pour imposer une façon d&#39;aborder la création de l&#39;application en une aggrégation de pièces simples, à la responsabilité ciblée, et à l&#39;API bien défini.</description><author>Martin Angers</author><category></category><pubDate>27 Mar 12 00:00 +0000</pubDate></item></channel></rss>
<rss version="2.0"><channel><title></title><description></description><link></link><lastBuildDate>14 Jul 13 19:43 -0400</lastBuildDate><generator>trofaf</generator><item><title>Ce blogue a déménagé sur GitHub</title><link>/010-demenagement</link><description>Suite à l&#39;annonce de la fermeture de Calepin.co, j&#39;ai déménagé ce blogue sur http://hypermegatop.github.com. Veuillez mettre à jour vos favoris!</description><author>Martin Angers</author><category></category><pubDate>30 Apr 12 00:00 +0000</pubDate></item><item><title>Je suis venu te dire que je m&#39;en vais</title><link>/009-je-men-vais</link><description>Ou plutôt, &#34;je suis venu te dire qu&#39;on m&#39;évince&#34;, mais ça &#34;punch&#34; moins... En effet, mon coup de foudre pour le blogiciel Calepin aura finalement été son baiser de la mort. Sur Twitter la semaine dernière, via le canal officiel du site, on apprenait que c&#39;était la fin des haricots.</description><author>Martin Angers</author><category></category><pubDate>23 Apr 12 00:00 +0000</pubDate></item><item><title>Propriétés calculées avec Backbone</title><link>/008-backbone-computed-properties</link><description>La beauté de l&#39;univers du code libre est que lorsqu&#39;il manque une fonctionnalité, on peut se retrousser les manches, ouvrir le code et l&#39;ajouter. Voici ma petite histoire des propriétés calculées avec Backbone.</description><author>Martin Angers</author><category></category><pubDate>13 Apr 12 00:00 +0000</pubDate></item><item><title>implement.js: typage fort et Javascript</title><link>/007-implement-js</link><description>L&#39;injection de dépendance avec Javascript a comme conséquence de ne pouvoir assumer que les fonctionnalités offertes par l&#39;instance reçue seront celles attendues.</description><author>Martin Angers</author><category></category><pubDate>02 Apr 12 00:00 +0000</pubDate></item><item><title>Expérimentations sur l&#39;injection de dépendance avec node.js</title><link>/006-dependency-injection</link><description>L&#39;injection de dépendance permet de découpler les différentes composantes d&#39;une application pour en faciliter l&#39;entretien, la testabilité, circonscrire l&#39;impact des changements, mais aussi pour imposer une façon d&#39;aborder la création de l&#39;application en une aggrégation de pièces simples, à la responsabilité ciblée, et à l&#39;API bien défini.</description><author>Martin Angers</author><category></category><pubDate>27 Mar 12 00:00 +0000</pubDate></item></channel></rss>
9 changes: 3 additions & 6 deletions example/templates/post.amber
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extends layout

block content
if Post.ShortPost.Lang
article[lang=Post.ShortPost.Lang]
#{unescaped(Post.Content)}
else
article
#{unescaped(Post.Content)}
article
[lang=Post.ShortPost.Lang] ? len(Post.ShortPost.Lang) > 0
| #{unescaped(Post.Content)}
29 changes: 24 additions & 5 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"sort"
"strings"

"github.com/eknkc/amber"
)
Expand All @@ -17,6 +18,21 @@ var (
postTpl *template.Template
postTplNm = "post.amber"
rssTplNm = "rss.amber"

// Special files in the public directory, that must not be deleted
// If value is true, this must match the prefix of the file (HasPrefix())
specFiles = map[string]struct{}{
"favicon.ico": struct{}{},
"robots.txt": struct{}{},
"humans.txt": struct{}{},
"crossdomain.xml": struct{}{},
"apple-touch-icon.png": struct{}{},
"apple-touch-icon-114x114-precomposed.png": struct{}{},
"apple-touch-icon-144x144-precomposed.png": struct{}{},
"apple-touch-icon-57x57-precomposed.png": struct{}{},
"apple-touch-icon-72x72-precomposed.png": struct{}{},
"apple-touch-icon-precomposed.png": struct{}{},
}
)

type sortableLongPost []*LongPost
Expand Down Expand Up @@ -58,16 +74,19 @@ func compileTemplate() error {
}

func clearPublicDir() error {
// Clear the public directory, except subdirs
// Clear the public directory, except subdirs and special files (favicon.ico)
fis, err := ioutil.ReadDir(PublicDir)
if err != nil {
return fmt.Errorf("error getting public directory files: %s", err)
}
for _, fi := range fis {
if !fi.IsDir() && fi.Name() != "favicon.ico" {
err = os.Remove(filepath.Join(PublicDir, fi.Name()))
if err != nil {
return fmt.Errorf("error deleting file %s: %s", fi.Name(), err)
if !fi.IsDir() && !strings.HasPrefix(fi.Name(), ".") {
// Check for special files
if _, ok := specFiles[fi.Name()]; !ok {
err = os.Remove(filepath.Join(PublicDir, fi.Name()))
if err != nil {
return fmt.Errorf("error deleting file %s: %s", fi.Name(), err)
}
}
}
}
Expand Down
78 changes: 78 additions & 0 deletions gen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"bytes"
"io/ioutil"
"log"
"sort"
"testing"
"time"
)

func mustParse(s string) time.Time {
t, err := time.Parse("2006-01-02", s)
if err != nil {
panic(err)
}
return t
}

func TestSort(t *testing.T) {
ps := make(sortableLongPost, 5)
ps[0] = &LongPost{
ShortPost: &ShortPost{
Title: "a",
PubTime: mustParse("2012-01-07"),
},
}
ps[1] = &LongPost{
ShortPost: &ShortPost{
Title: "b",
PubTime: mustParse("2012-04-22"),
},
}
ps[2] = &LongPost{
ShortPost: &ShortPost{
Title: "c",
PubTime: mustParse("2012-01-01"),
},
}
ps[3] = &LongPost{
ShortPost: &ShortPost{
Title: "d",
PubTime: mustParse("2011-11-30"),
},
}
ps[4] = &LongPost{
ShortPost: &ShortPost{
Title: "e",
PubTime: mustParse("2012-12-01"),
},
}
sort.Sort(ps)

buf := bytes.NewBuffer(nil)
for _, p := range ps {
buf.WriteString(p.Title)
}
if buf.String() != "dcabe" {
t.Errorf("expected 'dcabe', got %s", buf.String())
}
}

func BenchmarkGenerateSite(b *testing.B) {
b.StopTimer()
log.SetOutput(ioutil.Discard)
Options.RecentPostsCount = 5
PublicDir = "./example/public"
PostsDir = "./example/posts"
TemplatesDir = "./example/templates"
b.StartTimer()

for i := 0; i < b.N; i++ {
err := generateSite()
if err != nil {
b.Fatal(err)
}
}
}
Loading

0 comments on commit 4141bc9

Please sign in to comment.